| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #import "ARDAppClient+Internal.h" | 28 #import "ARDAppClient+Internal.h" |
| 29 | 29 |
| 30 #if defined(WEBRTC_IOS) | 30 #if defined(WEBRTC_IOS) |
| 31 #import "RTCAVFoundationVideoSource.h" | 31 #import "RTCAVFoundationVideoSource.h" |
| 32 #endif | 32 #endif |
| 33 #import "RTCFileLogger.h" | 33 #import "RTCFileLogger.h" |
| 34 #import "RTCICEServer.h" | 34 #import "RTCICEServer.h" |
| 35 #import "RTCLogging.h" |
| 35 #import "RTCMediaConstraints.h" | 36 #import "RTCMediaConstraints.h" |
| 36 #import "RTCMediaStream.h" | 37 #import "RTCMediaStream.h" |
| 37 #import "RTCPair.h" | 38 #import "RTCPair.h" |
| 38 #import "RTCPeerConnectionInterface.h" | 39 #import "RTCPeerConnectionInterface.h" |
| 39 #import "RTCVideoCapturer.h" | 40 #import "RTCVideoCapturer.h" |
| 40 #import "RTCAVFoundationVideoSource.h" | |
| 41 | 41 |
| 42 #import "ARDAppEngineClient.h" | 42 #import "ARDAppEngineClient.h" |
| 43 #import "ARDCEODTURNClient.h" | 43 #import "ARDCEODTURNClient.h" |
| 44 #import "ARDJoinResponse.h" | 44 #import "ARDJoinResponse.h" |
| 45 #import "ARDLogging.h" | |
| 46 #import "ARDMessageResponse.h" | 45 #import "ARDMessageResponse.h" |
| 47 #import "ARDSDPUtils.h" | 46 #import "ARDSDPUtils.h" |
| 48 #import "ARDSignalingMessage.h" | 47 #import "ARDSignalingMessage.h" |
| 49 #import "ARDUtilities.h" | 48 #import "ARDUtilities.h" |
| 50 #import "ARDWebSocketChannel.h" | 49 #import "ARDWebSocketChannel.h" |
| 51 #import "RTCICECandidate+JSON.h" | 50 #import "RTCICECandidate+JSON.h" |
| 52 #import "RTCSessionDescription+JSON.h" | 51 #import "RTCSessionDescription+JSON.h" |
| 53 | 52 |
| 54 | 53 |
| 55 static NSString * const kARDDefaultSTUNServerUrl = | 54 static NSString * const kARDDefaultSTUNServerUrl = |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 options:(NSDictionary *)options { | 154 options:(NSDictionary *)options { |
| 156 NSParameterAssert(roomId.length); | 155 NSParameterAssert(roomId.length); |
| 157 NSParameterAssert(_state == kARDAppClientStateDisconnected); | 156 NSParameterAssert(_state == kARDAppClientStateDisconnected); |
| 158 self.state = kARDAppClientStateConnecting; | 157 self.state = kARDAppClientStateConnecting; |
| 159 | 158 |
| 160 // Request TURN. | 159 // Request TURN. |
| 161 __weak ARDAppClient *weakSelf = self; | 160 __weak ARDAppClient *weakSelf = self; |
| 162 [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, | 161 [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, |
| 163 NSError *error) { | 162 NSError *error) { |
| 164 if (error) { | 163 if (error) { |
| 165 ARDLog("Error retrieving TURN servers: %@", error.localizedDescription); | 164 RTCLogError("Error retrieving TURN servers: %@", |
| 165 error.localizedDescription); |
| 166 } | 166 } |
| 167 ARDAppClient *strongSelf = weakSelf; | 167 ARDAppClient *strongSelf = weakSelf; |
| 168 [strongSelf.iceServers addObjectsFromArray:turnServers]; | 168 [strongSelf.iceServers addObjectsFromArray:turnServers]; |
| 169 strongSelf.isTurnComplete = YES; | 169 strongSelf.isTurnComplete = YES; |
| 170 [strongSelf startSignalingIfReady]; | 170 [strongSelf startSignalingIfReady]; |
| 171 }]; | 171 }]; |
| 172 | 172 |
| 173 // Join room on room server. | 173 // Join room on room server. |
| 174 [_roomServerClient joinRoomWithRoomId:roomId | 174 [_roomServerClient joinRoomWithRoomId:roomId |
| 175 completionHandler:^(ARDJoinResponse *response, NSError *error) { | 175 completionHandler:^(ARDJoinResponse *response, NSError *error) { |
| 176 ARDAppClient *strongSelf = weakSelf; | 176 ARDAppClient *strongSelf = weakSelf; |
| 177 if (error) { | 177 if (error) { |
| 178 [strongSelf.delegate appClient:strongSelf didError:error]; | 178 [strongSelf.delegate appClient:strongSelf didError:error]; |
| 179 return; | 179 return; |
| 180 } | 180 } |
| 181 NSError *joinError = | 181 NSError *joinError = |
| 182 [[strongSelf class] errorForJoinResultType:response.result]; | 182 [[strongSelf class] errorForJoinResultType:response.result]; |
| 183 if (joinError) { | 183 if (joinError) { |
| 184 ARDLog(@"Failed to join room:%@ on room server.", roomId); | 184 RTCLogError(@"Failed to join room:%@ on room server.", roomId); |
| 185 [strongSelf disconnect]; | 185 [strongSelf disconnect]; |
| 186 [strongSelf.delegate appClient:strongSelf didError:joinError]; | 186 [strongSelf.delegate appClient:strongSelf didError:joinError]; |
| 187 return; | 187 return; |
| 188 } | 188 } |
| 189 ARDLog(@"Joined room:%@ on room server.", roomId); | 189 RTCLog(@"Joined room:%@ on room server.", roomId); |
| 190 strongSelf.roomId = response.roomId; | 190 strongSelf.roomId = response.roomId; |
| 191 strongSelf.clientId = response.clientId; | 191 strongSelf.clientId = response.clientId; |
| 192 strongSelf.isInitiator = response.isInitiator; | 192 strongSelf.isInitiator = response.isInitiator; |
| 193 for (ARDSignalingMessage *message in response.messages) { | 193 for (ARDSignalingMessage *message in response.messages) { |
| 194 if (message.type == kARDSignalingMessageTypeOffer || | 194 if (message.type == kARDSignalingMessageTypeOffer || |
| 195 message.type == kARDSignalingMessageTypeAnswer) { | 195 message.type == kARDSignalingMessageTypeAnswer) { |
| 196 strongSelf.hasReceivedSdp = YES; | 196 strongSelf.hasReceivedSdp = YES; |
| 197 [strongSelf.messageQueue insertObject:message atIndex:0]; | 197 [strongSelf.messageQueue insertObject:message atIndex:0]; |
| 198 } else { | 198 } else { |
| 199 [strongSelf.messageQueue addObject:message]; | 199 [strongSelf.messageQueue addObject:message]; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 break; | 271 break; |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 | 274 |
| 275 #pragma mark - RTCPeerConnectionDelegate | 275 #pragma mark - RTCPeerConnectionDelegate |
| 276 // Callbacks for this delegate occur on non-main thread and need to be | 276 // Callbacks for this delegate occur on non-main thread and need to be |
| 277 // dispatched back to main queue as needed. | 277 // dispatched back to main queue as needed. |
| 278 | 278 |
| 279 - (void)peerConnection:(RTCPeerConnection *)peerConnection | 279 - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 280 signalingStateChanged:(RTCSignalingState)stateChanged { | 280 signalingStateChanged:(RTCSignalingState)stateChanged { |
| 281 ARDLog(@"Signaling state changed: %d", stateChanged); | 281 RTCLog(@"Signaling state changed: %d", stateChanged); |
| 282 } | 282 } |
| 283 | 283 |
| 284 - (void)peerConnection:(RTCPeerConnection *)peerConnection | 284 - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 285 addedStream:(RTCMediaStream *)stream { | 285 addedStream:(RTCMediaStream *)stream { |
| 286 dispatch_async(dispatch_get_main_queue(), ^{ | 286 dispatch_async(dispatch_get_main_queue(), ^{ |
| 287 ARDLog(@"Received %lu video tracks and %lu audio tracks", | 287 RTCLog(@"Received %lu video tracks and %lu audio tracks", |
| 288 (unsigned long)stream.videoTracks.count, | 288 (unsigned long)stream.videoTracks.count, |
| 289 (unsigned long)stream.audioTracks.count); | 289 (unsigned long)stream.audioTracks.count); |
| 290 if (stream.videoTracks.count) { | 290 if (stream.videoTracks.count) { |
| 291 RTCVideoTrack *videoTrack = stream.videoTracks[0]; | 291 RTCVideoTrack *videoTrack = stream.videoTracks[0]; |
| 292 [_delegate appClient:self didReceiveRemoteVideoTrack:videoTrack]; | 292 [_delegate appClient:self didReceiveRemoteVideoTrack:videoTrack]; |
| 293 } | 293 } |
| 294 }); | 294 }); |
| 295 } | 295 } |
| 296 | 296 |
| 297 - (void)peerConnection:(RTCPeerConnection *)peerConnection | 297 - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 298 removedStream:(RTCMediaStream *)stream { | 298 removedStream:(RTCMediaStream *)stream { |
| 299 ARDLog(@"Stream was removed."); | 299 RTCLog(@"Stream was removed."); |
| 300 } | 300 } |
| 301 | 301 |
| 302 - (void)peerConnectionOnRenegotiationNeeded: | 302 - (void)peerConnectionOnRenegotiationNeeded: |
| 303 (RTCPeerConnection *)peerConnection { | 303 (RTCPeerConnection *)peerConnection { |
| 304 ARDLog(@"WARNING: Renegotiation needed but unimplemented."); | 304 RTCLog(@"WARNING: Renegotiation needed but unimplemented."); |
| 305 } | 305 } |
| 306 | 306 |
| 307 - (void)peerConnection:(RTCPeerConnection *)peerConnection | 307 - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 308 iceConnectionChanged:(RTCICEConnectionState)newState { | 308 iceConnectionChanged:(RTCICEConnectionState)newState { |
| 309 ARDLog(@"ICE state changed: %d", newState); | 309 RTCLog(@"ICE state changed: %d", newState); |
| 310 dispatch_async(dispatch_get_main_queue(), ^{ | 310 dispatch_async(dispatch_get_main_queue(), ^{ |
| 311 [_delegate appClient:self didChangeConnectionState:newState]; | 311 [_delegate appClient:self didChangeConnectionState:newState]; |
| 312 }); | 312 }); |
| 313 } | 313 } |
| 314 | 314 |
| 315 - (void)peerConnection:(RTCPeerConnection *)peerConnection | 315 - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 316 iceGatheringChanged:(RTCICEGatheringState)newState { | 316 iceGatheringChanged:(RTCICEGatheringState)newState { |
| 317 ARDLog(@"ICE gathering state changed: %d", newState); | 317 RTCLog(@"ICE gathering state changed: %d", newState); |
| 318 } | 318 } |
| 319 | 319 |
| 320 - (void)peerConnection:(RTCPeerConnection *)peerConnection | 320 - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 321 gotICECandidate:(RTCICECandidate *)candidate { | 321 gotICECandidate:(RTCICECandidate *)candidate { |
| 322 dispatch_async(dispatch_get_main_queue(), ^{ | 322 dispatch_async(dispatch_get_main_queue(), ^{ |
| 323 ARDICECandidateMessage *message = | 323 ARDICECandidateMessage *message = |
| 324 [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; | 324 [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; |
| 325 [self sendSignalingMessage:message]; | 325 [self sendSignalingMessage:message]; |
| 326 }); | 326 }); |
| 327 } | 327 } |
| 328 | 328 |
| 329 - (void)peerConnection:(RTCPeerConnection*)peerConnection | 329 - (void)peerConnection:(RTCPeerConnection*)peerConnection |
| 330 didOpenDataChannel:(RTCDataChannel*)dataChannel { | 330 didOpenDataChannel:(RTCDataChannel*)dataChannel { |
| 331 } | 331 } |
| 332 | 332 |
| 333 #pragma mark - RTCSessionDescriptionDelegate | 333 #pragma mark - RTCSessionDescriptionDelegate |
| 334 // Callbacks for this delegate occur on non-main thread and need to be | 334 // Callbacks for this delegate occur on non-main thread and need to be |
| 335 // dispatched back to main queue as needed. | 335 // dispatched back to main queue as needed. |
| 336 | 336 |
| 337 - (void)peerConnection:(RTCPeerConnection *)peerConnection | 337 - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 338 didCreateSessionDescription:(RTCSessionDescription *)sdp | 338 didCreateSessionDescription:(RTCSessionDescription *)sdp |
| 339 error:(NSError *)error { | 339 error:(NSError *)error { |
| 340 dispatch_async(dispatch_get_main_queue(), ^{ | 340 dispatch_async(dispatch_get_main_queue(), ^{ |
| 341 if (error) { | 341 if (error) { |
| 342 ARDLog(@"Failed to create session description. Error: %@", error); | 342 RTCLogError(@"Failed to create session description. Error: %@", error); |
| 343 [self disconnect]; | 343 [self disconnect]; |
| 344 NSDictionary *userInfo = @{ | 344 NSDictionary *userInfo = @{ |
| 345 NSLocalizedDescriptionKey: @"Failed to create session description.", | 345 NSLocalizedDescriptionKey: @"Failed to create session description.", |
| 346 }; | 346 }; |
| 347 NSError *sdpError = | 347 NSError *sdpError = |
| 348 [[NSError alloc] initWithDomain:kARDAppClientErrorDomain | 348 [[NSError alloc] initWithDomain:kARDAppClientErrorDomain |
| 349 code:kARDAppClientErrorCreateSDP | 349 code:kARDAppClientErrorCreateSDP |
| 350 userInfo:userInfo]; | 350 userInfo:userInfo]; |
| 351 [_delegate appClient:self didError:sdpError]; | 351 [_delegate appClient:self didError:sdpError]; |
| 352 return; | 352 return; |
| 353 } | 353 } |
| 354 // Prefer H264 if available. | 354 // Prefer H264 if available. |
| 355 RTCSessionDescription *sdpPreferringH264 = | 355 RTCSessionDescription *sdpPreferringH264 = |
| 356 [ARDSDPUtils descriptionForDescription:sdp | 356 [ARDSDPUtils descriptionForDescription:sdp |
| 357 preferredVideoCodec:@"H264"]; | 357 preferredVideoCodec:@"H264"]; |
| 358 [_peerConnection setLocalDescriptionWithDelegate:self | 358 [_peerConnection setLocalDescriptionWithDelegate:self |
| 359 sessionDescription:sdpPreferringH264]; | 359 sessionDescription:sdpPreferringH264]; |
| 360 ARDSessionDescriptionMessage *message = | 360 ARDSessionDescriptionMessage *message = |
| 361 [[ARDSessionDescriptionMessage alloc] | 361 [[ARDSessionDescriptionMessage alloc] |
| 362 initWithDescription:sdpPreferringH264]; | 362 initWithDescription:sdpPreferringH264]; |
| 363 [self sendSignalingMessage:message]; | 363 [self sendSignalingMessage:message]; |
| 364 }); | 364 }); |
| 365 } | 365 } |
| 366 | 366 |
| 367 - (void)peerConnection:(RTCPeerConnection *)peerConnection | 367 - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 368 didSetSessionDescriptionWithError:(NSError *)error { | 368 didSetSessionDescriptionWithError:(NSError *)error { |
| 369 dispatch_async(dispatch_get_main_queue(), ^{ | 369 dispatch_async(dispatch_get_main_queue(), ^{ |
| 370 if (error) { | 370 if (error) { |
| 371 ARDLog(@"Failed to set session description. Error: %@", error); | 371 RTCLogError(@"Failed to set session description. Error: %@", error); |
| 372 [self disconnect]; | 372 [self disconnect]; |
| 373 NSDictionary *userInfo = @{ | 373 NSDictionary *userInfo = @{ |
| 374 NSLocalizedDescriptionKey: @"Failed to set session description.", | 374 NSLocalizedDescriptionKey: @"Failed to set session description.", |
| 375 }; | 375 }; |
| 376 NSError *sdpError = | 376 NSError *sdpError = |
| 377 [[NSError alloc] initWithDomain:kARDAppClientErrorDomain | 377 [[NSError alloc] initWithDomain:kARDAppClientErrorDomain |
| 378 code:kARDAppClientErrorSetSDP | 378 code:kARDAppClientErrorSetSDP |
| 379 userInfo:userInfo]; | 379 userInfo:userInfo]; |
| 380 [_delegate appClient:self didError:sdpError]; | 380 [_delegate appClient:self didError:sdpError]; |
| 381 return; | 381 return; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 code:kARDAppClientErrorInvalidRoom | 649 code:kARDAppClientErrorInvalidRoom |
| 650 userInfo:@{ | 650 userInfo:@{ |
| 651 NSLocalizedDescriptionKey: @"Invalid room.", | 651 NSLocalizedDescriptionKey: @"Invalid room.", |
| 652 }]; | 652 }]; |
| 653 break; | 653 break; |
| 654 } | 654 } |
| 655 return error; | 655 return error; |
| 656 } | 656 } |
| 657 | 657 |
| 658 @end | 658 @end |
| OLD | NEW |