OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import "ARDAppClient+Internal.h" | 11 #import "ARDAppClient+Internal.h" |
12 | 12 |
13 #if defined(WEBRTC_IOS) | 13 #if defined(WEBRTC_IOS) |
14 #import "WebRTC/RTCAVFoundationVideoSource.h" | 14 #import "WebRTC/RTCAVFoundationVideoSource.h" |
15 #import "WebRTC/RTCTracing.h" | |
16 #endif | 15 #endif |
17 #import "WebRTC/RTCAudioTrack.h" | 16 #import "WebRTC/RTCAudioTrack.h" |
18 #import "WebRTC/RTCConfiguration.h" | 17 #import "WebRTC/RTCConfiguration.h" |
19 #import "WebRTC/RTCFileLogger.h" | 18 #import "WebRTC/RTCFileLogger.h" |
20 #import "WebRTC/RTCIceServer.h" | 19 #import "WebRTC/RTCIceServer.h" |
21 #import "WebRTC/RTCLogging.h" | 20 #import "WebRTC/RTCLogging.h" |
22 #import "WebRTC/RTCMediaConstraints.h" | 21 #import "WebRTC/RTCMediaConstraints.h" |
23 #import "WebRTC/RTCMediaStream.h" | 22 #import "WebRTC/RTCMediaStream.h" |
24 #import "WebRTC/RTCPeerConnectionFactory.h" | 23 #import "WebRTC/RTCPeerConnectionFactory.h" |
25 #import "WebRTC/RTCRtpSender.h" | 24 #import "WebRTC/RTCRtpSender.h" |
| 25 #import "WebRTC/RTCTracing.h" |
26 | 26 |
27 #import "ARDAppEngineClient.h" | 27 #import "ARDAppEngineClient.h" |
28 #import "ARDCEODTURNClient.h" | 28 #import "ARDCEODTURNClient.h" |
29 #import "ARDJoinResponse.h" | 29 #import "ARDJoinResponse.h" |
30 #import "ARDMessageResponse.h" | 30 #import "ARDMessageResponse.h" |
31 #import "ARDSDPUtils.h" | 31 #import "ARDSDPUtils.h" |
32 #import "ARDSignalingMessage.h" | 32 #import "ARDSignalingMessage.h" |
33 #import "ARDUtilities.h" | 33 #import "ARDUtilities.h" |
34 #import "ARDWebSocketChannel.h" | 34 #import "ARDWebSocketChannel.h" |
35 #import "RTCIceCandidate+JSON.h" | 35 #import "RTCIceCandidate+JSON.h" |
(...skipping 12 matching lines...) Expand all Loading... |
48 static NSInteger const kARDAppClientErrorCreateSDP = -3; | 48 static NSInteger const kARDAppClientErrorCreateSDP = -3; |
49 static NSInteger const kARDAppClientErrorSetSDP = -4; | 49 static NSInteger const kARDAppClientErrorSetSDP = -4; |
50 static NSInteger const kARDAppClientErrorInvalidClient = -5; | 50 static NSInteger const kARDAppClientErrorInvalidClient = -5; |
51 static NSInteger const kARDAppClientErrorInvalidRoom = -6; | 51 static NSInteger const kARDAppClientErrorInvalidRoom = -6; |
52 static NSString * const kARDMediaStreamId = @"ARDAMS"; | 52 static NSString * const kARDMediaStreamId = @"ARDAMS"; |
53 static NSString * const kARDAudioTrackId = @"ARDAMSa0"; | 53 static NSString * const kARDAudioTrackId = @"ARDAMSa0"; |
54 static NSString * const kARDVideoTrackId = @"ARDAMSv0"; | 54 static NSString * const kARDVideoTrackId = @"ARDAMSv0"; |
55 | 55 |
56 // TODO(tkchin): Remove guard once rtc_sdk_common_objc compiles on Mac. | 56 // TODO(tkchin): Remove guard once rtc_sdk_common_objc compiles on Mac. |
57 #if defined(WEBRTC_IOS) | 57 #if defined(WEBRTC_IOS) |
58 // TODO(tkchin): Add this as a UI option. | 58 // TODO(tkchin): Add these as UI options. |
59 static BOOL const kARDAppClientEnableTracing = NO; | 59 static BOOL const kARDAppClientEnableTracing = NO; |
| 60 static BOOL const kARDAppClientEnableRtcEventLog = YES; |
| 61 static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. |
60 #endif | 62 #endif |
61 | 63 |
62 // We need a proxy to NSTimer because it causes a strong retain cycle. When | 64 // We need a proxy to NSTimer because it causes a strong retain cycle. When |
63 // using the proxy, |invalidate| must be called before it properly deallocs. | 65 // using the proxy, |invalidate| must be called before it properly deallocs. |
64 @interface ARDTimerProxy : NSObject | 66 @interface ARDTimerProxy : NSObject |
65 | 67 |
66 - (instancetype)initWithInterval:(NSTimeInterval)interval | 68 - (instancetype)initWithInterval:(NSTimeInterval)interval |
67 repeats:(BOOL)repeats | 69 repeats:(BOOL)repeats |
68 timerHandler:(void (^)(void))timerHandler; | 70 timerHandler:(void (^)(void))timerHandler; |
69 - (void)invalidate; | 71 - (void)invalidate; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 isLoopback:(BOOL)isLoopback | 222 isLoopback:(BOOL)isLoopback |
221 isAudioOnly:(BOOL)isAudioOnly { | 223 isAudioOnly:(BOOL)isAudioOnly { |
222 NSParameterAssert(roomId.length); | 224 NSParameterAssert(roomId.length); |
223 NSParameterAssert(_state == kARDAppClientStateDisconnected); | 225 NSParameterAssert(_state == kARDAppClientStateDisconnected); |
224 _isLoopback = isLoopback; | 226 _isLoopback = isLoopback; |
225 _isAudioOnly = isAudioOnly; | 227 _isAudioOnly = isAudioOnly; |
226 self.state = kARDAppClientStateConnecting; | 228 self.state = kARDAppClientStateConnecting; |
227 | 229 |
228 #if defined(WEBRTC_IOS) | 230 #if defined(WEBRTC_IOS) |
229 if (kARDAppClientEnableTracing) { | 231 if (kARDAppClientEnableTracing) { |
230 NSArray *paths = NSSearchPathForDirectoriesInDomains( | 232 NSString *filePath = [self documentsFilePathForFileName:@"webrtc-trace.txt"]
; |
231 NSDocumentDirectory, NSUserDomainMask, YES); | |
232 NSString *documentsDirPath = paths.firstObject; | |
233 NSString *filePath = | |
234 [documentsDirPath stringByAppendingPathComponent:@"webrtc-trace.txt"]; | |
235 RTCStartInternalCapture(filePath); | 233 RTCStartInternalCapture(filePath); |
236 } | 234 } |
237 #endif | 235 #endif |
238 | 236 |
239 // Request TURN. | 237 // Request TURN. |
240 __weak ARDAppClient *weakSelf = self; | 238 __weak ARDAppClient *weakSelf = self; |
241 [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, | 239 [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, |
242 NSError *error) { | 240 NSError *error) { |
243 if (error) { | 241 if (error) { |
244 RTCLogError("Error retrieving TURN servers: %@", | 242 RTCLogError("Error retrieving TURN servers: %@", |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 305 } |
308 _clientId = nil; | 306 _clientId = nil; |
309 _roomId = nil; | 307 _roomId = nil; |
310 _isInitiator = NO; | 308 _isInitiator = NO; |
311 _hasReceivedSdp = NO; | 309 _hasReceivedSdp = NO; |
312 _messageQueue = [NSMutableArray array]; | 310 _messageQueue = [NSMutableArray array]; |
313 _peerConnection = nil; | 311 _peerConnection = nil; |
314 self.state = kARDAppClientStateDisconnected; | 312 self.state = kARDAppClientStateDisconnected; |
315 #if defined(WEBRTC_IOS) | 313 #if defined(WEBRTC_IOS) |
316 RTCStopInternalCapture(); | 314 RTCStopInternalCapture(); |
| 315 [_factory stopRtcEventLog]; |
317 #endif | 316 #endif |
318 } | 317 } |
319 | 318 |
320 #pragma mark - ARDSignalingChannelDelegate | 319 #pragma mark - ARDSignalingChannelDelegate |
321 | 320 |
322 - (void)channel:(id<ARDSignalingChannel>)channel | 321 - (void)channel:(id<ARDSignalingChannel>)channel |
323 didReceiveMessage:(ARDSignalingMessage *)message { | 322 didReceiveMessage:(ARDSignalingMessage *)message { |
324 switch (message.type) { | 323 switch (message.type) { |
325 case kARDSignalingMessageTypeOffer: | 324 case kARDSignalingMessageTypeOffer: |
326 case kARDSignalingMessageTypeAnswer: | 325 case kARDSignalingMessageTypeAnswer: |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 [strongSelf peerConnection:strongSelf.peerConnection | 490 [strongSelf peerConnection:strongSelf.peerConnection |
492 didCreateSessionDescription:sdp | 491 didCreateSessionDescription:sdp |
493 error:error]; | 492 error:error]; |
494 }]; | 493 }]; |
495 } | 494 } |
496 }); | 495 }); |
497 } | 496 } |
498 | 497 |
499 #pragma mark - Private | 498 #pragma mark - Private |
500 | 499 |
| 500 #if defined(WEBRTC_IOS) |
| 501 |
| 502 - (NSString *)documentsFilePathForFileName:(NSString *)fileName { |
| 503 NSParameterAssert(fileName.length); |
| 504 NSArray *paths = NSSearchPathForDirectoriesInDomains( |
| 505 NSDocumentDirectory, NSUserDomainMask, YES); |
| 506 NSString *documentsDirPath = paths.firstObject; |
| 507 NSString *filePath = |
| 508 [documentsDirPath stringByAppendingPathComponent:fileName]; |
| 509 return filePath; |
| 510 } |
| 511 |
| 512 #endif |
| 513 |
501 - (BOOL)hasJoinedRoomServerRoom { | 514 - (BOOL)hasJoinedRoomServerRoom { |
502 return _clientId.length; | 515 return _clientId.length; |
503 } | 516 } |
504 | 517 |
505 // Begins the peer connection connection process if we have both joined a room | 518 // Begins the peer connection connection process if we have both joined a room |
506 // on the room server and tried to obtain a TURN server. Otherwise does nothing. | 519 // on the room server and tried to obtain a TURN server. Otherwise does nothing. |
507 // A peer connection object will be created with a stream that contains local | 520 // A peer connection object will be created with a stream that contains local |
508 // audio and video capture. If this client is the caller, an offer is created as | 521 // audio and video capture. If this client is the caller, an offer is created as |
509 // well, otherwise the client will wait for an offer to arrive. | 522 // well, otherwise the client will wait for an offer to arrive. |
510 - (void)startSignalingIfReady { | 523 - (void)startSignalingIfReady { |
511 if (!_isTurnComplete || !self.hasJoinedRoomServerRoom) { | 524 if (!_isTurnComplete || !self.hasJoinedRoomServerRoom) { |
512 return; | 525 return; |
513 } | 526 } |
514 self.state = kARDAppClientStateConnected; | 527 self.state = kARDAppClientStateConnected; |
515 | 528 |
| 529 #if defined(WEBRTC_IOS) |
| 530 // Start event log. |
| 531 if (kARDAppClientEnableRtcEventLog) { |
| 532 NSString *filePath = [self documentsFilePathForFileName:@"webrtc-rtceventlog
"]; |
| 533 if (![_factory startRtcEventLogWithFilePath:filePath |
| 534 maxSizeInBytes:kARDAppClientRtcEventLogMaxSizeI
nBytes]) { |
| 535 RTCLogError(@"Failed to start event logging."); |
| 536 } |
| 537 } |
| 538 #endif |
| 539 |
516 // Create peer connection. | 540 // Create peer connection. |
517 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; | 541 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; |
518 RTCConfiguration *config = [[RTCConfiguration alloc] init]; | 542 RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
519 config.iceServers = _iceServers; | 543 config.iceServers = _iceServers; |
520 _peerConnection = [_factory peerConnectionWithConfiguration:config | 544 _peerConnection = [_factory peerConnectionWithConfiguration:config |
521 constraints:constraints | 545 constraints:constraints |
522 delegate:self]; | 546 delegate:self]; |
523 // Create AV senders. | 547 // Create AV senders. |
524 [self createAudioSender]; | 548 [self createAudioSender]; |
525 [self createVideoSender]; | 549 [self createVideoSender]; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 code:kARDAppClientErrorInvalidRoom | 813 code:kARDAppClientErrorInvalidRoom |
790 userInfo:@{ | 814 userInfo:@{ |
791 NSLocalizedDescriptionKey: @"Invalid room.", | 815 NSLocalizedDescriptionKey: @"Invalid room.", |
792 }]; | 816 }]; |
793 break; | 817 break; |
794 } | 818 } |
795 return error; | 819 return error; |
796 } | 820 } |
797 | 821 |
798 @end | 822 @end |
OLD | NEW |