├── .gitignore ├── AppRTCDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── AppRTCDemo.xccheckout ├── AppRTCDemo ├── APPRTCAppDelegate.h ├── APPRTCAppDelegate.m ├── APPRTCViewController.h ├── APPRTCViewController.m ├── ARDAppClient.h ├── ARDAppClient.m ├── ARDMessageResponse.h ├── ARDMessageResponse.m ├── ARDRegisterResponse.h ├── ARDRegisterResponse.m ├── ARDSignalingMessage.h ├── ARDSignalingMessage.m ├── ARDUtilities.h ├── ARDUtilities.m ├── ARDWebSocketChannel.h ├── ARDWebSocketChannel.m ├── AppRTCDemo-Prefix.pch ├── Default.png ├── Info.plist ├── RTCICECandidate+JSON.h ├── RTCICECandidate+JSON.m ├── RTCICEServer+JSON.h ├── RTCICEServer+JSON.m ├── RTCMediaConstraints+JSON.h ├── RTCMediaConstraints+JSON.m ├── RTCSessionDescription+JSON.h ├── RTCSessionDescription+JSON.m ├── ResourceRules.plist ├── en.lproj │ └── APPRTCViewController.xib ├── main.m └── third_party │ └── SocketRocket │ ├── LICENSE │ ├── SRWebSocket.h │ └── SRWebSocket.m ├── AppRTCDemoTests ├── AppRTCDemoTests.m └── Info.plist ├── LICENSE ├── README.md ├── include ├── RTCAudioSource.h ├── RTCAudioTrack.h ├── RTCDataChannel.h ├── RTCEAGLVideoView.h ├── RTCI420Frame.h ├── RTCICECandidate.h ├── RTCICEServer.h ├── RTCMediaConstraints.h ├── RTCMediaSource.h ├── RTCMediaStream.h ├── RTCMediaStreamTrack.h ├── RTCNSGLVideoView.h ├── RTCOpenGLVideoRenderer.h ├── RTCPair.h ├── RTCPeerConnection.h ├── RTCPeerConnectionDelegate.h ├── RTCPeerConnectionFactory.h ├── RTCSessionDescription.h ├── RTCSessionDescriptionDelegate.h ├── RTCStatsDelegate.h ├── RTCStatsReport.h ├── RTCTypes.h ├── RTCVideoCapturer.h ├── RTCVideoRenderer.h ├── RTCVideoSource.h └── RTCVideoTrack.h ├── libWebRTC.a └── libWebRTC.a.tar.bz2 /.gitignore: -------------------------------------------------------------------------------- 1 | xcuserdata 2 | -------------------------------------------------------------------------------- /AppRTCDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AppRTCDemo.xcodeproj/project.xcworkspace/xcshareddata/AppRTCDemo.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 83390ACB-3909-4B4D-822E-7B36A474BA73 9 | IDESourceControlProjectName 10 | AppRTCDemo 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | BFB1AFB9723584E74255CED175009BEC403E4BF3 14 | github.com:hiroeorz/AppRTCDemo.git 15 | 16 | IDESourceControlProjectPath 17 | AppRTCDemo.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | BFB1AFB9723584E74255CED175009BEC403E4BF3 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | github.com:hiroeorz/AppRTCDemo.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | BFB1AFB9723584E74255CED175009BEC403E4BF3 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | BFB1AFB9723584E74255CED175009BEC403E4BF3 36 | IDESourceControlWCCName 37 | AppRTCDemo 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /AppRTCDemo/APPRTCAppDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // The main application class of the AppRTCDemo iOS app demonstrating 31 | // interoperability between the Objective C implementation of PeerConnection 32 | // and the apprtc.appspot.com demo webapp. 33 | @interface APPRTCAppDelegate : NSObject 34 | @end 35 | -------------------------------------------------------------------------------- /AppRTCDemo/APPRTCAppDelegate.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "APPRTCAppDelegate.h" 29 | 30 | #import "APPRTCViewController.h" 31 | #import "RTCPeerConnectionFactory.h" 32 | 33 | @implementation APPRTCAppDelegate { 34 | UIWindow* _window; 35 | } 36 | 37 | #pragma mark - UIApplicationDelegate methods 38 | 39 | - (BOOL)application:(UIApplication*)application 40 | didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { 41 | [RTCPeerConnectionFactory initializeSSL]; 42 | _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 43 | APPRTCViewController* viewController = 44 | [[APPRTCViewController alloc] initWithNibName:@"APPRTCViewController" 45 | bundle:nil]; 46 | _window.rootViewController = viewController; 47 | [_window makeKeyAndVisible]; 48 | return YES; 49 | } 50 | 51 | - (void)applicationWillResignActive:(UIApplication*)application { 52 | [[self appRTCViewController] applicationWillResignActive:application]; 53 | } 54 | 55 | - (void)applicationWillTerminate:(UIApplication*)application { 56 | [RTCPeerConnectionFactory deinitializeSSL]; 57 | } 58 | 59 | #pragma mark - Private 60 | 61 | - (APPRTCViewController*)appRTCViewController { 62 | return (APPRTCViewController*)_window.rootViewController; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /AppRTCDemo/APPRTCViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // The view controller that is displayed when AppRTCDemo is loaded. 31 | @interface APPRTCViewController : UIViewController 32 | 33 | @property(weak, nonatomic) IBOutlet UITextField* roomInput; 34 | @property(weak, nonatomic) IBOutlet UITextView* instructionsView; 35 | @property(weak, nonatomic) IBOutlet UITextView* logView; 36 | @property(weak, nonatomic) IBOutlet UIView* blackView; 37 | 38 | - (void)applicationWillResignActive:(UIApplication*)application; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /AppRTCDemo/APPRTCViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if !defined(__has_feature) || !__has_feature(objc_arc) 29 | #error "This file requires ARC support." 30 | #endif 31 | 32 | #import "APPRTCViewController.h" 33 | 34 | #import 35 | #import "ARDAppClient.h" 36 | #import "RTCEAGLVideoView.h" 37 | #import "RTCVideoTrack.h" 38 | 39 | // Padding space for local video view with its parent. 40 | static CGFloat const kLocalViewPadding = 20; 41 | 42 | @interface APPRTCViewController () 44 | @property(nonatomic, assign) UIInterfaceOrientation statusBarOrientation; 45 | @property(nonatomic, strong) RTCEAGLVideoView* localVideoView; 46 | @property(nonatomic, strong) RTCEAGLVideoView* remoteVideoView; 47 | @end 48 | 49 | @implementation APPRTCViewController { 50 | ARDAppClient *_client; 51 | RTCVideoTrack* _localVideoTrack; 52 | RTCVideoTrack* _remoteVideoTrack; 53 | CGSize _localVideoSize; 54 | CGSize _remoteVideoSize; 55 | } 56 | 57 | - (void)viewDidLoad { 58 | [super viewDidLoad]; 59 | 60 | self.remoteVideoView = 61 | [[RTCEAGLVideoView alloc] initWithFrame:self.blackView.bounds]; 62 | self.remoteVideoView.delegate = self; 63 | self.remoteVideoView.transform = CGAffineTransformMakeScale(-1, 1); 64 | [self.blackView addSubview:self.remoteVideoView]; 65 | 66 | self.localVideoView = 67 | [[RTCEAGLVideoView alloc] initWithFrame:self.blackView.bounds]; 68 | self.localVideoView.delegate = self; 69 | [self.blackView addSubview:self.localVideoView]; 70 | 71 | self.statusBarOrientation = 72 | [UIApplication sharedApplication].statusBarOrientation; 73 | self.roomInput.delegate = self; 74 | [self.roomInput becomeFirstResponder]; 75 | } 76 | 77 | - (void)viewDidLayoutSubviews { 78 | if (self.statusBarOrientation != 79 | [UIApplication sharedApplication].statusBarOrientation) { 80 | self.statusBarOrientation = 81 | [UIApplication sharedApplication].statusBarOrientation; 82 | [[NSNotificationCenter defaultCenter] 83 | postNotificationName:@"StatusBarOrientationDidChange" 84 | object:nil]; 85 | } 86 | } 87 | 88 | - (void)applicationWillResignActive:(UIApplication*)application { 89 | [self disconnect]; 90 | } 91 | 92 | #pragma mark - ARDAppClientDelegate 93 | 94 | - (void)appClient:(ARDAppClient *)client 95 | didChangeState:(ARDAppClientState)state { 96 | switch (state) { 97 | case kARDAppClientStateConnected: 98 | NSLog(@"Client connected."); 99 | break; 100 | case kARDAppClientStateConnecting: 101 | NSLog(@"Client connecting."); 102 | break; 103 | case kARDAppClientStateDisconnected: 104 | NSLog(@"Client disconnected."); 105 | [self resetUI]; 106 | break; 107 | } 108 | } 109 | 110 | - (void)appClient:(ARDAppClient *)client 111 | didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { 112 | _localVideoTrack = localVideoTrack; 113 | [_localVideoTrack addRenderer:self.localVideoView]; 114 | self.localVideoView.hidden = NO; 115 | } 116 | 117 | - (void)appClient:(ARDAppClient *)client 118 | didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { 119 | _remoteVideoTrack = remoteVideoTrack; 120 | [_remoteVideoTrack addRenderer:self.remoteVideoView]; 121 | } 122 | 123 | - (void)appClient:(ARDAppClient *)client 124 | didError:(NSError *)error { 125 | [self showAlertWithMessage:[NSString stringWithFormat:@"%@", error]]; 126 | [self disconnect]; 127 | } 128 | 129 | #pragma mark - RTCEAGLVideoViewDelegate 130 | 131 | - (void)videoView:(RTCEAGLVideoView*)videoView 132 | didChangeVideoSize:(CGSize)size { 133 | if (videoView == self.localVideoView) { 134 | _localVideoSize = size; 135 | } else if (videoView == self.remoteVideoView) { 136 | _remoteVideoSize = size; 137 | } else { 138 | NSParameterAssert(NO); 139 | } 140 | [self updateVideoViewLayout]; 141 | } 142 | 143 | #pragma mark - UITextFieldDelegate 144 | 145 | - (void)textFieldDidEndEditing:(UITextField*)textField { 146 | NSString* room = textField.text; 147 | if ([room length] == 0) { 148 | return; 149 | } 150 | textField.hidden = YES; 151 | self.instructionsView.hidden = YES; 152 | self.logView.hidden = NO; 153 | [_client disconnect]; 154 | // TODO(tkchin): support reusing the same client object. 155 | _client = [[ARDAppClient alloc] initWithDelegate:self]; 156 | [_client connectToRoomWithId:room options:nil]; 157 | [self setupCaptureSession]; 158 | } 159 | 160 | - (BOOL)textFieldShouldReturn:(UITextField*)textField { 161 | // There is no other control that can take focus, so manually resign focus 162 | // when return (Join) is pressed to trigger |textFieldDidEndEditing|. 163 | [textField resignFirstResponder]; 164 | return YES; 165 | } 166 | 167 | #pragma mark - Private 168 | 169 | - (void)disconnect { 170 | [self resetUI]; 171 | [_client disconnect]; 172 | } 173 | 174 | - (void)showAlertWithMessage:(NSString*)message { 175 | UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil 176 | message:message 177 | delegate:nil 178 | cancelButtonTitle:@"OK" 179 | otherButtonTitles:nil]; 180 | [alertView show]; 181 | } 182 | 183 | - (void)resetUI { 184 | [self.roomInput resignFirstResponder]; 185 | self.roomInput.text = nil; 186 | self.roomInput.hidden = NO; 187 | self.instructionsView.hidden = NO; 188 | self.logView.hidden = YES; 189 | self.logView.text = nil; 190 | if (_localVideoTrack) { 191 | [_localVideoTrack removeRenderer:self.localVideoView]; 192 | _localVideoTrack = nil; 193 | [self.localVideoView renderFrame:nil]; 194 | } 195 | if (_remoteVideoTrack) { 196 | [_remoteVideoTrack removeRenderer:self.remoteVideoView]; 197 | _remoteVideoTrack = nil; 198 | [self.remoteVideoView renderFrame:nil]; 199 | } 200 | self.blackView.hidden = YES; 201 | } 202 | 203 | - (void)setupCaptureSession { 204 | self.blackView.hidden = NO; 205 | [self updateVideoViewLayout]; 206 | } 207 | 208 | - (void)updateVideoViewLayout { 209 | // TODO(tkchin): handle rotation. 210 | CGSize defaultAspectRatio = CGSizeMake(4, 3); 211 | CGSize localAspectRatio = CGSizeEqualToSize(_localVideoSize, CGSizeZero) ? 212 | defaultAspectRatio : _localVideoSize; 213 | CGSize remoteAspectRatio = CGSizeEqualToSize(_remoteVideoSize, CGSizeZero) ? 214 | defaultAspectRatio : _remoteVideoSize; 215 | 216 | CGRect remoteVideoFrame = 217 | AVMakeRectWithAspectRatioInsideRect(remoteAspectRatio, 218 | self.blackView.bounds); 219 | self.remoteVideoView.frame = remoteVideoFrame; 220 | 221 | CGRect localVideoFrame = 222 | AVMakeRectWithAspectRatioInsideRect(localAspectRatio, 223 | self.blackView.bounds); 224 | localVideoFrame.size.width = localVideoFrame.size.width / 3; 225 | localVideoFrame.size.height = localVideoFrame.size.height / 3; 226 | localVideoFrame.origin.x = CGRectGetMaxX(self.blackView.bounds) 227 | - localVideoFrame.size.width - kLocalViewPadding; 228 | localVideoFrame.origin.y = CGRectGetMaxY(self.blackView.bounds) 229 | - localVideoFrame.size.height - kLocalViewPadding; 230 | self.localVideoView.frame = localVideoFrame; 231 | } 232 | 233 | @end 234 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDAppClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #import "RTCVideoTrack.h" 31 | 32 | typedef NS_ENUM(NSInteger, ARDAppClientState) { 33 | // Disconnected from servers. 34 | kARDAppClientStateDisconnected, 35 | // Connecting to servers. 36 | kARDAppClientStateConnecting, 37 | // Connected to servers. 38 | kARDAppClientStateConnected, 39 | }; 40 | 41 | @class ARDAppClient; 42 | @protocol ARDAppClientDelegate 43 | 44 | - (void)appClient:(ARDAppClient *)client 45 | didChangeState:(ARDAppClientState)state; 46 | 47 | - (void)appClient:(ARDAppClient *)client 48 | didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack; 49 | 50 | - (void)appClient:(ARDAppClient *)client 51 | didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack; 52 | 53 | - (void)appClient:(ARDAppClient *)client 54 | didError:(NSError *)error; 55 | 56 | @end 57 | 58 | // Handles connections to the AppRTC server for a given room. 59 | @interface ARDAppClient : NSObject 60 | 61 | @property(nonatomic, readonly) ARDAppClientState state; 62 | @property(nonatomic, weak) id delegate; 63 | 64 | - (instancetype)initWithDelegate:(id)delegate; 65 | 66 | // Establishes a connection with the AppRTC servers for the given room id. 67 | // TODO(tkchin): provide available keys/values for options. This will be used 68 | // for call configurations such as overriding server choice, specifying codecs 69 | // and so on. 70 | - (void)connectToRoomWithId:(NSString *)roomId 71 | options:(NSDictionary *)options; 72 | 73 | // Disconnects from the AppRTC servers and any connected clients. 74 | - (void)disconnect; 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDAppClient.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "ARDAppClient.h" 29 | 30 | #import 31 | 32 | #import "ARDMessageResponse.h" 33 | #import "ARDRegisterResponse.h" 34 | #import "ARDSignalingMessage.h" 35 | #import "ARDUtilities.h" 36 | #import "ARDWebSocketChannel.h" 37 | #import "RTCICECandidate+JSON.h" 38 | #import "RTCICEServer+JSON.h" 39 | #import "RTCMediaConstraints.h" 40 | #import "RTCMediaStream.h" 41 | #import "RTCPair.h" 42 | #import "RTCPeerConnection.h" 43 | #import "RTCPeerConnectionDelegate.h" 44 | #import "RTCPeerConnectionFactory.h" 45 | #import "RTCSessionDescription+JSON.h" 46 | #import "RTCSessionDescriptionDelegate.h" 47 | #import "RTCVideoCapturer.h" 48 | #import "RTCVideoTrack.h" 49 | 50 | // TODO(tkchin): move these to a configuration object. 51 | static NSString *kARDRoomServerHostUrl = 52 | @"https://apprtc.appspot.com"; 53 | static NSString *kARDRoomServerRegisterFormat = 54 | @"https://apprtc.appspot.com/register/%@"; 55 | static NSString *kARDRoomServerMessageFormat = 56 | @"https://apprtc.appspot.com/message/%@/%@"; 57 | static NSString *kARDRoomServerByeFormat = 58 | @"https://apprtc.appspot.com/bye/%@/%@"; 59 | 60 | static NSString *kARDDefaultSTUNServerUrl = 61 | @"stun:stun.l.google.com:19302"; 62 | // TODO(tkchin): figure out a better username for CEOD statistics. 63 | static NSString *kARDTurnRequestUrl = 64 | @"https://computeengineondemand.appspot.com" 65 | @"/turn?username=iapprtc&key=4080218913"; 66 | 67 | static NSString *kARDAppClientErrorDomain = @"ARDAppClient"; 68 | static NSInteger kARDAppClientErrorUnknown = -1; 69 | static NSInteger kARDAppClientErrorRoomFull = -2; 70 | static NSInteger kARDAppClientErrorCreateSDP = -3; 71 | static NSInteger kARDAppClientErrorSetSDP = -4; 72 | static NSInteger kARDAppClientErrorNetwork = -5; 73 | static NSInteger kARDAppClientErrorInvalidClient = -6; 74 | static NSInteger kARDAppClientErrorInvalidRoom = -7; 75 | 76 | @interface ARDAppClient () 78 | @property(nonatomic, strong) ARDWebSocketChannel *channel; 79 | @property(nonatomic, strong) RTCPeerConnection *peerConnection; 80 | @property(nonatomic, strong) RTCPeerConnectionFactory *factory; 81 | @property(nonatomic, strong) NSMutableArray *messageQueue; 82 | 83 | @property(nonatomic, assign) BOOL isTurnComplete; 84 | @property(nonatomic, assign) BOOL hasReceivedSdp; 85 | @property(nonatomic, readonly) BOOL isRegisteredWithRoomServer; 86 | 87 | @property(nonatomic, strong) NSString *roomId; 88 | @property(nonatomic, strong) NSString *clientId; 89 | @property(nonatomic, assign) BOOL isInitiator; 90 | @property(nonatomic, strong) NSMutableArray *iceServers; 91 | @property(nonatomic, strong) NSURL *webSocketURL; 92 | @property(nonatomic, strong) NSURL *webSocketRestURL; 93 | @end 94 | 95 | @implementation ARDAppClient 96 | 97 | @synthesize delegate = _delegate; 98 | @synthesize state = _state; 99 | @synthesize channel = _channel; 100 | @synthesize peerConnection = _peerConnection; 101 | @synthesize factory = _factory; 102 | @synthesize messageQueue = _messageQueue; 103 | @synthesize isTurnComplete = _isTurnComplete; 104 | @synthesize hasReceivedSdp = _hasReceivedSdp; 105 | @synthesize roomId = _roomId; 106 | @synthesize clientId = _clientId; 107 | @synthesize isInitiator = _isInitiator; 108 | @synthesize iceServers = _iceServers; 109 | @synthesize webSocketURL = _websocketURL; 110 | @synthesize webSocketRestURL = _websocketRestURL; 111 | 112 | - (instancetype)initWithDelegate:(id)delegate { 113 | if (self = [super init]) { 114 | _delegate = delegate; 115 | _factory = [[RTCPeerConnectionFactory alloc] init]; 116 | _messageQueue = [NSMutableArray array]; 117 | _iceServers = [NSMutableArray arrayWithObject:[self defaultSTUNServer]]; 118 | } 119 | return self; 120 | } 121 | 122 | - (void)dealloc { 123 | [self disconnect]; 124 | } 125 | 126 | - (void)setState:(ARDAppClientState)state { 127 | if (_state == state) { 128 | return; 129 | } 130 | _state = state; 131 | [_delegate appClient:self didChangeState:_state]; 132 | } 133 | 134 | - (void)connectToRoomWithId:(NSString *)roomId 135 | options:(NSDictionary *)options { 136 | NSParameterAssert(roomId.length); 137 | NSParameterAssert(_state == kARDAppClientStateDisconnected); 138 | self.state = kARDAppClientStateConnecting; 139 | 140 | // Request TURN. 141 | __weak ARDAppClient *weakSelf = self; 142 | NSURL *turnRequestURL = [NSURL URLWithString:kARDTurnRequestUrl]; 143 | [self requestTURNServersWithURL:turnRequestURL 144 | completionHandler:^(NSArray *turnServers) { 145 | ARDAppClient *strongSelf = weakSelf; 146 | [strongSelf.iceServers addObjectsFromArray:turnServers]; 147 | strongSelf.isTurnComplete = YES; 148 | [strongSelf startSignalingIfReady]; 149 | }]; 150 | 151 | // Register with room server. 152 | [self registerWithRoomServerForRoomId:roomId 153 | completionHandler:^(ARDRegisterResponse *response) { 154 | ARDAppClient *strongSelf = weakSelf; 155 | if (!response || response.result != kARDRegisterResultTypeSuccess) { 156 | NSLog(@"Failed to register with room server. Result:%d", 157 | (int)response.result); 158 | [strongSelf disconnect]; 159 | NSDictionary *userInfo = @{ 160 | NSLocalizedDescriptionKey: @"Room is full.", 161 | }; 162 | NSError *error = 163 | [[NSError alloc] initWithDomain:kARDAppClientErrorDomain 164 | code:kARDAppClientErrorRoomFull 165 | userInfo:userInfo]; 166 | [strongSelf.delegate appClient:strongSelf didError:error]; 167 | return; 168 | } 169 | NSLog(@"Registered with room server."); 170 | strongSelf.roomId = response.roomId; 171 | strongSelf.clientId = response.clientId; 172 | strongSelf.isInitiator = response.isInitiator; 173 | for (ARDSignalingMessage *message in response.messages) { 174 | if (message.type == kARDSignalingMessageTypeOffer || 175 | message.type == kARDSignalingMessageTypeAnswer) { 176 | strongSelf.hasReceivedSdp = YES; 177 | [strongSelf.messageQueue insertObject:message atIndex:0]; 178 | } else { 179 | [strongSelf.messageQueue addObject:message]; 180 | } 181 | } 182 | strongSelf.webSocketURL = response.webSocketURL; 183 | strongSelf.webSocketRestURL = response.webSocketRestURL; 184 | [strongSelf registerWithColliderIfReady]; 185 | [strongSelf startSignalingIfReady]; 186 | }]; 187 | } 188 | 189 | - (void)disconnect { 190 | if (_state == kARDAppClientStateDisconnected) { 191 | return; 192 | } 193 | if (self.isRegisteredWithRoomServer) { 194 | [self unregisterWithRoomServer]; 195 | } 196 | if (_channel) { 197 | if (_channel.state == kARDWebSocketChannelStateRegistered) { 198 | // Tell the other client we're hanging up. 199 | ARDByeMessage *byeMessage = [[ARDByeMessage alloc] init]; 200 | NSData *byeData = [byeMessage JSONData]; 201 | [_channel sendData:byeData]; 202 | } 203 | // Disconnect from collider. 204 | _channel = nil; 205 | } 206 | _clientId = nil; 207 | _roomId = nil; 208 | _isInitiator = NO; 209 | _hasReceivedSdp = NO; 210 | _messageQueue = [NSMutableArray array]; 211 | _peerConnection = nil; 212 | self.state = kARDAppClientStateDisconnected; 213 | } 214 | 215 | #pragma mark - ARDWebSocketChannelDelegate 216 | 217 | - (void)channel:(ARDWebSocketChannel *)channel 218 | didReceiveMessage:(ARDSignalingMessage *)message { 219 | switch (message.type) { 220 | case kARDSignalingMessageTypeOffer: 221 | case kARDSignalingMessageTypeAnswer: 222 | _hasReceivedSdp = YES; 223 | [_messageQueue insertObject:message atIndex:0]; 224 | break; 225 | case kARDSignalingMessageTypeCandidate: 226 | [_messageQueue addObject:message]; 227 | break; 228 | case kARDSignalingMessageTypeBye: 229 | [self processSignalingMessage:message]; 230 | return; 231 | } 232 | [self drainMessageQueueIfReady]; 233 | } 234 | 235 | - (void)channel:(ARDWebSocketChannel *)channel 236 | didChangeState:(ARDWebSocketChannelState)state { 237 | switch (state) { 238 | case kARDWebSocketChannelStateOpen: 239 | break; 240 | case kARDWebSocketChannelStateRegistered: 241 | break; 242 | case kARDWebSocketChannelStateClosed: 243 | case kARDWebSocketChannelStateError: 244 | // TODO(tkchin): reconnection scenarios. Right now we just disconnect 245 | // completely if the websocket connection fails. 246 | [self disconnect]; 247 | break; 248 | } 249 | } 250 | 251 | #pragma mark - RTCPeerConnectionDelegate 252 | 253 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 254 | signalingStateChanged:(RTCSignalingState)stateChanged { 255 | NSLog(@"Signaling state changed: %d", stateChanged); 256 | } 257 | 258 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 259 | addedStream:(RTCMediaStream *)stream { 260 | dispatch_async(dispatch_get_main_queue(), ^{ 261 | NSLog(@"Received %lu video tracks and %lu audio tracks", 262 | (unsigned long)stream.videoTracks.count, 263 | (unsigned long)stream.audioTracks.count); 264 | if (stream.videoTracks.count) { 265 | RTCVideoTrack *videoTrack = stream.videoTracks[0]; 266 | [_delegate appClient:self didReceiveRemoteVideoTrack:videoTrack]; 267 | } 268 | }); 269 | } 270 | 271 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 272 | removedStream:(RTCMediaStream *)stream { 273 | NSLog(@"Stream was removed."); 274 | } 275 | 276 | - (void)peerConnectionOnRenegotiationNeeded: 277 | (RTCPeerConnection *)peerConnection { 278 | NSLog(@"WARNING: Renegotiation needed but unimplemented."); 279 | } 280 | 281 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 282 | iceConnectionChanged:(RTCICEConnectionState)newState { 283 | NSLog(@"ICE state changed: %d", newState); 284 | } 285 | 286 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 287 | iceGatheringChanged:(RTCICEGatheringState)newState { 288 | NSLog(@"ICE gathering state changed: %d", newState); 289 | } 290 | 291 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 292 | gotICECandidate:(RTCICECandidate *)candidate { 293 | dispatch_async(dispatch_get_main_queue(), ^{ 294 | ARDICECandidateMessage *message = 295 | [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; 296 | [self sendSignalingMessage:message]; 297 | }); 298 | } 299 | 300 | - (void)peerConnection:(RTCPeerConnection*)peerConnection 301 | didOpenDataChannel:(RTCDataChannel*)dataChannel { 302 | } 303 | 304 | #pragma mark - RTCSessionDescriptionDelegate 305 | 306 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 307 | didCreateSessionDescription:(RTCSessionDescription *)sdp 308 | error:(NSError *)error { 309 | dispatch_async(dispatch_get_main_queue(), ^{ 310 | if (error) { 311 | NSLog(@"Failed to create session description. Error: %@", error); 312 | [self disconnect]; 313 | NSDictionary *userInfo = @{ 314 | NSLocalizedDescriptionKey: @"Failed to create session description.", 315 | }; 316 | NSError *sdpError = 317 | [[NSError alloc] initWithDomain:kARDAppClientErrorDomain 318 | code:kARDAppClientErrorCreateSDP 319 | userInfo:userInfo]; 320 | [_delegate appClient:self didError:sdpError]; 321 | return; 322 | } 323 | [_peerConnection setLocalDescriptionWithDelegate:self 324 | sessionDescription:sdp]; 325 | ARDSessionDescriptionMessage *message = 326 | [[ARDSessionDescriptionMessage alloc] initWithDescription:sdp]; 327 | [self sendSignalingMessage:message]; 328 | }); 329 | } 330 | 331 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 332 | didSetSessionDescriptionWithError:(NSError *)error { 333 | dispatch_async(dispatch_get_main_queue(), ^{ 334 | if (error) { 335 | NSLog(@"Failed to set session description. Error: %@", error); 336 | [self disconnect]; 337 | NSDictionary *userInfo = @{ 338 | NSLocalizedDescriptionKey: @"Failed to set session description.", 339 | }; 340 | NSError *sdpError = 341 | [[NSError alloc] initWithDomain:kARDAppClientErrorDomain 342 | code:kARDAppClientErrorSetSDP 343 | userInfo:userInfo]; 344 | [_delegate appClient:self didError:sdpError]; 345 | return; 346 | } 347 | // If we're answering and we've just set the remote offer we need to create 348 | // an answer and set the local description. 349 | if (!_isInitiator && !_peerConnection.localDescription) { 350 | RTCMediaConstraints *constraints = [self defaultAnswerConstraints]; 351 | [_peerConnection createAnswerWithDelegate:self 352 | constraints:constraints]; 353 | 354 | } 355 | }); 356 | } 357 | 358 | #pragma mark - Private 359 | 360 | - (BOOL)isRegisteredWithRoomServer { 361 | return _clientId.length; 362 | } 363 | 364 | - (void)startSignalingIfReady { 365 | if (!_isTurnComplete || !self.isRegisteredWithRoomServer) { 366 | return; 367 | } 368 | self.state = kARDAppClientStateConnected; 369 | 370 | // Create peer connection. 371 | RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; 372 | _peerConnection = [_factory peerConnectionWithICEServers:_iceServers 373 | constraints:constraints 374 | delegate:self]; 375 | RTCMediaStream *localStream = [self createLocalMediaStream]; 376 | [_peerConnection addStream:localStream]; 377 | if (_isInitiator) { 378 | [self sendOffer]; 379 | } else { 380 | [self waitForAnswer]; 381 | } 382 | } 383 | 384 | - (void)sendOffer { 385 | [_peerConnection createOfferWithDelegate:self 386 | constraints:[self defaultOfferConstraints]]; 387 | } 388 | 389 | - (void)waitForAnswer { 390 | [self drainMessageQueueIfReady]; 391 | } 392 | 393 | - (void)drainMessageQueueIfReady { 394 | if (!_peerConnection || !_hasReceivedSdp) { 395 | return; 396 | } 397 | for (ARDSignalingMessage *message in _messageQueue) { 398 | [self processSignalingMessage:message]; 399 | } 400 | [_messageQueue removeAllObjects]; 401 | } 402 | 403 | - (void)processSignalingMessage:(ARDSignalingMessage *)message { 404 | NSParameterAssert(_peerConnection || 405 | message.type == kARDSignalingMessageTypeBye); 406 | switch (message.type) { 407 | case kARDSignalingMessageTypeOffer: 408 | case kARDSignalingMessageTypeAnswer: { 409 | ARDSessionDescriptionMessage *sdpMessage = 410 | (ARDSessionDescriptionMessage *)message; 411 | RTCSessionDescription *description = sdpMessage.sessionDescription; 412 | [_peerConnection setRemoteDescriptionWithDelegate:self 413 | sessionDescription:description]; 414 | break; 415 | } 416 | case kARDSignalingMessageTypeCandidate: { 417 | ARDICECandidateMessage *candidateMessage = 418 | (ARDICECandidateMessage *)message; 419 | [_peerConnection addICECandidate:candidateMessage.candidate]; 420 | break; 421 | } 422 | case kARDSignalingMessageTypeBye: 423 | // Other client disconnected. 424 | // TODO(tkchin): support waiting in room for next client. For now just 425 | // disconnect. 426 | [self disconnect]; 427 | break; 428 | } 429 | } 430 | 431 | - (void)sendSignalingMessage:(ARDSignalingMessage *)message { 432 | if (_isInitiator) { 433 | [self sendSignalingMessageToRoomServer:message completionHandler:nil]; 434 | } else { 435 | [self sendSignalingMessageToCollider:message]; 436 | } 437 | } 438 | 439 | - (RTCMediaStream *)createLocalMediaStream { 440 | RTCMediaStream* localStream = [_factory mediaStreamWithLabel:@"ARDAMS"]; 441 | RTCVideoTrack* localVideoTrack = nil; 442 | 443 | // The iOS simulator doesn't provide any sort of camera capture 444 | // support or emulation (http://goo.gl/rHAnC1) so don't bother 445 | // trying to open a local stream. 446 | // TODO(tkchin): local video capture for OSX. See 447 | // https://code.google.com/p/webrtc/issues/detail?id=3417. 448 | #if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE 449 | NSString *cameraID = nil; 450 | for (AVCaptureDevice *captureDevice in 451 | [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) { 452 | if (captureDevice.position == AVCaptureDevicePositionFront) { 453 | cameraID = [captureDevice localizedName]; 454 | break; 455 | } 456 | } 457 | NSAssert(cameraID, @"Unable to get the front camera id"); 458 | 459 | RTCVideoCapturer *capturer = 460 | [RTCVideoCapturer capturerWithDeviceName:cameraID]; 461 | RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints]; 462 | RTCVideoSource *videoSource = 463 | [_factory videoSourceWithCapturer:capturer 464 | constraints:mediaConstraints]; 465 | localVideoTrack = 466 | [_factory videoTrackWithID:@"ARDAMSv0" source:videoSource]; 467 | if (localVideoTrack) { 468 | [localStream addVideoTrack:localVideoTrack]; 469 | } 470 | [_delegate appClient:self didReceiveLocalVideoTrack:localVideoTrack]; 471 | #endif 472 | [localStream addAudioTrack:[_factory audioTrackWithID:@"ARDAMSa0"]]; 473 | return localStream; 474 | } 475 | 476 | - (void)requestTURNServersWithURL:(NSURL *)requestURL 477 | completionHandler:(void (^)(NSArray *turnServers))completionHandler { 478 | NSParameterAssert([requestURL absoluteString].length); 479 | NSMutableURLRequest *request = 480 | [NSMutableURLRequest requestWithURL:requestURL]; 481 | // We need to set origin because TURN provider whitelists requests based on 482 | // origin. 483 | [request addValue:@"Mozilla/5.0" forHTTPHeaderField:@"user-agent"]; 484 | [request addValue:kARDRoomServerHostUrl forHTTPHeaderField:@"origin"]; 485 | [NSURLConnection sendAsyncRequest:request 486 | completionHandler:^(NSURLResponse *response, 487 | NSData *data, 488 | NSError *error) { 489 | NSArray *turnServers = [NSArray array]; 490 | if (error) { 491 | NSLog(@"Unable to get TURN server."); 492 | completionHandler(turnServers); 493 | return; 494 | } 495 | NSDictionary *dict = [NSDictionary dictionaryWithJSONData:data]; 496 | turnServers = [RTCICEServer serversFromCEODJSONDictionary:dict]; 497 | completionHandler(turnServers); 498 | }]; 499 | } 500 | 501 | #pragma mark - Room server methods 502 | 503 | - (void)registerWithRoomServerForRoomId:(NSString *)roomId 504 | completionHandler:(void (^)(ARDRegisterResponse *))completionHandler { 505 | NSString *urlString = 506 | [NSString stringWithFormat:kARDRoomServerRegisterFormat, roomId]; 507 | NSURL *roomURL = [NSURL URLWithString:urlString]; 508 | NSLog(@"Registering with room server."); 509 | __weak ARDAppClient *weakSelf = self; 510 | [NSURLConnection sendAsyncPostToURL:roomURL 511 | withData:nil 512 | completionHandler:^(BOOL succeeded, NSData *data) { 513 | ARDAppClient *strongSelf = weakSelf; 514 | if (!succeeded) { 515 | NSError *error = [self roomServerNetworkError]; 516 | [strongSelf.delegate appClient:strongSelf didError:error]; 517 | completionHandler(nil); 518 | return; 519 | } 520 | ARDRegisterResponse *response = 521 | [ARDRegisterResponse responseFromJSONData:data]; 522 | completionHandler(response); 523 | }]; 524 | } 525 | 526 | - (void)sendSignalingMessageToRoomServer:(ARDSignalingMessage *)message 527 | completionHandler:(void (^)(ARDMessageResponse *))completionHandler { 528 | NSData *data = [message JSONData]; 529 | NSString *urlString = 530 | [NSString stringWithFormat: 531 | kARDRoomServerMessageFormat, _roomId, _clientId]; 532 | NSURL *url = [NSURL URLWithString:urlString]; 533 | NSLog(@"C->RS POST: %@", message); 534 | __weak ARDAppClient *weakSelf = self; 535 | [NSURLConnection sendAsyncPostToURL:url 536 | withData:data 537 | completionHandler:^(BOOL succeeded, NSData *data) { 538 | ARDAppClient *strongSelf = weakSelf; 539 | if (!succeeded) { 540 | NSError *error = [self roomServerNetworkError]; 541 | [strongSelf.delegate appClient:strongSelf didError:error]; 542 | return; 543 | } 544 | ARDMessageResponse *response = 545 | [ARDMessageResponse responseFromJSONData:data]; 546 | NSError *error = nil; 547 | switch (response.result) { 548 | case kARDMessageResultTypeSuccess: 549 | break; 550 | case kARDMessageResultTypeUnknown: 551 | error = 552 | [[NSError alloc] initWithDomain:kARDAppClientErrorDomain 553 | code:kARDAppClientErrorUnknown 554 | userInfo:@{ 555 | NSLocalizedDescriptionKey: @"Unknown error.", 556 | }]; 557 | case kARDMessageResultTypeInvalidClient: 558 | error = 559 | [[NSError alloc] initWithDomain:kARDAppClientErrorDomain 560 | code:kARDAppClientErrorInvalidClient 561 | userInfo:@{ 562 | NSLocalizedDescriptionKey: @"Invalid client.", 563 | }]; 564 | break; 565 | case kARDMessageResultTypeInvalidRoom: 566 | error = 567 | [[NSError alloc] initWithDomain:kARDAppClientErrorDomain 568 | code:kARDAppClientErrorInvalidRoom 569 | userInfo:@{ 570 | NSLocalizedDescriptionKey: @"Invalid room.", 571 | }]; 572 | break; 573 | }; 574 | if (error) { 575 | [strongSelf.delegate appClient:strongSelf didError:error]; 576 | } 577 | if (completionHandler) { 578 | completionHandler(response); 579 | } 580 | }]; 581 | } 582 | 583 | - (void)unregisterWithRoomServer { 584 | NSString *urlString = 585 | [NSString stringWithFormat:kARDRoomServerByeFormat, _roomId, _clientId]; 586 | NSURL *url = [NSURL URLWithString:urlString]; 587 | NSURLRequest *request = [NSURLRequest requestWithURL:url]; 588 | NSURLResponse *response = nil; 589 | // We want a synchronous request so that we know that we're unregistered from 590 | // room server before we do any further unregistration. 591 | NSLog(@"C->RS: BYE"); 592 | NSError *error = nil; 593 | [NSURLConnection sendSynchronousRequest:request 594 | returningResponse:&response 595 | error:&error]; 596 | if (error) { 597 | NSLog(@"Error unregistering from room server: %@", error); 598 | } 599 | NSLog(@"Unregistered from room server."); 600 | } 601 | 602 | - (NSError *)roomServerNetworkError { 603 | NSError *error = 604 | [[NSError alloc] initWithDomain:kARDAppClientErrorDomain 605 | code:kARDAppClientErrorNetwork 606 | userInfo:@{ 607 | NSLocalizedDescriptionKey: @"Room server network error", 608 | }]; 609 | return error; 610 | } 611 | 612 | #pragma mark - Collider methods 613 | 614 | - (void)registerWithColliderIfReady { 615 | if (!self.isRegisteredWithRoomServer) { 616 | return; 617 | } 618 | // Open WebSocket connection. 619 | _channel = 620 | [[ARDWebSocketChannel alloc] initWithURL:_websocketURL 621 | restURL:_websocketRestURL 622 | delegate:self]; 623 | [_channel registerForRoomId:_roomId clientId:_clientId]; 624 | } 625 | 626 | - (void)sendSignalingMessageToCollider:(ARDSignalingMessage *)message { 627 | NSData *data = [message JSONData]; 628 | [_channel sendData:data]; 629 | } 630 | 631 | #pragma mark - Defaults 632 | 633 | - (RTCMediaConstraints *)defaultMediaStreamConstraints { 634 | RTCMediaConstraints* constraints = 635 | [[RTCMediaConstraints alloc] 636 | initWithMandatoryConstraints:nil 637 | optionalConstraints:nil]; 638 | return constraints; 639 | } 640 | 641 | - (RTCMediaConstraints *)defaultAnswerConstraints { 642 | return [self defaultOfferConstraints]; 643 | } 644 | 645 | - (RTCMediaConstraints *)defaultOfferConstraints { 646 | NSArray *mandatoryConstraints = @[ 647 | [[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"], 648 | [[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"] 649 | ]; 650 | RTCMediaConstraints* constraints = 651 | [[RTCMediaConstraints alloc] 652 | initWithMandatoryConstraints:mandatoryConstraints 653 | optionalConstraints:nil]; 654 | return constraints; 655 | } 656 | 657 | - (RTCMediaConstraints *)defaultPeerConnectionConstraints { 658 | NSArray *optionalConstraints = @[ 659 | [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"] 660 | ]; 661 | RTCMediaConstraints* constraints = 662 | [[RTCMediaConstraints alloc] 663 | initWithMandatoryConstraints:nil 664 | optionalConstraints:optionalConstraints]; 665 | return constraints; 666 | } 667 | 668 | - (RTCICEServer *)defaultSTUNServer { 669 | NSURL *defaultSTUNServerURL = [NSURL URLWithString:kARDDefaultSTUNServerUrl]; 670 | return [[RTCICEServer alloc] initWithURI:defaultSTUNServerURL 671 | username:@"" 672 | password:@""]; 673 | } 674 | 675 | @end 676 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDMessageResponse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | typedef NS_ENUM(NSInteger, ARDMessageResultType) { 31 | kARDMessageResultTypeUnknown, 32 | kARDMessageResultTypeSuccess, 33 | kARDMessageResultTypeInvalidRoom, 34 | kARDMessageResultTypeInvalidClient 35 | }; 36 | 37 | @interface ARDMessageResponse : NSObject 38 | 39 | @property(nonatomic, readonly) ARDMessageResultType result; 40 | 41 | + (ARDMessageResponse *)responseFromJSONData:(NSData *)data; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDMessageResponse.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "ARDMessageResponse.h" 29 | 30 | #import "ARDUtilities.h" 31 | 32 | static NSString const *kARDMessageResultKey = @"result"; 33 | 34 | @interface ARDMessageResponse () 35 | 36 | @property(nonatomic, assign) ARDMessageResultType result; 37 | 38 | @end 39 | 40 | @implementation ARDMessageResponse 41 | 42 | @synthesize result = _result; 43 | 44 | + (ARDMessageResponse *)responseFromJSONData:(NSData *)data { 45 | NSDictionary *responseJSON = [NSDictionary dictionaryWithJSONData:data]; 46 | if (!responseJSON) { 47 | return nil; 48 | } 49 | ARDMessageResponse *response = [[ARDMessageResponse alloc] init]; 50 | response.result = 51 | [[self class] resultTypeFromString:responseJSON[kARDMessageResultKey]]; 52 | return response; 53 | } 54 | 55 | #pragma mark - Private 56 | 57 | + (ARDMessageResultType)resultTypeFromString:(NSString *)resultString { 58 | ARDMessageResultType result = kARDMessageResultTypeUnknown; 59 | if ([resultString isEqualToString:@"SUCCESS"]) { 60 | result = kARDMessageResultTypeSuccess; 61 | } else if ([resultString isEqualToString:@"INVALID_CLIENT"]) { 62 | result = kARDMessageResultTypeInvalidClient; 63 | } else if ([resultString isEqualToString:@"INVALID_ROOM"]) { 64 | result = kARDMessageResultTypeInvalidRoom; 65 | } 66 | return result; 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDRegisterResponse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | typedef NS_ENUM(NSInteger, ARDRegisterResultType) { 31 | kARDRegisterResultTypeUnknown, 32 | kARDRegisterResultTypeSuccess, 33 | kARDRegisterResultTypeFull 34 | }; 35 | 36 | // Result of registering with the GAE server. 37 | @interface ARDRegisterResponse : NSObject 38 | 39 | @property(nonatomic, readonly) ARDRegisterResultType result; 40 | @property(nonatomic, readonly) BOOL isInitiator; 41 | @property(nonatomic, readonly) NSString *roomId; 42 | @property(nonatomic, readonly) NSString *clientId; 43 | @property(nonatomic, readonly) NSArray *messages; 44 | @property(nonatomic, readonly) NSURL *webSocketURL; 45 | @property(nonatomic, readonly) NSURL *webSocketRestURL; 46 | 47 | + (ARDRegisterResponse *)responseFromJSONData:(NSData *)data; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDRegisterResponse.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "ARDRegisterResponse.h" 29 | 30 | #import "ARDSignalingMessage.h" 31 | #import "ARDUtilities.h" 32 | #import "RTCICEServer+JSON.h" 33 | 34 | static NSString const *kARDRegisterResultKey = @"result"; 35 | static NSString const *kARDRegisterResultParamsKey = @"params"; 36 | static NSString const *kARDRegisterInitiatorKey = @"is_initiator"; 37 | static NSString const *kARDRegisterRoomIdKey = @"room_id"; 38 | static NSString const *kARDRegisterClientIdKey = @"client_id"; 39 | static NSString const *kARDRegisterMessagesKey = @"messages"; 40 | static NSString const *kARDRegisterWebSocketURLKey = @"wss_url"; 41 | static NSString const *kARDRegisterWebSocketRestURLKey = @"wss_post_url"; 42 | 43 | @interface ARDRegisterResponse () 44 | 45 | @property(nonatomic, assign) ARDRegisterResultType result; 46 | @property(nonatomic, assign) BOOL isInitiator; 47 | @property(nonatomic, strong) NSString *roomId; 48 | @property(nonatomic, strong) NSString *clientId; 49 | @property(nonatomic, strong) NSArray *messages; 50 | @property(nonatomic, strong) NSURL *webSocketURL; 51 | @property(nonatomic, strong) NSURL *webSocketRestURL; 52 | 53 | @end 54 | 55 | @implementation ARDRegisterResponse 56 | 57 | @synthesize result = _result; 58 | @synthesize isInitiator = _isInitiator; 59 | @synthesize roomId = _roomId; 60 | @synthesize clientId = _clientId; 61 | @synthesize messages = _messages; 62 | @synthesize webSocketURL = _webSocketURL; 63 | @synthesize webSocketRestURL = _webSocketRestURL; 64 | 65 | + (ARDRegisterResponse *)responseFromJSONData:(NSData *)data { 66 | NSDictionary *responseJSON = [NSDictionary dictionaryWithJSONData:data]; 67 | if (!responseJSON) { 68 | return nil; 69 | } 70 | ARDRegisterResponse *response = [[ARDRegisterResponse alloc] init]; 71 | NSString *resultString = responseJSON[kARDRegisterResultKey]; 72 | response.result = [[self class] resultTypeFromString:resultString]; 73 | NSDictionary *params = responseJSON[kARDRegisterResultParamsKey]; 74 | 75 | response.isInitiator = [params[kARDRegisterInitiatorKey] boolValue]; 76 | response.roomId = params[kARDRegisterRoomIdKey]; 77 | response.clientId = params[kARDRegisterClientIdKey]; 78 | 79 | // Parse messages. 80 | NSArray *messages = params[kARDRegisterMessagesKey]; 81 | NSMutableArray *signalingMessages = 82 | [NSMutableArray arrayWithCapacity:messages.count]; 83 | for (NSString *message in messages) { 84 | ARDSignalingMessage *signalingMessage = 85 | [ARDSignalingMessage messageFromJSONString:message]; 86 | [signalingMessages addObject:signalingMessage]; 87 | } 88 | response.messages = signalingMessages; 89 | 90 | // Parse websocket urls. 91 | NSString *webSocketURLString = params[kARDRegisterWebSocketURLKey]; 92 | response.webSocketURL = [NSURL URLWithString:webSocketURLString]; 93 | NSString *webSocketRestURLString = params[kARDRegisterWebSocketRestURLKey]; 94 | response.webSocketRestURL = [NSURL URLWithString:webSocketRestURLString]; 95 | 96 | return response; 97 | } 98 | 99 | #pragma mark - Private 100 | 101 | + (ARDRegisterResultType)resultTypeFromString:(NSString *)resultString { 102 | ARDRegisterResultType result = kARDRegisterResultTypeUnknown; 103 | if ([resultString isEqualToString:@"SUCCESS"]) { 104 | result = kARDRegisterResultTypeSuccess; 105 | } else if ([resultString isEqualToString:@"FULL"]) { 106 | result = kARDRegisterResultTypeFull; 107 | } 108 | return result; 109 | } 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDSignalingMessage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #import "RTCICECandidate.h" 31 | #import "RTCSessionDescription.h" 32 | 33 | typedef enum { 34 | kARDSignalingMessageTypeCandidate, 35 | kARDSignalingMessageTypeOffer, 36 | kARDSignalingMessageTypeAnswer, 37 | kARDSignalingMessageTypeBye, 38 | } ARDSignalingMessageType; 39 | 40 | @interface ARDSignalingMessage : NSObject 41 | 42 | @property(nonatomic, readonly) ARDSignalingMessageType type; 43 | 44 | + (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString; 45 | - (NSData *)JSONData; 46 | 47 | @end 48 | 49 | @interface ARDICECandidateMessage : ARDSignalingMessage 50 | 51 | @property(nonatomic, readonly) RTCICECandidate *candidate; 52 | 53 | - (instancetype)initWithCandidate:(RTCICECandidate *)candidate; 54 | 55 | @end 56 | 57 | @interface ARDSessionDescriptionMessage : ARDSignalingMessage 58 | 59 | @property(nonatomic, readonly) RTCSessionDescription *sessionDescription; 60 | 61 | - (instancetype)initWithDescription:(RTCSessionDescription *)description; 62 | 63 | @end 64 | 65 | @interface ARDByeMessage : ARDSignalingMessage 66 | @end 67 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDSignalingMessage.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "ARDSignalingMessage.h" 29 | 30 | #import "ARDUtilities.h" 31 | #import "RTCICECandidate+JSON.h" 32 | #import "RTCSessionDescription+JSON.h" 33 | 34 | static NSString const *kARDSignalingMessageTypeKey = @"type"; 35 | 36 | @implementation ARDSignalingMessage 37 | 38 | @synthesize type = _type; 39 | 40 | - (instancetype)initWithType:(ARDSignalingMessageType)type { 41 | if (self = [super init]) { 42 | _type = type; 43 | } 44 | return self; 45 | } 46 | 47 | - (NSString *)description { 48 | return [[NSString alloc] initWithData:[self JSONData] 49 | encoding:NSUTF8StringEncoding]; 50 | } 51 | 52 | + (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString { 53 | NSDictionary *values = [NSDictionary dictionaryWithJSONString:jsonString]; 54 | if (!values) { 55 | NSLog(@"Error parsing signaling message JSON."); 56 | return nil; 57 | } 58 | 59 | NSString *typeString = values[kARDSignalingMessageTypeKey]; 60 | ARDSignalingMessage *message = nil; 61 | if ([typeString isEqualToString:@"candidate"]) { 62 | RTCICECandidate *candidate = 63 | [RTCICECandidate candidateFromJSONDictionary:values]; 64 | message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; 65 | } else if ([typeString isEqualToString:@"offer"] || 66 | [typeString isEqualToString:@"answer"]) { 67 | RTCSessionDescription *description = 68 | [RTCSessionDescription descriptionFromJSONDictionary:values]; 69 | message = 70 | [[ARDSessionDescriptionMessage alloc] initWithDescription:description]; 71 | } else if ([typeString isEqualToString:@"bye"]) { 72 | message = [[ARDByeMessage alloc] init]; 73 | } else { 74 | NSLog(@"Unexpected type: %@", typeString); 75 | } 76 | return message; 77 | } 78 | 79 | - (NSData *)JSONData { 80 | return nil; 81 | } 82 | 83 | @end 84 | 85 | @implementation ARDICECandidateMessage 86 | 87 | @synthesize candidate = _candidate; 88 | 89 | - (instancetype)initWithCandidate:(RTCICECandidate *)candidate { 90 | if (self = [super initWithType:kARDSignalingMessageTypeCandidate]) { 91 | _candidate = candidate; 92 | } 93 | return self; 94 | } 95 | 96 | - (NSData *)JSONData { 97 | return [_candidate JSONData]; 98 | } 99 | 100 | @end 101 | 102 | @implementation ARDSessionDescriptionMessage 103 | 104 | @synthesize sessionDescription = _sessionDescription; 105 | 106 | - (instancetype)initWithDescription:(RTCSessionDescription *)description { 107 | ARDSignalingMessageType type = kARDSignalingMessageTypeOffer; 108 | NSString *typeString = description.type; 109 | if ([typeString isEqualToString:@"offer"]) { 110 | type = kARDSignalingMessageTypeOffer; 111 | } else if ([typeString isEqualToString:@"answer"]) { 112 | type = kARDSignalingMessageTypeAnswer; 113 | } else { 114 | NSAssert(NO, @"Unexpected type: %@", typeString); 115 | } 116 | if (self = [super initWithType:type]) { 117 | _sessionDescription = description; 118 | } 119 | return self; 120 | } 121 | 122 | - (NSData *)JSONData { 123 | return [_sessionDescription JSONData]; 124 | } 125 | 126 | @end 127 | 128 | @implementation ARDByeMessage 129 | 130 | - (instancetype)init { 131 | return [super initWithType:kARDSignalingMessageTypeBye]; 132 | } 133 | 134 | - (NSData *)JSONData { 135 | NSDictionary *message = @{ 136 | @"type": @"bye" 137 | }; 138 | return [NSJSONSerialization dataWithJSONObject:message 139 | options:NSJSONWritingPrettyPrinted 140 | error:NULL]; 141 | } 142 | 143 | @end 144 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDUtilities.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | @interface NSDictionary (ARDUtilites) 31 | 32 | // Creates a dictionary with the keys and values in the JSON object. 33 | + (NSDictionary *)dictionaryWithJSONString:(NSString *)jsonString; 34 | + (NSDictionary *)dictionaryWithJSONData:(NSData *)jsonData; 35 | 36 | @end 37 | 38 | @interface NSURLConnection (ARDUtilities) 39 | 40 | // Issues an asynchronous request that calls back on main queue. 41 | + (void)sendAsyncRequest:(NSURLRequest *)request 42 | completionHandler:(void (^)(NSURLResponse *response, 43 | NSData *data, 44 | NSError *error))completionHandler; 45 | 46 | // Posts data to the specified URL. 47 | + (void)sendAsyncPostToURL:(NSURL *)url 48 | withData:(NSData *)data 49 | completionHandler:(void (^)(BOOL succeeded, 50 | NSData *data))completionHandler; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDUtilities.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "ARDUtilities.h" 29 | 30 | @implementation NSDictionary (ARDUtilites) 31 | 32 | + (NSDictionary *)dictionaryWithJSONString:(NSString *)jsonString { 33 | NSParameterAssert(jsonString.length > 0); 34 | NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; 35 | NSError *error = nil; 36 | NSDictionary *dict = 37 | [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; 38 | if (error) { 39 | NSLog(@"Error parsing JSON: %@", error.localizedDescription); 40 | } 41 | return dict; 42 | } 43 | 44 | + (NSDictionary *)dictionaryWithJSONData:(NSData *)jsonData { 45 | NSError *error = nil; 46 | NSDictionary *dict = 47 | [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; 48 | if (error) { 49 | NSLog(@"Error parsing JSON: %@", error.localizedDescription); 50 | } 51 | return dict; 52 | } 53 | 54 | @end 55 | 56 | @implementation NSURLConnection (ARDUtilities) 57 | 58 | + (void)sendAsyncRequest:(NSURLRequest *)request 59 | completionHandler:(void (^)(NSURLResponse *response, 60 | NSData *data, 61 | NSError *error))completionHandler { 62 | // Kick off an async request which will call back on main thread. 63 | [NSURLConnection sendAsynchronousRequest:request 64 | queue:[NSOperationQueue mainQueue] 65 | completionHandler:^(NSURLResponse *response, 66 | NSData *data, 67 | NSError *error) { 68 | if (completionHandler) { 69 | completionHandler(response, data, error); 70 | } 71 | }]; 72 | } 73 | 74 | // Posts data to the specified URL. 75 | + (void)sendAsyncPostToURL:(NSURL *)url 76 | withData:(NSData *)data 77 | completionHandler:(void (^)(BOOL succeeded, 78 | NSData *data))completionHandler { 79 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 80 | request.HTTPMethod = @"POST"; 81 | request.HTTPBody = data; 82 | [[self class] sendAsyncRequest:request 83 | completionHandler:^(NSURLResponse *response, 84 | NSData *data, 85 | NSError *error) { 86 | if (error) { 87 | NSLog(@"Error posting data: %@", error.localizedDescription); 88 | if (completionHandler) { 89 | completionHandler(NO, data); 90 | } 91 | return; 92 | } 93 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; 94 | if (httpResponse.statusCode != 200) { 95 | NSString *serverResponse = data.length > 0 ? 96 | [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] : 97 | nil; 98 | NSLog(@"Received bad response: %@", serverResponse); 99 | if (completionHandler) { 100 | completionHandler(NO, data); 101 | } 102 | return; 103 | } 104 | if (completionHandler) { 105 | completionHandler(YES, data); 106 | } 107 | }]; 108 | } 109 | 110 | @end 111 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDWebSocketChannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #import "ARDSignalingMessage.h" 31 | 32 | typedef NS_ENUM(NSInteger, ARDWebSocketChannelState) { 33 | // State when disconnected. 34 | kARDWebSocketChannelStateClosed, 35 | // State when connection is established but not ready for use. 36 | kARDWebSocketChannelStateOpen, 37 | // State when connection is established and registered. 38 | kARDWebSocketChannelStateRegistered, 39 | // State when connection encounters a fatal error. 40 | kARDWebSocketChannelStateError 41 | }; 42 | 43 | @class ARDWebSocketChannel; 44 | @protocol ARDWebSocketChannelDelegate 45 | 46 | - (void)channel:(ARDWebSocketChannel *)channel 47 | didChangeState:(ARDWebSocketChannelState)state; 48 | 49 | - (void)channel:(ARDWebSocketChannel *)channel 50 | didReceiveMessage:(ARDSignalingMessage *)message; 51 | 52 | @end 53 | 54 | // Wraps a WebSocket connection to the AppRTC WebSocket server. 55 | @interface ARDWebSocketChannel : NSObject 56 | 57 | @property(nonatomic, readonly) NSString *roomId; 58 | @property(nonatomic, readonly) NSString *clientId; 59 | @property(nonatomic, readonly) ARDWebSocketChannelState state; 60 | @property(nonatomic, weak) id delegate; 61 | 62 | - (instancetype)initWithURL:(NSURL *)url 63 | restURL:(NSURL *)restURL 64 | delegate:(id)delegate; 65 | 66 | // Registers with the WebSocket server for the given room and client id once 67 | // the web socket connection is open. 68 | - (void)registerForRoomId:(NSString *)roomId 69 | clientId:(NSString *)clientId; 70 | 71 | // Sends data over the WebSocket connection if registered, otherwise POSTs to 72 | // the web socket server instead. 73 | - (void)sendData:(NSData *)data; 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /AppRTCDemo/ARDWebSocketChannel.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "ARDWebSocketChannel.h" 29 | 30 | #import "ARDUtilities.h" 31 | #import "SRWebSocket.h" 32 | 33 | // TODO(tkchin): move these to a configuration object. 34 | static NSString const *kARDWSSMessageErrorKey = @"error"; 35 | static NSString const *kARDWSSMessagePayloadKey = @"msg"; 36 | 37 | @interface ARDWebSocketChannel () 38 | @end 39 | 40 | @implementation ARDWebSocketChannel { 41 | NSURL *_url; 42 | NSURL *_restURL; 43 | SRWebSocket *_socket; 44 | } 45 | 46 | @synthesize delegate = _delegate; 47 | @synthesize state = _state; 48 | @synthesize roomId = _roomId; 49 | @synthesize clientId = _clientId; 50 | 51 | - (instancetype)initWithURL:(NSURL *)url 52 | restURL:(NSURL *)restURL 53 | delegate:(id)delegate { 54 | if (self = [super init]) { 55 | _url = url; 56 | _restURL = restURL; 57 | _delegate = delegate; 58 | _socket = [[SRWebSocket alloc] initWithURL:url]; 59 | _socket.delegate = self; 60 | NSLog(@"Opening WebSocket."); 61 | [_socket open]; 62 | } 63 | return self; 64 | } 65 | 66 | - (void)dealloc { 67 | [self disconnect]; 68 | } 69 | 70 | - (void)setState:(ARDWebSocketChannelState)state { 71 | if (_state == state) { 72 | return; 73 | } 74 | _state = state; 75 | [_delegate channel:self didChangeState:_state]; 76 | } 77 | 78 | - (void)registerForRoomId:(NSString *)roomId 79 | clientId:(NSString *)clientId { 80 | NSParameterAssert(roomId.length); 81 | NSParameterAssert(clientId.length); 82 | _roomId = roomId; 83 | _clientId = clientId; 84 | if (_state == kARDWebSocketChannelStateOpen) { 85 | [self registerWithCollider]; 86 | } 87 | } 88 | 89 | - (void)sendData:(NSData *)data { 90 | NSParameterAssert(_clientId.length); 91 | NSParameterAssert(_roomId.length); 92 | if (_state == kARDWebSocketChannelStateRegistered) { 93 | NSString *payload = 94 | [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 95 | NSDictionary *message = @{ 96 | @"cmd": @"send", 97 | @"msg": payload, 98 | }; 99 | NSData *messageJSONObject = 100 | [NSJSONSerialization dataWithJSONObject:message 101 | options:NSJSONWritingPrettyPrinted 102 | error:nil]; 103 | NSString *messageString = 104 | [[NSString alloc] initWithData:messageJSONObject 105 | encoding:NSUTF8StringEncoding]; 106 | NSLog(@"C->WSS: %@", messageString); 107 | [_socket send:messageString]; 108 | } else { 109 | NSString *dataString = 110 | [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 111 | NSLog(@"C->WSS POST: %@", dataString); 112 | NSString *urlString = 113 | [NSString stringWithFormat:@"%@/%@/%@", 114 | [_restURL absoluteString], _roomId, _clientId]; 115 | NSURL *url = [NSURL URLWithString:urlString]; 116 | [NSURLConnection sendAsyncPostToURL:url 117 | withData:data 118 | completionHandler:nil]; 119 | } 120 | } 121 | 122 | - (void)disconnect { 123 | if (_state == kARDWebSocketChannelStateClosed || 124 | _state == kARDWebSocketChannelStateError) { 125 | return; 126 | } 127 | [_socket close]; 128 | NSLog(@"C->WSS DELETE rid:%@ cid:%@", _roomId, _clientId); 129 | NSString *urlString = 130 | [NSString stringWithFormat:@"%@/%@/%@", 131 | [_restURL absoluteString], _roomId, _clientId]; 132 | NSURL *url = [NSURL URLWithString:urlString]; 133 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 134 | request.HTTPMethod = @"DELETE"; 135 | request.HTTPBody = nil; 136 | [NSURLConnection sendAsyncRequest:request completionHandler:nil]; 137 | } 138 | 139 | #pragma mark - SRWebSocketDelegate 140 | 141 | - (void)webSocketDidOpen:(SRWebSocket *)webSocket { 142 | NSLog(@"WebSocket connection opened."); 143 | self.state = kARDWebSocketChannelStateOpen; 144 | if (_roomId.length && _clientId.length) { 145 | [self registerWithCollider]; 146 | } 147 | } 148 | 149 | - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message { 150 | NSString *messageString = message; 151 | NSData *messageData = [messageString dataUsingEncoding:NSUTF8StringEncoding]; 152 | id jsonObject = [NSJSONSerialization JSONObjectWithData:messageData 153 | options:0 154 | error:nil]; 155 | if (![jsonObject isKindOfClass:[NSDictionary class]]) { 156 | NSLog(@"Unexpected message: %@", jsonObject); 157 | return; 158 | } 159 | NSDictionary *wssMessage = jsonObject; 160 | NSString *errorString = wssMessage[kARDWSSMessageErrorKey]; 161 | if (errorString.length) { 162 | NSLog(@"WSS error: %@", errorString); 163 | return; 164 | } 165 | NSString *payload = wssMessage[kARDWSSMessagePayloadKey]; 166 | ARDSignalingMessage *signalingMessage = 167 | [ARDSignalingMessage messageFromJSONString:payload]; 168 | NSLog(@"WSS->C: %@", payload); 169 | [_delegate channel:self didReceiveMessage:signalingMessage]; 170 | } 171 | 172 | - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error { 173 | NSLog(@"WebSocket error: %@", error); 174 | self.state = kARDWebSocketChannelStateError; 175 | } 176 | 177 | - (void)webSocket:(SRWebSocket *)webSocket 178 | didCloseWithCode:(NSInteger)code 179 | reason:(NSString *)reason 180 | wasClean:(BOOL)wasClean { 181 | NSLog(@"WebSocket closed with code: %ld reason:%@ wasClean:%d", 182 | (long)code, reason, wasClean); 183 | NSParameterAssert(_state != kARDWebSocketChannelStateError); 184 | self.state = kARDWebSocketChannelStateClosed; 185 | } 186 | 187 | #pragma mark - Private 188 | 189 | - (void)registerWithCollider { 190 | if (_state == kARDWebSocketChannelStateRegistered) { 191 | return; 192 | } 193 | NSParameterAssert(_roomId.length); 194 | NSParameterAssert(_clientId.length); 195 | NSDictionary *registerMessage = @{ 196 | @"cmd": @"register", 197 | @"roomid" : _roomId, 198 | @"clientid" : _clientId, 199 | }; 200 | NSData *message = 201 | [NSJSONSerialization dataWithJSONObject:registerMessage 202 | options:NSJSONWritingPrettyPrinted 203 | error:nil]; 204 | NSString *messageString = 205 | [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding]; 206 | NSLog(@"Registering on WSS for rid:%@ cid:%@", _roomId, _clientId); 207 | // Registration can fail if server rejects it. For example, if the room is 208 | // full. 209 | [_socket send:messageString]; 210 | self.state = kARDWebSocketChannelStateRegistered; 211 | } 212 | 213 | @end 214 | -------------------------------------------------------------------------------- /AppRTCDemo/AppRTCDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | // 29 | // Prefix header for all source files of the 'AppRTCDemo' target in the 30 | // 'AppRTCDemo' project 31 | // 32 | 33 | #import 34 | 35 | #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0 36 | #warning "This project uses features only available in iOS SDK 6.0 and later." 37 | #endif 38 | 39 | #import 40 | #import 41 | -------------------------------------------------------------------------------- /AppRTCDemo/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroeorz/AppRTCDemo/7458a7ecb63ef3dc42a4e46a259959e57becf117/AppRTCDemo/Default.png -------------------------------------------------------------------------------- /AppRTCDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 12E55 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleDisplayName 10 | AppRTCDemo 11 | CFBundleExecutable 12 | AppRTCDemo 13 | CFBundleIcons 14 | 15 | CFBundlePrimaryIcon 16 | 17 | CFBundleIconFiles 18 | 19 | Icon.png 20 | 21 | 22 | 23 | CFBundleIdentifier 24 | com.google.AppRTCDemo 25 | CFBundleInfoDictionaryVersion 26 | 6.0 27 | CFBundleName 28 | AppRTCDemo 29 | CFBundlePackageType 30 | APPL 31 | CFBundleResourceSpecification 32 | ResourceRules.plist 33 | CFBundleShortVersionString 34 | 1.0 35 | CFBundleSignature 36 | ???? 37 | CFBundleSupportedPlatforms 38 | 39 | iPhoneOS 40 | 41 | CFBundleVersion 42 | 1.0 43 | UIRequiredDeviceCapabilities 44 | 45 | armv7 46 | 47 | UIStatusBarTintParameters 48 | 49 | UINavigationBar 50 | 51 | Style 52 | UIBarStyleDefault 53 | Translucent 54 | 55 | 56 | 57 | UISupportedInterfaceOrientations 58 | 59 | UIInterfaceOrientationPortrait 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /AppRTCDemo/RTCICECandidate+JSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCICECandidate.h" 29 | 30 | @interface RTCICECandidate (JSON) 31 | 32 | + (RTCICECandidate *)candidateFromJSONDictionary:(NSDictionary *)dictionary; 33 | - (NSData *)JSONData; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /AppRTCDemo/RTCICECandidate+JSON.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCICECandidate+JSON.h" 29 | 30 | static NSString const *kRTCICECandidateTypeKey = @"type"; 31 | static NSString const *kRTCICECandidateTypeValue = @"candidate"; 32 | static NSString const *kRTCICECandidateMidKey = @"id"; 33 | static NSString const *kRTCICECandidateMLineIndexKey = @"label"; 34 | static NSString const *kRTCICECandidateSdpKey = @"candidate"; 35 | 36 | @implementation RTCICECandidate (JSON) 37 | 38 | + (RTCICECandidate *)candidateFromJSONDictionary:(NSDictionary *)dictionary { 39 | NSString *mid = dictionary[kRTCICECandidateMidKey]; 40 | NSString *sdp = dictionary[kRTCICECandidateSdpKey]; 41 | NSNumber *num = dictionary[kRTCICECandidateMLineIndexKey]; 42 | NSInteger mLineIndex = [num integerValue]; 43 | return [[RTCICECandidate alloc] initWithMid:mid index:mLineIndex sdp:sdp]; 44 | } 45 | 46 | - (NSData *)JSONData { 47 | NSDictionary *json = @{ 48 | kRTCICECandidateTypeKey : kRTCICECandidateTypeValue, 49 | kRTCICECandidateMLineIndexKey : @(self.sdpMLineIndex), 50 | kRTCICECandidateMidKey : self.sdpMid, 51 | kRTCICECandidateSdpKey : self.sdp 52 | }; 53 | NSError *error = nil; 54 | NSData *data = 55 | [NSJSONSerialization dataWithJSONObject:json 56 | options:NSJSONWritingPrettyPrinted 57 | error:&error]; 58 | if (error) { 59 | NSLog(@"Error serializing JSON: %@", error); 60 | return nil; 61 | } 62 | return data; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /AppRTCDemo/RTCICEServer+JSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCICEServer.h" 29 | 30 | @interface RTCICEServer (JSON) 31 | 32 | + (RTCICEServer *)serverFromJSONDictionary:(NSDictionary *)dictionary; 33 | // CEOD provides different JSON, and this parses that. 34 | + (NSArray *)serversFromCEODJSONDictionary:(NSDictionary *)dictionary; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /AppRTCDemo/RTCICEServer+JSON.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCICEServer+JSON.h" 29 | 30 | static NSString const *kRTCICEServerUsernameKey = @"username"; 31 | static NSString const *kRTCICEServerPasswordKey = @"password"; 32 | static NSString const *kRTCICEServerUrisKey = @"uris"; 33 | static NSString const *kRTCICEServerUrlKey = @"urls"; 34 | static NSString const *kRTCICEServerCredentialKey = @"credential"; 35 | 36 | @implementation RTCICEServer (JSON) 37 | 38 | + (RTCICEServer *)serverFromJSONDictionary:(NSDictionary *)dictionary { 39 | NSString *url = dictionary[kRTCICEServerUrlKey]; 40 | NSString *username = dictionary[kRTCICEServerUsernameKey]; 41 | NSString *credential = dictionary[kRTCICEServerCredentialKey]; 42 | username = username ? username : @""; 43 | credential = credential ? credential : @""; 44 | return [[RTCICEServer alloc] initWithURI:[NSURL URLWithString:url] 45 | username:username 46 | password:credential]; 47 | } 48 | 49 | + (NSArray *)serversFromCEODJSONDictionary:(NSDictionary *)dictionary { 50 | NSString *username = dictionary[kRTCICEServerUsernameKey]; 51 | NSString *password = dictionary[kRTCICEServerPasswordKey]; 52 | NSArray *uris = dictionary[kRTCICEServerUrisKey]; 53 | NSMutableArray *servers = [NSMutableArray arrayWithCapacity:uris.count]; 54 | for (NSString *uri in uris) { 55 | RTCICEServer *server = 56 | [[RTCICEServer alloc] initWithURI:[NSURL URLWithString:uri] 57 | username:username 58 | password:password]; 59 | [servers addObject:server]; 60 | } 61 | return servers; 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /AppRTCDemo/RTCMediaConstraints+JSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCMediaConstraints.h" 29 | 30 | @interface RTCMediaConstraints (JSON) 31 | 32 | + (RTCMediaConstraints *)constraintsFromJSONDictionary: 33 | (NSDictionary *)dictionary; 34 | 35 | @end 36 | 37 | -------------------------------------------------------------------------------- /AppRTCDemo/RTCMediaConstraints+JSON.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCMediaConstraints+JSON.h" 29 | 30 | #import "RTCPair.h" 31 | 32 | static NSString const *kRTCMediaConstraintsMandatoryKey = @"mandatory"; 33 | 34 | @implementation RTCMediaConstraints (JSON) 35 | 36 | + (RTCMediaConstraints *)constraintsFromJSONDictionary: 37 | (NSDictionary *)dictionary { 38 | NSDictionary *mandatory = dictionary[kRTCMediaConstraintsMandatoryKey]; 39 | NSMutableArray *mandatoryContraints = 40 | [NSMutableArray arrayWithCapacity:[mandatory count]]; 41 | [mandatory enumerateKeysAndObjectsUsingBlock:^( 42 | id key, id obj, BOOL *stop) { 43 | [mandatoryContraints addObject:[[RTCPair alloc] initWithKey:key 44 | value:obj]]; 45 | }]; 46 | // TODO(tkchin): figure out json formats for optional constraints. 47 | RTCMediaConstraints *constraints = 48 | [[RTCMediaConstraints alloc] 49 | initWithMandatoryConstraints:mandatoryContraints 50 | optionalConstraints:nil]; 51 | return constraints; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /AppRTCDemo/RTCSessionDescription+JSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCSessionDescription.h" 29 | 30 | @interface RTCSessionDescription (JSON) 31 | 32 | + (RTCSessionDescription *)descriptionFromJSONDictionary: 33 | (NSDictionary *)dictionary; 34 | - (NSData *)JSONData; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /AppRTCDemo/RTCSessionDescription+JSON.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCSessionDescription+JSON.h" 29 | 30 | static NSString const *kRTCSessionDescriptionTypeKey = @"type"; 31 | static NSString const *kRTCSessionDescriptionSdpKey = @"sdp"; 32 | 33 | @implementation RTCSessionDescription (JSON) 34 | 35 | + (RTCSessionDescription *)descriptionFromJSONDictionary: 36 | (NSDictionary *)dictionary { 37 | NSString *type = dictionary[kRTCSessionDescriptionTypeKey]; 38 | NSString *sdp = dictionary[kRTCSessionDescriptionSdpKey]; 39 | return [[RTCSessionDescription alloc] initWithType:type sdp:sdp]; 40 | } 41 | 42 | - (NSData *)JSONData { 43 | NSDictionary *json = @{ 44 | kRTCSessionDescriptionTypeKey : self.type, 45 | kRTCSessionDescriptionSdpKey : self.description 46 | }; 47 | return [NSJSONSerialization dataWithJSONObject:json options:0 error:nil]; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /AppRTCDemo/ResourceRules.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | rules 6 | 7 | .* 8 | 9 | Info.plist 10 | 11 | omit 12 | 13 | weight 14 | 10 15 | 16 | ResourceRules.plist 17 | 18 | omit 19 | 20 | weight 21 | 100 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /AppRTCDemo/en.lproj/APPRTCViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1536 5 | 13B42 6 | 4514 7 | 1265 8 | 696.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 3747 12 | 13 | 14 | IBNSLayoutConstraint 15 | IBProxyObject 16 | IBUITextField 17 | IBUITextView 18 | IBUIView 19 | 20 | 21 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 22 | 23 | 24 | PluginDependencyRecalculationVersion 25 | 26 | 27 | 28 | 29 | IBFilesOwner 30 | IBCocoaTouchFramework 31 | 32 | 33 | IBFirstResponder 34 | IBCocoaTouchFramework 35 | 36 | 37 | 38 | 274 39 | 40 | 41 | 42 | 292 43 | {{20, 20}, {280, 141}} 44 | 45 | 46 | 47 | _NS:9 48 | 49 | 1 50 | MSAxIDEAA 51 | 52 | YES 53 | NO 54 | IBCocoaTouchFramework 55 | Enter the room below to connect to apprtc. 56 | 57 | 2 58 | IBCocoaTouchFramework 59 | 60 | 61 | 1 62 | 14 63 | 64 | 65 | HelveticaNeue 66 | 14 67 | 16 68 | 69 | 70 | 71 | 72 | 292 73 | {{20, 180}, {280, 30}} 74 | 75 | 76 | 77 | _NS:9 78 | NO 79 | YES 80 | IBCocoaTouchFramework 81 | 0 82 | 83 | 3 84 | apprtc room 85 | 86 | 3 87 | MAA 88 | 89 | 2 90 | 91 | 92 | YES 93 | 17 94 | 95 | 2 96 | 3 97 | IBCocoaTouchFramework 98 | 99 | 100 | 101 | 102 | 103 | 104 | -2147483356 105 | {{20, 20}, {280, 190}} 106 | 107 | 108 | 109 | _NS:9 110 | 111 | YES 112 | YES 113 | IBCocoaTouchFramework 114 | NO 115 | 116 | 117 | 2 118 | IBCocoaTouchFramework 119 | 120 | 121 | 122 | 123 | 124 | 125 | -2147483356 126 | {{20, 228}, {280, 300}} 127 | 128 | 129 | 130 | _NS:9 131 | 132 | 3 133 | MAA 134 | 135 | IBCocoaTouchFramework 136 | 137 | 138 | {{0, 20}, {320, 548}} 139 | 140 | 141 | 142 | 143 | 3 144 | MC43NQA 145 | 146 | 147 | NO 148 | 149 | 150 | IBUIScreenMetrics 151 | 152 | YES 153 | 154 | 155 | 156 | 157 | 158 | {320, 568} 159 | {568, 320} 160 | 161 | 162 | IBCocoaTouchFramework 163 | Retina 4-inch Full Screen 164 | 2 165 | 166 | IBCocoaTouchFramework 167 | 168 | 169 | 170 | 171 | 172 | 173 | view 174 | 175 | 176 | 177 | 7 178 | 179 | 180 | 181 | roomInput 182 | 183 | 184 | 185 | 108 186 | 187 | 188 | 189 | instructionsView 190 | 191 | 192 | 193 | 127 194 | 195 | 196 | 197 | logView 198 | 199 | 200 | 201 | 138 202 | 203 | 204 | 205 | blackView 206 | 207 | 208 | 209 | 151 210 | 211 | 212 | 213 | 214 | 215 | 0 216 | 217 | 218 | 219 | 220 | 221 | -1 222 | 223 | 224 | File's Owner 225 | 226 | 227 | -2 228 | 229 | 230 | 231 | 232 | 6 233 | 234 | 235 | 236 | 237 | 4 238 | 0 239 | 240 | 4 241 | 1 242 | 243 | 20 244 | 245 | 1000 246 | 247 | 8 248 | 23 249 | 3 250 | NO 251 | 252 | 253 | 254 | 3 255 | 0 256 | 257 | 3 258 | 1 259 | 260 | 228 261 | 262 | 1000 263 | 264 | 3 265 | 9 266 | 3 267 | NO 268 | 269 | 270 | 271 | 5 272 | 0 273 | 274 | 5 275 | 1 276 | 277 | 0.0 278 | 279 | 1000 280 | 281 | 6 282 | 24 283 | 2 284 | NO 285 | 286 | 287 | 288 | 6 289 | 0 290 | 291 | 6 292 | 1 293 | 294 | 0.0 295 | 296 | 1000 297 | 298 | 6 299 | 24 300 | 2 301 | NO 302 | 303 | 304 | 305 | 6 306 | 0 307 | 308 | 6 309 | 1 310 | 311 | 20 312 | 313 | 1000 314 | 315 | 0 316 | 29 317 | 3 318 | NO 319 | 320 | 321 | 322 | 5 323 | 0 324 | 325 | 5 326 | 1 327 | 328 | 20 329 | 330 | 1000 331 | 332 | 0 333 | 29 334 | 3 335 | NO 336 | 337 | 338 | 339 | 4 340 | 0 341 | 342 | 4 343 | 1 344 | 345 | 0.0 346 | 347 | 1000 348 | 349 | 6 350 | 24 351 | 2 352 | NO 353 | 354 | 355 | 356 | 3 357 | 0 358 | 359 | 3 360 | 1 361 | 362 | 20 363 | 364 | 1000 365 | 366 | 0 367 | 29 368 | 3 369 | NO 370 | 371 | 372 | 373 | 6 374 | 0 375 | 376 | 6 377 | 1 378 | 379 | 20 380 | 381 | 1000 382 | 383 | 0 384 | 29 385 | 3 386 | NO 387 | 388 | 389 | 390 | 5 391 | 0 392 | 393 | 5 394 | 1 395 | 396 | 20 397 | 398 | 1000 399 | 400 | 0 401 | 29 402 | 3 403 | NO 404 | 405 | 406 | 407 | 6 408 | 0 409 | 410 | 6 411 | 1 412 | 413 | 20 414 | 415 | 1000 416 | 417 | 0 418 | 29 419 | 3 420 | NO 421 | 422 | 423 | 424 | 3 425 | 0 426 | 427 | 3 428 | 1 429 | 430 | 20 431 | 432 | 1000 433 | 434 | 0 435 | 29 436 | 3 437 | NO 438 | 439 | 440 | 441 | 5 442 | 0 443 | 444 | 5 445 | 1 446 | 447 | 20 448 | 449 | 1000 450 | 451 | 0 452 | 29 453 | 3 454 | NO 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 57 465 | 466 | 467 | 468 | 469 | 8 470 | 0 471 | 472 | 0 473 | 1 474 | 475 | 141 476 | 477 | 1000 478 | 479 | 3 480 | 9 481 | 1 482 | NO 483 | 484 | 485 | 486 | 487 | 488 | 62 489 | 490 | 491 | 492 | 493 | 63 494 | 495 | 496 | 497 | 498 | 66 499 | 500 | 501 | 502 | 503 | 104 504 | 505 | 506 | 507 | 508 | 509 | 107 510 | 511 | 512 | 513 | 514 | 123 515 | 516 | 517 | 518 | 519 | 126 520 | 521 | 522 | 523 | 524 | 128 525 | 526 | 527 | 528 | 529 | 8 530 | 0 531 | 532 | 0 533 | 1 534 | 535 | 190 536 | 537 | 1000 538 | 539 | 3 540 | 9 541 | 1 542 | NO 543 | 544 | 545 | 546 | 547 | 548 | 133 549 | 550 | 551 | 552 | 553 | 137 554 | 555 | 556 | 557 | 558 | 139 559 | 560 | 561 | 562 | 563 | 141 564 | 565 | 566 | 567 | 568 | 142 569 | 570 | 571 | 572 | 573 | 148 574 | 575 | 576 | 577 | 578 | 149 579 | 580 | 581 | 582 | 583 | 153 584 | 585 | 586 | 587 | 588 | 154 589 | 590 | 591 | 592 | 593 | 155 594 | 595 | 596 | 597 | 598 | 599 | 600 | APPRTCViewController 601 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 602 | UIResponder 603 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 604 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 605 | 606 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 607 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 608 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 609 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 610 | 611 | 612 | 613 | 614 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 615 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 616 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 617 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 618 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 619 | 620 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 621 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 622 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 623 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 624 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 625 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 626 | 627 | 628 | 629 | 630 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 647 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 648 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 649 | 650 | 651 | 652 | 653 | 654 | 155 655 | 656 | 657 | 658 | 659 | APPRTCViewController 660 | UIViewController 661 | 662 | UIView 663 | UITextField 664 | UITextView 665 | UITextView 666 | 667 | 668 | 669 | blackView 670 | UIView 671 | 672 | 673 | roomInput 674 | UITextField 675 | 676 | 677 | instructionsView 678 | UITextView 679 | 680 | 681 | logView 682 | UITextView 683 | 684 | 685 | 686 | IBProjectSource 687 | ./Classes/APPRTCViewController.h 688 | 689 | 690 | 691 | NSLayoutConstraint 692 | NSObject 693 | 694 | IBProjectSource 695 | ./Classes/NSLayoutConstraint.h 696 | 697 | 698 | 699 | 700 | 0 701 | IBCocoaTouchFramework 702 | YES 703 | 704 | com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS 705 | 706 | 707 | 708 | com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 709 | 710 | 711 | YES 712 | 3 713 | YES 714 | 3747 715 | 716 | 717 | -------------------------------------------------------------------------------- /AppRTCDemo/main.m: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #import "APPRTCAppDelegate.h" 31 | 32 | int main(int argc, char* argv[]) { 33 | @autoreleasepool { 34 | return UIApplicationMain( 35 | argc, argv, nil, NSStringFromClass([APPRTCAppDelegate class])); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /AppRTCDemo/third_party/SocketRocket/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright 2012 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | -------------------------------------------------------------------------------- /AppRTCDemo/third_party/SocketRocket/SRWebSocket.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2012 Square Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #import 18 | #import 19 | 20 | typedef enum { 21 | SR_CONNECTING = 0, 22 | SR_OPEN = 1, 23 | SR_CLOSING = 2, 24 | SR_CLOSED = 3, 25 | } SRReadyState; 26 | 27 | typedef enum SRStatusCode : NSInteger { 28 | SRStatusCodeNormal = 1000, 29 | SRStatusCodeGoingAway = 1001, 30 | SRStatusCodeProtocolError = 1002, 31 | SRStatusCodeUnhandledType = 1003, 32 | // 1004 reserved. 33 | SRStatusNoStatusReceived = 1005, 34 | // 1004-1006 reserved. 35 | SRStatusCodeInvalidUTF8 = 1007, 36 | SRStatusCodePolicyViolated = 1008, 37 | SRStatusCodeMessageTooBig = 1009, 38 | } SRStatusCode; 39 | 40 | @class SRWebSocket; 41 | 42 | extern NSString *const SRWebSocketErrorDomain; 43 | extern NSString *const SRHTTPResponseErrorKey; 44 | 45 | #pragma mark - SRWebSocketDelegate 46 | 47 | @protocol SRWebSocketDelegate; 48 | 49 | #pragma mark - SRWebSocket 50 | 51 | @interface SRWebSocket : NSObject 52 | 53 | @property (nonatomic, weak) id delegate; 54 | 55 | @property (nonatomic, readonly) SRReadyState readyState; 56 | @property (nonatomic, readonly, retain) NSURL *url; 57 | 58 | // This returns the negotiated protocol. 59 | // It will be nil until after the handshake completes. 60 | @property (nonatomic, readonly, copy) NSString *protocol; 61 | 62 | // Protocols should be an array of strings that turn into Sec-WebSocket-Protocol. 63 | - (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols; 64 | - (id)initWithURLRequest:(NSURLRequest *)request; 65 | 66 | // Some helper constructors. 67 | - (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols; 68 | - (id)initWithURL:(NSURL *)url; 69 | 70 | // Delegate queue will be dispatch_main_queue by default. 71 | // You cannot set both OperationQueue and dispatch_queue. 72 | - (void)setDelegateOperationQueue:(NSOperationQueue*) queue; 73 | - (void)setDelegateDispatchQueue:(dispatch_queue_t) queue; 74 | 75 | // By default, it will schedule itself on +[NSRunLoop SR_networkRunLoop] using defaultModes. 76 | - (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode; 77 | - (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode; 78 | 79 | // SRWebSockets are intended for one-time-use only. Open should be called once and only once. 80 | - (void)open; 81 | 82 | - (void)close; 83 | - (void)closeWithCode:(NSInteger)code reason:(NSString *)reason; 84 | 85 | // Send a UTF8 String or Data. 86 | - (void)send:(id)data; 87 | 88 | // Send Data (can be nil) in a ping message. 89 | - (void)sendPing:(NSData *)data; 90 | 91 | @end 92 | 93 | #pragma mark - SRWebSocketDelegate 94 | 95 | @protocol SRWebSocketDelegate 96 | 97 | // message will either be an NSString if the server is using text 98 | // or NSData if the server is using binary. 99 | - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message; 100 | 101 | @optional 102 | 103 | - (void)webSocketDidOpen:(SRWebSocket *)webSocket; 104 | - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error; 105 | - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean; 106 | - (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload; 107 | 108 | @end 109 | 110 | #pragma mark - NSURLRequest (CertificateAdditions) 111 | 112 | @interface NSURLRequest (CertificateAdditions) 113 | 114 | @property (nonatomic, retain, readonly) NSArray *SR_SSLPinnedCertificates; 115 | 116 | @end 117 | 118 | #pragma mark - NSMutableURLRequest (CertificateAdditions) 119 | 120 | @interface NSMutableURLRequest (CertificateAdditions) 121 | 122 | @property (nonatomic, retain) NSArray *SR_SSLPinnedCertificates; 123 | 124 | @end 125 | 126 | #pragma mark - NSRunLoop (SRWebSocket) 127 | 128 | @interface NSRunLoop (SRWebSocket) 129 | 130 | + (NSRunLoop *)SR_networkRunLoop; 131 | 132 | @end 133 | -------------------------------------------------------------------------------- /AppRTCDemoTests/AppRTCDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppRTCDemoTests.m 3 | // AppRTCDemoTests 4 | // 5 | // Created by HIROE Shin on 2015/01/04. 6 | // Copyright (c) 2015年 Shin Hiroe. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface AppRTCDemoTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation AppRTCDemoTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /AppRTCDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | Goroneko-Lab.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, The WebRTC project authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the 13 | distribution. 14 | 15 | * Neither the name of Google nor the names of its contributors may 16 | be used to endorse or promote products derived from this software 17 | without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AppRTCDemo sample project for iOS 2 | 3 | ## About 4 | 5 | This is unofficial XCode Project of AppRTCDemo (for ios). 6 | AppRTCDemo is WebRTC demo application. 7 | 8 | Please see [How to get started with WebRTC and iOS without wasting 10 hours of your life](http://ninjanetic.com/how-to-get-started-with-webrtc-and-ios-without-wasting-10-hours-of-your-life/) for more details. 9 | 10 | ## Usage 11 | 12 | 1. Build this project on Xcode, and run on ios device. 13 | 2. Open [https://apprtc.appspot.com/](https://apprtc.appspot.com/) in Browser (Chrome or Firefox). 14 | 3. Check room number at end of URL. 15 | 4. Input room number in app's text filed, that has placeholder "apprtc room". 16 | 5. Join to room. 17 | 18 | ## Build and Run Environment 19 | 20 | * Xcode Version 6.1.1 21 | * MacOSX 10.10.1 22 | * iPhone 5s (arm64) 23 | * iOS 8.1.2 -------------------------------------------------------------------------------- /include/RTCAudioSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCMediaSource.h" 29 | 30 | // RTCAudioSource is an ObjectiveC wrapper for AudioSourceInterface. It is 31 | // used as the source for one or more RTCAudioTrack objects. 32 | @interface RTCAudioSource : RTCMediaSource 33 | 34 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 35 | // Disallow init and don't add to documentation 36 | - (id)init __attribute__( 37 | (unavailable("init is not a supported initializer for this class."))); 38 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /include/RTCAudioTrack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCMediaStreamTrack.h" 29 | 30 | // RTCAudioTrack is an ObjectiveC wrapper for AudioTrackInterface. 31 | @interface RTCAudioTrack : RTCMediaStreamTrack 32 | 33 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 34 | // Disallow init and don't add to documentation 35 | - (id)init __attribute__( 36 | (unavailable("init is not a supported initializer for this class."))); 37 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /include/RTCDataChannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // ObjectiveC wrapper for a DataChannelInit object. 31 | @interface RTCDataChannelInit : NSObject 32 | 33 | // Set to YES if ordered delivery is required 34 | @property(nonatomic) BOOL isOrdered; 35 | // Max period in milliseconds in which retransmissions will be sent. After this 36 | // time, no more retransmissions will be sent. -1 if unset. 37 | @property(nonatomic) NSInteger maxRetransmitTimeMs; 38 | // The max number of retransmissions. -1 if unset. 39 | @property(nonatomic) NSInteger maxRetransmits; 40 | // Set to YES if the channel has been externally negotiated and we do not send 41 | // an in-band signalling in the form of an "open" message 42 | @property(nonatomic) BOOL isNegotiated; 43 | // The stream id, or SID, for SCTP data channels. -1 if unset. 44 | @property(nonatomic) NSInteger streamId; 45 | // Set by the application and opaque to the WebRTC implementation. 46 | @property(nonatomic) NSString* protocol; 47 | 48 | @end 49 | 50 | // ObjectiveC wrapper for a DataBuffer object. 51 | @interface RTCDataBuffer : NSObject 52 | 53 | @property(nonatomic, readonly) NSData* data; 54 | @property(nonatomic, readonly) BOOL isBinary; 55 | 56 | - (instancetype)initWithData:(NSData*)data isBinary:(BOOL)isBinary; 57 | 58 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 59 | // Disallow init and don't add to documentation 60 | - (id)init __attribute__(( 61 | unavailable("init is not a supported initializer for this class."))); 62 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 63 | 64 | @end 65 | 66 | // Keep in sync with webrtc::DataChannelInterface::DataState 67 | typedef enum { 68 | kRTCDataChannelStateConnecting, 69 | kRTCDataChannelStateOpen, 70 | kRTCDataChannelStateClosing, 71 | kRTCDataChannelStateClosed 72 | } RTCDataChannelState; 73 | 74 | @class RTCDataChannel; 75 | // Protocol for receving data channel state and message events. 76 | @protocol RTCDataChannelDelegate 77 | 78 | // Called when the data channel state has changed. 79 | - (void)channelDidChangeState:(RTCDataChannel*)channel; 80 | 81 | // Called when a data buffer was successfully received. 82 | - (void)channel:(RTCDataChannel*)channel 83 | didReceiveMessageWithBuffer:(RTCDataBuffer*)buffer; 84 | 85 | @end 86 | 87 | // ObjectiveC wrapper for a DataChannel object. 88 | // See talk/app/webrtc/datachannelinterface.h 89 | @interface RTCDataChannel : NSObject 90 | 91 | @property(nonatomic, readonly) NSString* label; 92 | @property(nonatomic, readonly) BOOL isReliable; 93 | @property(nonatomic, readonly) BOOL isOrdered; 94 | @property(nonatomic, readonly) NSUInteger maxRetransmitTime; 95 | @property(nonatomic, readonly) NSUInteger maxRetransmits; 96 | @property(nonatomic, readonly) NSString* protocol; 97 | @property(nonatomic, readonly) BOOL isNegotiated; 98 | @property(nonatomic, readonly) NSInteger streamId; 99 | @property(nonatomic, readonly) RTCDataChannelState state; 100 | @property(nonatomic, readonly) NSUInteger bufferedAmount; 101 | @property(nonatomic, weak) id delegate; 102 | 103 | - (void)close; 104 | - (BOOL)sendData:(RTCDataBuffer*)data; 105 | 106 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 107 | // Disallow init and don't add to documentation 108 | - (id)init __attribute__(( 109 | unavailable("init is not a supported initializer for this class."))); 110 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /include/RTCEAGLVideoView.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | #import 30 | 31 | #import "RTCVideoRenderer.h" 32 | 33 | @class RTCEAGLVideoView; 34 | @protocol RTCEAGLVideoViewDelegate 35 | 36 | - (void)videoView:(RTCEAGLVideoView*)videoView didChangeVideoSize:(CGSize)size; 37 | 38 | @end 39 | 40 | // RTCEAGLVideoView is an RTCVideoRenderer which renders i420 frames in its 41 | // bounds using OpenGLES 2.0. 42 | @interface RTCEAGLVideoView : UIView 43 | 44 | @property(nonatomic, weak) id delegate; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /include/RTCI420Frame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // RTCI420Frame is an ObjectiveC version of cricket::VideoFrame. 31 | @interface RTCI420Frame : NSObject 32 | 33 | @property(nonatomic, readonly) NSUInteger width; 34 | @property(nonatomic, readonly) NSUInteger height; 35 | @property(nonatomic, readonly) NSUInteger chromaWidth; 36 | @property(nonatomic, readonly) NSUInteger chromaHeight; 37 | @property(nonatomic, readonly) NSUInteger chromaSize; 38 | // These can return NULL if the object is not backed by a buffer. 39 | @property(nonatomic, readonly) const uint8_t* yPlane; 40 | @property(nonatomic, readonly) const uint8_t* uPlane; 41 | @property(nonatomic, readonly) const uint8_t* vPlane; 42 | @property(nonatomic, readonly) NSInteger yPitch; 43 | @property(nonatomic, readonly) NSInteger uPitch; 44 | @property(nonatomic, readonly) NSInteger vPitch; 45 | 46 | - (BOOL)makeExclusive; 47 | 48 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 49 | // Disallow init and don't add to documentation 50 | - (id)init __attribute__(( 51 | unavailable("init is not a supported initializer for this class."))); 52 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 53 | 54 | @end 55 | 56 | -------------------------------------------------------------------------------- /include/RTCICECandidate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // RTCICECandidate contains an instance of ICECandidateInterface. 31 | @interface RTCICECandidate : NSObject 32 | 33 | // If present, this contains the identifier of the "media stream 34 | // identification" as defined in [RFC 3388] for m-line this candidate is 35 | // associated with. 36 | @property(nonatomic, copy, readonly) NSString* sdpMid; 37 | 38 | // This indicates the index (starting at zero) of m-line in the SDP this 39 | // candidate is associated with. 40 | @property(nonatomic, assign, readonly) NSInteger sdpMLineIndex; 41 | 42 | // Creates an SDP-ized form of this candidate. 43 | @property(nonatomic, copy, readonly) NSString* sdp; 44 | 45 | // Creates an ICECandidateInterface based on SDP string. 46 | - (id)initWithMid:(NSString*)sdpMid 47 | index:(NSInteger)sdpMLineIndex 48 | sdp:(NSString*)sdp; 49 | 50 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 51 | // Disallow init and don't add to documentation 52 | - (id)init __attribute__(( 53 | unavailable("init is not a supported initializer for this class."))); 54 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /include/RTCICEServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // RTCICEServer allows for the creation of ICEServer structs. 31 | @interface RTCICEServer : NSObject 32 | 33 | // The server URI, username, and password. 34 | @property(nonatomic, strong, readonly) NSURL* URI; 35 | @property(nonatomic, copy, readonly) NSString* username; 36 | @property(nonatomic, copy, readonly) NSString* password; 37 | 38 | // Initializer for RTCICEServer taking uri, username, and password. 39 | - (id)initWithURI:(NSURL*)URI 40 | username:(NSString*)username 41 | password:(NSString*)password; 42 | 43 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 44 | // Disallow init and don't add to documentation 45 | - (id)init __attribute__(( 46 | unavailable("init is not a supported initializer for this class."))); 47 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /include/RTCMediaConstraints.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // RTCMediaConstraints contains the media constraints to be used in 31 | // RTCPeerConnection and RTCMediaStream. 32 | @interface RTCMediaConstraints : NSObject 33 | 34 | // Initializer for RTCMediaConstraints. The parameters mandatory and optional 35 | // contain RTCPair objects with key/value for each constrant. 36 | - (id)initWithMandatoryConstraints:(NSArray *)mandatory 37 | optionalConstraints:(NSArray *)optional; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /include/RTCMediaSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #import "RTCTypes.h" 31 | 32 | // RTCMediaSource is an ObjectiveC wrapper for MediaSourceInterface 33 | @interface RTCMediaSource : NSObject 34 | 35 | // The current state of the RTCMediaSource. 36 | @property(nonatomic, assign, readonly) RTCSourceState state; 37 | 38 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 39 | // Disallow init and don't add to documentation 40 | - (id)init __attribute__(( 41 | unavailable("init is not a supported initializer for this class."))); 42 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /include/RTCMediaStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | @class RTCAudioTrack; 31 | @class RTCVideoTrack; 32 | 33 | // RTCMediaStream is an ObjectiveC wrapper for MediaStreamInterface. 34 | @interface RTCMediaStream : NSObject 35 | 36 | @property(nonatomic, strong, readonly) NSArray *audioTracks; 37 | @property(nonatomic, strong, readonly) NSArray *videoTracks; 38 | @property(nonatomic, strong, readonly) NSString *label; 39 | 40 | - (BOOL)addAudioTrack:(RTCAudioTrack *)track; 41 | - (BOOL)addVideoTrack:(RTCVideoTrack *)track; 42 | - (BOOL)removeAudioTrack:(RTCAudioTrack *)track; 43 | - (BOOL)removeVideoTrack:(RTCVideoTrack *)track; 44 | 45 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 46 | // Disallow init and don't add to documentation 47 | - (id)init __attribute__( 48 | (unavailable("init is not a supported initializer for this class."))); 49 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /include/RTCMediaStreamTrack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #import "RTCTypes.h" 31 | 32 | @class RTCMediaStreamTrack; 33 | @protocol RTCMediaStreamTrackDelegate 34 | 35 | - (void)mediaStreamTrackDidChange:(RTCMediaStreamTrack*)mediaStreamTrack; 36 | 37 | @end 38 | 39 | // RTCMediaStreamTrack implements the interface common to RTCAudioTrack and 40 | // RTCVideoTrack. Do not create an instance of this class, rather create one 41 | // of the derived classes. 42 | @interface RTCMediaStreamTrack : NSObject 43 | 44 | @property(nonatomic, readonly) NSString* kind; 45 | @property(nonatomic, readonly) NSString* label; 46 | @property(nonatomic, weak) id delegate; 47 | 48 | - (BOOL)isEnabled; 49 | - (BOOL)setEnabled:(BOOL)enabled; 50 | - (RTCTrackState)state; 51 | - (BOOL)setState:(RTCTrackState)state; 52 | 53 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 54 | // Disallow init and don't add to documentation 55 | - (id)init __attribute__( 56 | (unavailable("init is not a supported initializer for this class."))); 57 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /include/RTCNSGLVideoView.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if TARGET_OS_IPHONE 29 | #error "This file targets OSX." 30 | #endif 31 | 32 | #import 33 | 34 | #import "RTCVideoRenderer.h" 35 | 36 | @class RTCNSGLVideoView; 37 | @protocol RTCNSGLVideoViewDelegate 38 | 39 | - (void)videoView:(RTCNSGLVideoView*)videoView didChangeVideoSize:(CGSize)size; 40 | 41 | @end 42 | 43 | @interface RTCNSGLVideoView : NSOpenGLView 44 | 45 | @property(nonatomic, weak) id delegate; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /include/RTCOpenGLVideoRenderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | #if TARGET_OS_IPHONE 30 | #import 31 | #else 32 | #import 33 | #endif 34 | 35 | @class RTCI420Frame; 36 | 37 | // RTCOpenGLVideoRenderer issues appropriate OpenGL commands to draw a frame to 38 | // the currently bound framebuffer. Supports OpenGL 3.2 and OpenGLES 2.0. OpenGL 39 | // framebuffer creation and management should be handled elsewhere using the 40 | // same context used to initialize this class. 41 | @interface RTCOpenGLVideoRenderer : NSObject 42 | 43 | // The last successfully drawn frame. Used to avoid drawing frames unnecessarily 44 | // hence saving battery life by reducing load. 45 | @property(nonatomic, readonly) RTCI420Frame* lastDrawnFrame; 46 | 47 | #if TARGET_OS_IPHONE 48 | - (instancetype)initWithContext:(EAGLContext*)context; 49 | #else 50 | - (instancetype)initWithContext:(NSOpenGLContext*)context; 51 | #endif 52 | 53 | // Draws |frame| onto the currently bound OpenGL framebuffer. |setupGL| must be 54 | // called before this function will succeed. 55 | - (BOOL)drawFrame:(RTCI420Frame*)frame; 56 | 57 | // The following methods are used to manage OpenGL resources. On iOS 58 | // applications should release resources when placed in background for use in 59 | // the foreground application. In fact, attempting to call OpenGLES commands 60 | // while in background will result in application termination. 61 | 62 | // Sets up the OpenGL state needed for rendering. 63 | - (void)setupGL; 64 | // Tears down the OpenGL state created by |setupGL|. 65 | - (void)teardownGL; 66 | 67 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 68 | // Disallow init and don't add to documentation 69 | - (id)init __attribute__(( 70 | unavailable("init is not a supported initializer for this class."))); 71 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /include/RTCPair.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // A class to hold a key and value. 31 | @interface RTCPair : NSObject 32 | 33 | @property(nonatomic, strong, readonly) NSString *key; 34 | @property(nonatomic, strong, readonly) NSString *value; 35 | 36 | // Initialize a RTCPair object with a key and value. 37 | - (id)initWithKey:(NSString *)key value:(NSString *)value; 38 | 39 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 40 | // Disallow init and don't add to documentation 41 | - (id)init __attribute__( 42 | (unavailable("init is not a supported initializer for this class."))); 43 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /include/RTCPeerConnection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCPeerConnectionDelegate.h" 29 | 30 | @class RTCDataChannel; 31 | @class RTCDataChannelInit; 32 | @class RTCICECandidate; 33 | @class RTCICEServers; 34 | @class RTCMediaConstraints; 35 | @class RTCMediaStream; 36 | @class RTCMediaStreamTrack; 37 | @class RTCSessionDescription; 38 | @protocol RTCSessionDescriptionDelegate; 39 | @protocol RTCStatsDelegate; 40 | 41 | // RTCPeerConnection is an ObjectiveC friendly wrapper around a PeerConnection 42 | // object. See the documentation in talk/app/webrtc/peerconnectioninterface.h. 43 | // or http://www.webrtc.org/reference/native-apis, which in turn is inspired by 44 | // the JS APIs: http://dev.w3.org/2011/webrtc/editor/webrtc.html and 45 | // http://www.w3.org/TR/mediacapture-streams/ 46 | @interface RTCPeerConnection : NSObject 47 | 48 | @property(nonatomic, weak) id delegate; 49 | 50 | // Accessor methods to active local streams. 51 | @property(nonatomic, strong, readonly) NSArray *localStreams; 52 | 53 | // The local description. 54 | @property(nonatomic, assign, readonly) RTCSessionDescription *localDescription; 55 | 56 | // The remote description. 57 | @property(nonatomic, assign, readonly) RTCSessionDescription *remoteDescription; 58 | 59 | // The current signaling state. 60 | @property(nonatomic, assign, readonly) RTCSignalingState signalingState; 61 | @property(nonatomic, assign, readonly) RTCICEConnectionState iceConnectionState; 62 | @property(nonatomic, assign, readonly) RTCICEGatheringState iceGatheringState; 63 | 64 | // Add a new MediaStream to be sent on this PeerConnection. 65 | // Note that a SessionDescription negotiation is needed before the 66 | // remote peer can receive the stream. 67 | - (BOOL)addStream:(RTCMediaStream *)stream; 68 | 69 | // Remove a MediaStream from this PeerConnection. 70 | // Note that a SessionDescription negotiation is need before the 71 | // remote peer is notified. 72 | - (void)removeStream:(RTCMediaStream *)stream; 73 | 74 | // Create a data channel. 75 | - (RTCDataChannel*)createDataChannelWithLabel:(NSString*)label 76 | config:(RTCDataChannelInit*)config; 77 | 78 | // Create a new offer. 79 | // Success or failure will be reported via RTCSessionDescriptionDelegate. 80 | - (void)createOfferWithDelegate:(id)delegate 81 | constraints:(RTCMediaConstraints *)constraints; 82 | 83 | // Create an answer to an offer. 84 | // Success or failure will be reported via RTCSessionDescriptionDelegate. 85 | - (void)createAnswerWithDelegate:(id)delegate 86 | constraints:(RTCMediaConstraints *)constraints; 87 | 88 | // Sets the local session description. 89 | // Success or failure will be reported via RTCSessionDescriptionDelegate. 90 | - (void) 91 | setLocalDescriptionWithDelegate:(id)delegate 92 | sessionDescription:(RTCSessionDescription *)sdp; 93 | 94 | // Sets the remote session description. 95 | // Success or failure will be reported via RTCSessionDescriptionDelegate. 96 | - (void) 97 | setRemoteDescriptionWithDelegate:(id)delegate 98 | sessionDescription:(RTCSessionDescription *)sdp; 99 | 100 | // Restarts or updates the ICE Agent process of gathering local candidates 101 | // and pinging remote candidates. 102 | - (BOOL)updateICEServers:(NSArray *)servers 103 | constraints:(RTCMediaConstraints *)constraints; 104 | 105 | // Provides a remote candidate to the ICE Agent. 106 | - (BOOL)addICECandidate:(RTCICECandidate *)candidate; 107 | 108 | // Terminates all media and closes the transport. 109 | - (void)close; 110 | 111 | // Gets statistics for the media track. If |mediaStreamTrack| is nil statistics 112 | // are gathered for all tracks. 113 | // Statistics information will be reported via RTCStatsDelegate. 114 | - (BOOL)getStatsWithDelegate:(id)delegate 115 | mediaStreamTrack:(RTCMediaStreamTrack*)mediaStreamTrack 116 | statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel; 117 | 118 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 119 | // Disallow init and don't add to documentation 120 | - (id)init __attribute__( 121 | (unavailable("init is not a supported initializer for this class."))); 122 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 123 | 124 | @end 125 | -------------------------------------------------------------------------------- /include/RTCPeerConnectionDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #import "RTCTypes.h" 31 | 32 | @class RTCDataChannel; 33 | @class RTCICECandidate; 34 | @class RTCMediaStream; 35 | @class RTCPeerConnection; 36 | 37 | // RTCPeerConnectionDelegate is a protocol for an object that must be 38 | // implemented to get messages from PeerConnection. 39 | @protocol RTCPeerConnectionDelegate 40 | 41 | // Triggered when the SignalingState changed. 42 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 43 | signalingStateChanged:(RTCSignalingState)stateChanged; 44 | 45 | // Triggered when media is received on a new stream from remote peer. 46 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 47 | addedStream:(RTCMediaStream *)stream; 48 | 49 | // Triggered when a remote peer close a stream. 50 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 51 | removedStream:(RTCMediaStream *)stream; 52 | 53 | // Triggered when renegotiation is needed, for example the ICE has restarted. 54 | - (void)peerConnectionOnRenegotiationNeeded:(RTCPeerConnection *)peerConnection; 55 | 56 | // Called any time the ICEConnectionState changes. 57 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 58 | iceConnectionChanged:(RTCICEConnectionState)newState; 59 | 60 | // Called any time the ICEGatheringState changes. 61 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 62 | iceGatheringChanged:(RTCICEGatheringState)newState; 63 | 64 | // New Ice candidate have been found. 65 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 66 | gotICECandidate:(RTCICECandidate *)candidate; 67 | 68 | // New data channel has been opened. 69 | - (void)peerConnection:(RTCPeerConnection*)peerConnection 70 | didOpenDataChannel:(RTCDataChannel*)dataChannel; 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /include/RTCPeerConnectionFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | @class RTCAudioTrack; 31 | @class RTCMediaConstraints; 32 | @class RTCMediaStream; 33 | @class RTCPeerConnection; 34 | @class RTCVideoCapturer; 35 | @class RTCVideoSource; 36 | @class RTCVideoTrack; 37 | @protocol RTCPeerConnectionDelegate; 38 | 39 | // RTCPeerConnectionFactory is an ObjectiveC wrapper for PeerConnectionFactory. 40 | // It is the main entry point to the PeerConnection API for clients. 41 | @interface RTCPeerConnectionFactory : NSObject 42 | 43 | // Initialize & de-initialize the SSL subsystem. Failure is fatal. 44 | + (void)initializeSSL; 45 | + (void)deinitializeSSL; 46 | 47 | // Create an RTCPeerConnection object. RTCPeerConnectionFactory will create 48 | // required libjingle threads, socket and network manager factory classes for 49 | // networking. 50 | - (RTCPeerConnection *) 51 | peerConnectionWithICEServers:(NSArray *)servers 52 | constraints:(RTCMediaConstraints *)constraints 53 | delegate:(id)delegate; 54 | 55 | // Create an RTCMediaStream named |label|. 56 | - (RTCMediaStream *)mediaStreamWithLabel:(NSString *)label; 57 | 58 | // Creates a RTCVideoSource. The new source takes ownership of |capturer|. 59 | // |constraints| decides video resolution and frame rate but can be NULL. 60 | - (RTCVideoSource *)videoSourceWithCapturer:(RTCVideoCapturer *)capturer 61 | constraints:(RTCMediaConstraints *)constraints; 62 | 63 | // Creates a new local VideoTrack. The same |source| can be used in several 64 | // tracks. 65 | - (RTCVideoTrack *)videoTrackWithID:(NSString *)videoId 66 | source:(RTCVideoSource *)source; 67 | 68 | // Creates an new AudioTrack. 69 | - (RTCAudioTrack *)audioTrackWithID:(NSString *)audioId; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /include/RTCSessionDescription.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // Description of an RFC 4566 Session. 31 | // RTCSessionDescription is an ObjectiveC wrapper for 32 | // SessionDescriptionInterface. 33 | @interface RTCSessionDescription : NSObject 34 | 35 | // The SDP description. 36 | @property(nonatomic, copy, readonly) NSString *description; 37 | 38 | // The session type. 39 | @property(nonatomic, copy, readonly) NSString *type; 40 | 41 | - (id)initWithType:(NSString *)type sdp:(NSString *)sdp; 42 | 43 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 44 | // Disallow init and don't add to documentation 45 | - (id)init __attribute__( 46 | (unavailable("init is not a supported initializer for this class."))); 47 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 48 | 49 | @end 50 | 51 | -------------------------------------------------------------------------------- /include/RTCSessionDescriptionDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | @class RTCPeerConnection; 31 | @class RTCSessionDescription; 32 | 33 | extern NSString* const kRTCSessionDescriptionDelegateErrorDomain; 34 | extern int const kRTCSessionDescriptionDelegateErrorCode; 35 | 36 | // RTCSessionDescriptionDelegate is a protocol for listening to callback 37 | // messages when RTCSessionDescriptions are created or set. 38 | @protocol RTCSessionDescriptionDelegate 39 | 40 | // Called when creating a session. 41 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 42 | didCreateSessionDescription:(RTCSessionDescription *)sdp 43 | error:(NSError *)error; 44 | 45 | // Called when setting a local or remote description. 46 | - (void)peerConnection:(RTCPeerConnection *)peerConnection 47 | didSetSessionDescriptionWithError:(NSError *)error; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /include/RTCStatsDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | @class RTCPeerConnection; 31 | 32 | // RTCSessionDescriptionDelegate is a protocol for receiving statistic 33 | // reports from RTCPeerConnection. 34 | @protocol RTCStatsDelegate 35 | 36 | - (void)peerConnection:(RTCPeerConnection*)peerConnection 37 | didGetStats:(NSArray*)stats; // NSArray of RTCStatsReport*. 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /include/RTCStatsReport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2014, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // ObjectiveC friendly wrapper around a StatsReport object. 31 | // See talk/app/webrtc/statsypes.h 32 | @interface RTCStatsReport : NSObject 33 | 34 | @property(nonatomic, readonly) NSString* reportId; 35 | @property(nonatomic, readonly) NSString* type; 36 | @property(nonatomic, readonly) CFTimeInterval timestamp; 37 | @property(nonatomic, readonly) NSArray* values; // NSArray of RTCPair*. 38 | 39 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 40 | // Disallow init and don't add to documentation 41 | - (id)init __attribute__(( 42 | unavailable("init is not a supported initializer for this class."))); 43 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /include/RTCTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | // Enums that are common to the ObjectiveC version of the PeerConnection API. 29 | 30 | // RTCICEConnectionState correspond to the states in webrtc::ICEConnectionState. 31 | typedef enum { 32 | RTCICEConnectionNew, 33 | RTCICEConnectionChecking, 34 | RTCICEConnectionConnected, 35 | RTCICEConnectionCompleted, 36 | RTCICEConnectionFailed, 37 | RTCICEConnectionDisconnected, 38 | RTCICEConnectionClosed, 39 | } RTCICEConnectionState; 40 | 41 | // RTCICEGatheringState the states in webrtc::ICEGatheringState. 42 | typedef enum { 43 | RTCICEGatheringNew, 44 | RTCICEGatheringGathering, 45 | RTCICEGatheringComplete, 46 | } RTCICEGatheringState; 47 | 48 | // RTCSignalingState correspond to the states in webrtc::SignalingState. 49 | typedef enum { 50 | RTCSignalingStable, 51 | RTCSignalingHaveLocalOffer, 52 | RTCSignalingHaveLocalPrAnswer, 53 | RTCSignalingHaveRemoteOffer, 54 | RTCSignalingHaveRemotePrAnswer, 55 | RTCSignalingClosed, 56 | } RTCSignalingState; 57 | 58 | // RTCStatsOutputLevel correspond to webrtc::StatsOutputLevel 59 | typedef enum { 60 | RTCStatsOutputLevelStandard, 61 | RTCStatsOutputLevelDebug, 62 | } RTCStatsOutputLevel; 63 | 64 | // RTCSourceState corresponds to the states in webrtc::SourceState. 65 | typedef enum { 66 | RTCSourceStateInitializing, 67 | RTCSourceStateLive, 68 | RTCSourceStateEnded, 69 | RTCSourceStateMuted, 70 | } RTCSourceState; 71 | 72 | // RTCTrackState corresponds to the states in webrtc::TrackState. 73 | typedef enum { 74 | RTCTrackStateInitializing, 75 | RTCTrackStateLive, 76 | RTCTrackStateEnded, 77 | RTCTrackStateFailed, 78 | } RTCTrackState; 79 | -------------------------------------------------------------------------------- /include/RTCVideoCapturer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | // RTCVideoCapturer is an ObjectiveC wrapper for VideoCapturerInterface. 31 | @interface RTCVideoCapturer : NSObject 32 | 33 | // Create a new video capturer using the specified device. 34 | + (RTCVideoCapturer *)capturerWithDeviceName:(NSString *)deviceName; 35 | 36 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 37 | // Disallow init and don't add to documentation 38 | - (id)init __attribute__( 39 | (unavailable("init is not a supported initializer for this class."))); 40 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /include/RTCVideoRenderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | #if TARGET_OS_IPHONE 30 | #import 31 | #endif 32 | 33 | @class RTCI420Frame; 34 | 35 | @protocol RTCVideoRenderer 36 | 37 | // The size of the frame. 38 | - (void)setSize:(CGSize)size; 39 | 40 | // The frame to be displayed. 41 | - (void)renderFrame:(RTCI420Frame*)frame; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /include/RTCVideoSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCMediaSource.h" 29 | 30 | // RTCVideoSource is an ObjectiveC wrapper for VideoSourceInterface. 31 | @interface RTCVideoSource : RTCMediaSource 32 | 33 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 34 | // Disallow init and don't add to documentation 35 | - (id)init __attribute__( 36 | (unavailable("init is not a supported initializer for this class."))); 37 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /include/RTCVideoTrack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libjingle 3 | * Copyright 2013, Google Inc. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "RTCMediaStreamTrack.h" 29 | 30 | @protocol RTCVideoRenderer; 31 | 32 | // RTCVideoTrack is an ObjectiveC wrapper for VideoTrackInterface. 33 | @interface RTCVideoTrack : RTCMediaStreamTrack 34 | 35 | // Register a renderer that will render all frames received on this track. 36 | - (void)addRenderer:(id)renderer; 37 | 38 | // Deregister a renderer. 39 | - (void)removeRenderer:(id)renderer; 40 | 41 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 42 | // Disallow init and don't add to documentation 43 | - (id)init __attribute__( 44 | (unavailable("init is not a supported initializer for this class."))); 45 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /libWebRTC.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroeorz/AppRTCDemo/7458a7ecb63ef3dc42a4e46a259959e57becf117/libWebRTC.a -------------------------------------------------------------------------------- /libWebRTC.a.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroeorz/AppRTCDemo/7458a7ecb63ef3dc42a4e46a259959e57becf117/libWebRTC.a.tar.bz2 --------------------------------------------------------------------------------