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 |
201 options:(NSDictionary *)options { | 204 isLoopback:(BOOL)isLoopback |
205 isAudioOnly:(BOOL)isAudioOnly { | |
202 NSParameterAssert(roomId.length); | 206 NSParameterAssert(roomId.length); |
203 NSParameterAssert(_state == kARDAppClientStateDisconnected); | 207 NSParameterAssert(_state == kARDAppClientStateDisconnected); |
208 _isLoopback = isLoopback; | |
209 _isAudioOnly = isAudioOnly; | |
204 self.state = kARDAppClientStateConnecting; | 210 self.state = kARDAppClientStateConnecting; |
205 | 211 |
206 // Request TURN. | 212 // Request TURN. |
207 __weak ARDAppClient *weakSelf = self; | 213 __weak ARDAppClient *weakSelf = self; |
208 [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, | 214 [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, |
209 NSError *error) { | 215 NSError *error) { |
210 if (error) { | 216 if (error) { |
211 RTCLogError("Error retrieving TURN servers: %@", | 217 RTCLogError("Error retrieving TURN servers: %@", |
212 error.localizedDescription); | 218 error.localizedDescription); |
213 } | 219 } |
214 ARDAppClient *strongSelf = weakSelf; | 220 ARDAppClient *strongSelf = weakSelf; |
215 [strongSelf.iceServers addObjectsFromArray:turnServers]; | 221 [strongSelf.iceServers addObjectsFromArray:turnServers]; |
216 strongSelf.isTurnComplete = YES; | 222 strongSelf.isTurnComplete = YES; |
217 [strongSelf startSignalingIfReady]; | 223 [strongSelf startSignalingIfReady]; |
218 }]; | 224 }]; |
219 | 225 |
220 // Join room on room server. | 226 // Join room on room server. |
221 [_roomServerClient joinRoomWithRoomId:roomId | 227 [_roomServerClient joinRoomWithRoomId:roomId |
228 isLoopback:isLoopback | |
222 completionHandler:^(ARDJoinResponse *response, NSError *error) { | 229 completionHandler:^(ARDJoinResponse *response, NSError *error) { |
223 ARDAppClient *strongSelf = weakSelf; | 230 ARDAppClient *strongSelf = weakSelf; |
224 if (error) { | 231 if (error) { |
225 [strongSelf.delegate appClient:strongSelf didError:error]; | 232 [strongSelf.delegate appClient:strongSelf didError:error]; |
226 return; | 233 return; |
227 } | 234 } |
228 NSError *joinError = | 235 NSError *joinError = |
229 [[strongSelf class] errorForJoinResultType:response.result]; | 236 [[strongSelf class] errorForJoinResultType:response.result]; |
230 if (joinError) { | 237 if (joinError) { |
231 RTCLogError(@"Failed to join room:%@ on room server.", roomId); | 238 RTCLogError(@"Failed to join room:%@ on room server.", roomId); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 } | 579 } |
573 | 580 |
574 - (RTCVideoTrack *)createLocalVideoTrack { | 581 - (RTCVideoTrack *)createLocalVideoTrack { |
575 RTCVideoTrack* localVideoTrack = nil; | 582 RTCVideoTrack* localVideoTrack = nil; |
576 // The iOS simulator doesn't provide any sort of camera capture | 583 // The iOS simulator doesn't provide any sort of camera capture |
577 // support or emulation (http://goo.gl/rHAnC1) so don't bother | 584 // support or emulation (http://goo.gl/rHAnC1) so don't bother |
578 // trying to open a local stream. | 585 // trying to open a local stream. |
579 // TODO(tkchin): local video capture for OSX. See | 586 // TODO(tkchin): local video capture for OSX. See |
580 // https://code.google.com/p/webrtc/issues/detail?id=3417. | 587 // https://code.google.com/p/webrtc/issues/detail?id=3417. |
581 #if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE | 588 #if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE |
582 RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints]; | 589 if (!_isAudioOnly) { |
583 RTCAVFoundationVideoSource *source = | 590 RTCMediaConstraints *mediaConstraints = |
584 [[RTCAVFoundationVideoSource alloc] initWithFactory:_factory | 591 [self defaultMediaStreamConstraints]; |
585 constraints:mediaConstraints]; | 592 RTCAVFoundationVideoSource *source = |
586 localVideoTrack = | 593 [[RTCAVFoundationVideoSource alloc] initWithFactory:_factory |
587 [[RTCVideoTrack alloc] initWithFactory:_factory | 594 constraints:mediaConstraints]; |
588 source:source | 595 localVideoTrack = |
589 trackId:@"ARDAMSv0"]; | 596 [[RTCVideoTrack alloc] initWithFactory:_factory |
597 source:source | |
598 trackId:@"ARDAMSv0"]; | |
599 } | |
590 #endif | 600 #endif |
591 return localVideoTrack; | 601 return localVideoTrack; |
592 } | 602 } |
593 | 603 |
594 #pragma mark - Collider methods | 604 #pragma mark - Collider methods |
595 | 605 |
596 - (void)registerWithColliderIfReady { | 606 - (void)registerWithColliderIfReady { |
597 if (!self.hasJoinedRoomServerRoom) { | 607 if (!self.hasJoinedRoomServerRoom) { |
598 return; | 608 return; |
599 } | 609 } |
600 // Open WebSocket connection. | 610 // Open WebSocket connection. |
601 if (!_channel) { | 611 if (!_channel) { |
602 _channel = | 612 _channel = |
603 [[ARDWebSocketChannel alloc] initWithURL:_websocketURL | 613 [[ARDWebSocketChannel alloc] initWithURL:_websocketURL |
604 restURL:_websocketRestURL | 614 restURL:_websocketRestURL |
605 delegate:self]; | 615 delegate:self]; |
616 if (_isLoopback) { | |
617 _loopbackChannel = | |
618 [[ARDLoopbackWebSocketChannel alloc] initWithURL:_websocketURL | |
619 restURL:_websocketRestURL]; | |
620 } | |
606 } | 621 } |
607 [_channel registerForRoomId:_roomId clientId:_clientId]; | 622 [_channel registerForRoomId:_roomId clientId:_clientId]; |
623 if (_isLoopback) { | |
624 [_loopbackChannel registerForRoomId:_roomId clientId:@"LOOPBACk_CLIENT_ID"]; | |
tkchin_webrtc
2015/10/01 20:11:01
all caps missing k
Chuck
2015/10/02 14:27:08
Done.
| |
625 } | |
608 } | 626 } |
609 | 627 |
610 #pragma mark - Defaults | 628 #pragma mark - Defaults |
611 | 629 |
612 - (RTCMediaConstraints *)defaultMediaStreamConstraints { | 630 - (RTCMediaConstraints *)defaultMediaStreamConstraints { |
613 RTCMediaConstraints* constraints = | 631 RTCMediaConstraints* constraints = |
614 [[RTCMediaConstraints alloc] | 632 [[RTCMediaConstraints alloc] |
615 initWithMandatoryConstraints:nil | 633 initWithMandatoryConstraints:nil |
616 optionalConstraints:nil]; | 634 optionalConstraints:nil]; |
617 return constraints; | 635 return constraints; |
(...skipping 12 matching lines...) Expand all Loading... | |
630 [[RTCMediaConstraints alloc] | 648 [[RTCMediaConstraints alloc] |
631 initWithMandatoryConstraints:mandatoryConstraints | 649 initWithMandatoryConstraints:mandatoryConstraints |
632 optionalConstraints:nil]; | 650 optionalConstraints:nil]; |
633 return constraints; | 651 return constraints; |
634 } | 652 } |
635 | 653 |
636 - (RTCMediaConstraints *)defaultPeerConnectionConstraints { | 654 - (RTCMediaConstraints *)defaultPeerConnectionConstraints { |
637 if (_defaultPeerConnectionConstraints) { | 655 if (_defaultPeerConnectionConstraints) { |
638 return _defaultPeerConnectionConstraints; | 656 return _defaultPeerConnectionConstraints; |
639 } | 657 } |
658 NSString *value = _isLoopback ? @"false" : @"true"; | |
640 NSArray *optionalConstraints = @[ | 659 NSArray *optionalConstraints = @[ |
641 [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"] | 660 [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:value] |
642 ]; | 661 ]; |
643 RTCMediaConstraints* constraints = | 662 RTCMediaConstraints* constraints = |
644 [[RTCMediaConstraints alloc] | 663 [[RTCMediaConstraints alloc] |
645 initWithMandatoryConstraints:nil | 664 initWithMandatoryConstraints:nil |
646 optionalConstraints:optionalConstraints]; | 665 optionalConstraints:optionalConstraints]; |
647 return constraints; | 666 return constraints; |
648 } | 667 } |
649 | 668 |
650 - (RTCICEServer *)defaultSTUNServer { | 669 - (RTCICEServer *)defaultSTUNServer { |
651 NSURL *defaultSTUNServerURL = [NSURL URLWithString:kARDDefaultSTUNServerUrl]; | 670 NSURL *defaultSTUNServerURL = [NSURL URLWithString:kARDDefaultSTUNServerUrl]; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 code:kARDAppClientErrorInvalidRoom | 724 code:kARDAppClientErrorInvalidRoom |
706 userInfo:@{ | 725 userInfo:@{ |
707 NSLocalizedDescriptionKey: @"Invalid room.", | 726 NSLocalizedDescriptionKey: @"Invalid room.", |
708 }]; | 727 }]; |
709 break; | 728 break; |
710 } | 729 } |
711 return error; | 730 return error; |
712 } | 731 } |
713 | 732 |
714 @end | 733 @end |
OLD | NEW |