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 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 @implementation ARDAppClient { | 92 @implementation ARDAppClient { |
93 RTCFileLogger *_fileLogger; | 93 RTCFileLogger *_fileLogger; |
94 ARDTimerProxy *_statsTimer; | 94 ARDTimerProxy *_statsTimer; |
95 } | 95 } |
96 | 96 |
97 @synthesize shouldGetStats = _shouldGetStats; | 97 @synthesize shouldGetStats = _shouldGetStats; |
98 @synthesize state = _state; | 98 @synthesize state = _state; |
99 @synthesize delegate = _delegate; | 99 @synthesize delegate = _delegate; |
100 @synthesize roomServerClient = _roomServerClient; | 100 @synthesize roomServerClient = _roomServerClient; |
101 @synthesize channel = _channel; | 101 @synthesize channel = _channel; |
102 @synthesize loopbackChannel = _loopbackChannel; | |
102 @synthesize turnClient = _turnClient; | 103 @synthesize turnClient = _turnClient; |
103 @synthesize peerConnection = _peerConnection; | 104 @synthesize peerConnection = _peerConnection; |
104 @synthesize factory = _factory; | 105 @synthesize factory = _factory; |
105 @synthesize messageQueue = _messageQueue; | 106 @synthesize messageQueue = _messageQueue; |
106 @synthesize isTurnComplete = _isTurnComplete; | 107 @synthesize isTurnComplete = _isTurnComplete; |
107 @synthesize hasReceivedSdp = _hasReceivedSdp; | 108 @synthesize hasReceivedSdp = _hasReceivedSdp; |
108 @synthesize roomId = _roomId; | 109 @synthesize roomId = _roomId; |
109 @synthesize clientId = _clientId; | 110 @synthesize clientId = _clientId; |
110 @synthesize isInitiator = _isInitiator; | 111 @synthesize isInitiator = _isInitiator; |
111 @synthesize iceServers = _iceServers; | 112 @synthesize iceServers = _iceServers; |
112 @synthesize webSocketURL = _websocketURL; | 113 @synthesize webSocketURL = _websocketURL; |
113 @synthesize webSocketRestURL = _websocketRestURL; | 114 @synthesize webSocketRestURL = _websocketRestURL; |
114 @synthesize defaultPeerConnectionConstraints = | 115 @synthesize defaultPeerConnectionConstraints = |
115 _defaultPeerConnectionConstraints; | 116 _defaultPeerConnectionConstraints; |
117 @synthesize isLoopback = _isLoopback; | |
118 @synthesize isAudioOnly = _isAudioOnly; | |
116 | 119 |
117 - (instancetype)init { | 120 - (instancetype)init { |
118 if (self = [super init]) { | 121 if (self = [super init]) { |
119 _roomServerClient = [[ARDAppEngineClient alloc] init]; | 122 _roomServerClient = [[ARDAppEngineClient alloc] init]; |
120 NSURL *turnRequestURL = [NSURL URLWithString:kARDTurnRequestUrl]; | 123 NSURL *turnRequestURL = [NSURL URLWithString:kARDTurnRequestUrl]; |
121 _turnClient = [[ARDCEODTURNClient alloc] initWithURL:turnRequestURL]; | 124 _turnClient = [[ARDCEODTURNClient alloc] initWithURL:turnRequestURL]; |
122 [self configure]; | 125 [self configure]; |
123 } | 126 } |
124 return self; | 127 return self; |
125 } | 128 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 | 194 |
192 - (void)setState:(ARDAppClientState)state { | 195 - (void)setState:(ARDAppClientState)state { |
193 if (_state == state) { | 196 if (_state == state) { |
194 return; | 197 return; |
195 } | 198 } |
196 _state = state; | 199 _state = state; |
197 [_delegate appClient:self didChangeState:_state]; | 200 [_delegate appClient:self didChangeState:_state]; |
198 } | 201 } |
199 | 202 |
200 - (void)connectToRoomWithId:(NSString *)roomId | 203 - (void)connectToRoomWithId:(NSString *)roomId |
204 isLoopback:(BOOL)isLoopback | |
205 isAudioOnly:(BOOL)isAudioOnly | |
201 options:(NSDictionary *)options { | 206 options:(NSDictionary *)options { |
202 NSParameterAssert(roomId.length); | 207 NSParameterAssert(roomId.length); |
203 NSParameterAssert(_state == kARDAppClientStateDisconnected); | 208 NSParameterAssert(_state == kARDAppClientStateDisconnected); |
209 _isLoopback = isLoopback; | |
210 _isAudioOnly = isAudioOnly; | |
204 self.state = kARDAppClientStateConnecting; | 211 self.state = kARDAppClientStateConnecting; |
205 | 212 |
206 // Request TURN. | 213 // Request TURN. |
207 __weak ARDAppClient *weakSelf = self; | 214 __weak ARDAppClient *weakSelf = self; |
208 [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, | 215 [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, |
209 NSError *error) { | 216 NSError *error) { |
210 if (error) { | 217 if (error) { |
211 RTCLogError("Error retrieving TURN servers: %@", | 218 RTCLogError("Error retrieving TURN servers: %@", |
212 error.localizedDescription); | 219 error.localizedDescription); |
213 } | 220 } |
214 ARDAppClient *strongSelf = weakSelf; | 221 ARDAppClient *strongSelf = weakSelf; |
215 [strongSelf.iceServers addObjectsFromArray:turnServers]; | 222 [strongSelf.iceServers addObjectsFromArray:turnServers]; |
216 strongSelf.isTurnComplete = YES; | 223 strongSelf.isTurnComplete = YES; |
217 [strongSelf startSignalingIfReady]; | 224 [strongSelf startSignalingIfReady]; |
218 }]; | 225 }]; |
219 | 226 |
220 // Join room on room server. | 227 // Join room on room server. |
221 [_roomServerClient joinRoomWithRoomId:roomId | 228 [_roomServerClient joinRoomWithRoomId:roomId |
229 isLoopback:isLoopback | |
222 completionHandler:^(ARDJoinResponse *response, NSError *error) { | 230 completionHandler:^(ARDJoinResponse *response, NSError *error) { |
223 ARDAppClient *strongSelf = weakSelf; | 231 ARDAppClient *strongSelf = weakSelf; |
224 if (error) { | 232 if (error) { |
225 [strongSelf.delegate appClient:strongSelf didError:error]; | 233 [strongSelf.delegate appClient:strongSelf didError:error]; |
226 return; | 234 return; |
227 } | 235 } |
228 NSError *joinError = | 236 NSError *joinError = |
229 [[strongSelf class] errorForJoinResultType:response.result]; | 237 [[strongSelf class] errorForJoinResultType:response.result]; |
230 if (joinError) { | 238 if (joinError) { |
231 RTCLogError(@"Failed to join room:%@ on room server.", roomId); | 239 RTCLogError(@"Failed to join room:%@ on room server.", roomId); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 } | 580 } |
573 | 581 |
574 - (RTCVideoTrack *)createLocalVideoTrack { | 582 - (RTCVideoTrack *)createLocalVideoTrack { |
575 RTCVideoTrack* localVideoTrack = nil; | 583 RTCVideoTrack* localVideoTrack = nil; |
576 // The iOS simulator doesn't provide any sort of camera capture | 584 // The iOS simulator doesn't provide any sort of camera capture |
577 // support or emulation (http://goo.gl/rHAnC1) so don't bother | 585 // support or emulation (http://goo.gl/rHAnC1) so don't bother |
578 // trying to open a local stream. | 586 // trying to open a local stream. |
579 // TODO(tkchin): local video capture for OSX. See | 587 // TODO(tkchin): local video capture for OSX. See |
580 // https://code.google.com/p/webrtc/issues/detail?id=3417. | 588 // https://code.google.com/p/webrtc/issues/detail?id=3417. |
581 #if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE | 589 #if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE |
582 RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints]; | 590 if (!_isAudioOnly) { |
henrika_webrtc
2015/09/14 08:31:20
Not sure what type of logging support we have but
Chuck
2015/09/28 16:26:40
it doesn't look like we do much logging at all in
| |
583 RTCAVFoundationVideoSource *source = | 591 RTCMediaConstraints *mediaConstraints = |
584 [[RTCAVFoundationVideoSource alloc] initWithFactory:_factory | 592 [self defaultMediaStreamConstraints]; |
585 constraints:mediaConstraints]; | 593 RTCAVFoundationVideoSource *source = |
586 localVideoTrack = | 594 [[RTCAVFoundationVideoSource alloc] initWithFactory:_factory |
587 [[RTCVideoTrack alloc] initWithFactory:_factory | 595 constraints:mediaConstraints]; |
588 source:source | 596 localVideoTrack = |
589 trackId:@"ARDAMSv0"]; | 597 [[RTCVideoTrack alloc] initWithFactory:_factory |
598 source:source | |
599 trackId:@"ARDAMSv0"]; | |
600 } | |
590 #endif | 601 #endif |
591 return localVideoTrack; | 602 return localVideoTrack; |
592 } | 603 } |
593 | 604 |
594 #pragma mark - Collider methods | 605 #pragma mark - Collider methods |
595 | 606 |
596 - (void)registerWithColliderIfReady { | 607 - (void)registerWithColliderIfReady { |
597 if (!self.hasJoinedRoomServerRoom) { | 608 if (!self.hasJoinedRoomServerRoom) { |
598 return; | 609 return; |
599 } | 610 } |
600 // Open WebSocket connection. | 611 // Open WebSocket connection. |
601 if (!_channel) { | 612 if (!_channel) { |
602 _channel = | 613 _channel = |
603 [[ARDWebSocketChannel alloc] initWithURL:_websocketURL | 614 [[ARDWebSocketChannel alloc] initWithURL:_websocketURL |
604 restURL:_websocketRestURL | 615 restURL:_websocketRestURL |
605 delegate:self]; | 616 delegate:self]; |
617 if (_isLoopback) { | |
618 _loopbackChannel = | |
619 [[ARDLoopbackWebSocketChannel alloc] initWithURL:_websocketURL | |
620 restURL:_websocketRestURL]; | |
621 } | |
606 } | 622 } |
607 [_channel registerForRoomId:_roomId clientId:_clientId]; | 623 [_channel registerForRoomId:_roomId clientId:_clientId]; |
624 if (_isLoopback) { | |
625 [_loopbackChannel registerForRoomId:_roomId clientId:@"LOOPBACk_CLIENT_ID"]; | |
626 } | |
608 } | 627 } |
609 | 628 |
610 #pragma mark - Defaults | 629 #pragma mark - Defaults |
611 | 630 |
612 - (RTCMediaConstraints *)defaultMediaStreamConstraints { | 631 - (RTCMediaConstraints *)defaultMediaStreamConstraints { |
613 RTCMediaConstraints* constraints = | 632 RTCMediaConstraints* constraints = |
614 [[RTCMediaConstraints alloc] | 633 [[RTCMediaConstraints alloc] |
615 initWithMandatoryConstraints:nil | 634 initWithMandatoryConstraints:nil |
616 optionalConstraints:nil]; | 635 optionalConstraints:nil]; |
617 return constraints; | 636 return constraints; |
(...skipping 12 matching lines...) Expand all Loading... | |
630 [[RTCMediaConstraints alloc] | 649 [[RTCMediaConstraints alloc] |
631 initWithMandatoryConstraints:mandatoryConstraints | 650 initWithMandatoryConstraints:mandatoryConstraints |
632 optionalConstraints:nil]; | 651 optionalConstraints:nil]; |
633 return constraints; | 652 return constraints; |
634 } | 653 } |
635 | 654 |
636 - (RTCMediaConstraints *)defaultPeerConnectionConstraints { | 655 - (RTCMediaConstraints *)defaultPeerConnectionConstraints { |
637 if (_defaultPeerConnectionConstraints) { | 656 if (_defaultPeerConnectionConstraints) { |
638 return _defaultPeerConnectionConstraints; | 657 return _defaultPeerConnectionConstraints; |
639 } | 658 } |
659 NSString *value = _isLoopback ? @"false" : @"true"; | |
640 NSArray *optionalConstraints = @[ | 660 NSArray *optionalConstraints = @[ |
641 [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"] | 661 [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:value] |
642 ]; | 662 ]; |
643 RTCMediaConstraints* constraints = | 663 RTCMediaConstraints* constraints = |
644 [[RTCMediaConstraints alloc] | 664 [[RTCMediaConstraints alloc] |
645 initWithMandatoryConstraints:nil | 665 initWithMandatoryConstraints:nil |
646 optionalConstraints:optionalConstraints]; | 666 optionalConstraints:optionalConstraints]; |
647 return constraints; | 667 return constraints; |
648 } | 668 } |
649 | 669 |
650 - (RTCICEServer *)defaultSTUNServer { | 670 - (RTCICEServer *)defaultSTUNServer { |
651 NSURL *defaultSTUNServerURL = [NSURL URLWithString:kARDDefaultSTUNServerUrl]; | 671 NSURL *defaultSTUNServerURL = [NSURL URLWithString:kARDDefaultSTUNServerUrl]; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 code:kARDAppClientErrorInvalidRoom | 725 code:kARDAppClientErrorInvalidRoom |
706 userInfo:@{ | 726 userInfo:@{ |
707 NSLocalizedDescriptionKey: @"Invalid room.", | 727 NSLocalizedDescriptionKey: @"Invalid room.", |
708 }]; | 728 }]; |
709 break; | 729 break; |
710 } | 730 } |
711 return error; | 731 return error; |
712 } | 732 } |
713 | 733 |
714 @end | 734 @end |
OLD | NEW |