Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: webrtc/examples/objc/AppRTCDemo/ARDAppClient.m

Issue 1690313002: Update iOS AppRTCDemo to use the updated Objective-C API. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Update Mac demo and other changes after updating against master Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/base/objc/RTCTracing.h" 14 #import "webrtc/base/objc/RTCTracing.h"
15 #import "RTCAVFoundationVideoSource.h" 15 #import "webrtc/api/objc/RTCAVFoundationVideoSource.h"
16 #endif 16 #endif
17 #import "RTCFileLogger.h" 17 #import "webrtc/api/objc/RTCAudioTrack.h"
18 #import "RTCICEServer.h" 18 #import "webrtc/api/objc/RTCConfiguration.h"
19 #import "RTCLogging.h" 19 #import "webrtc/api/objc/RTCIceServer.h"
20 #import "RTCMediaConstraints.h" 20 #import "webrtc/api/objc/RTCMediaConstraints.h"
21 #import "RTCMediaStream.h" 21 #import "webrtc/api/objc/RTCMediaStream.h"
22 #import "RTCPair.h" 22 #import "webrtc/base/objc/RTCFileLogger.h"
23 #import "RTCPeerConnectionInterface.h" 23 #import "webrtc/base/objc/RTCLogging.h"
24 #import "RTCVideoCapturer.h"
25 24
26 #import "ARDAppEngineClient.h" 25 #import "ARDAppEngineClient.h"
27 #import "ARDCEODTURNClient.h" 26 #import "ARDCEODTURNClient.h"
28 #import "ARDJoinResponse.h" 27 #import "ARDJoinResponse.h"
29 #import "ARDMessageResponse.h" 28 #import "ARDMessageResponse.h"
30 #import "ARDSDPUtils.h" 29 #import "ARDSDPUtils.h"
31 #import "ARDSignalingMessage.h" 30 #import "ARDSignalingMessage.h"
32 #import "ARDUtilities.h" 31 #import "ARDUtilities.h"
33 #import "ARDWebSocketChannel.h" 32 #import "ARDWebSocketChannel.h"
34 #import "RTCICECandidate+JSON.h" 33 #import "RTCIceCandidate+JSON.h"
35 #import "RTCSessionDescription+JSON.h" 34 #import "RTCSessionDescription+JSON.h"
36 35
37 static NSString * const kARDDefaultSTUNServerUrl = 36 static NSString * const kARDDefaultSTUNServerUrl =
38 @"stun:stun.l.google.com:19302"; 37 @"stun:stun.l.google.com:19302";
39 // TODO(tkchin): figure out a better username for CEOD statistics. 38 // TODO(tkchin): figure out a better username for CEOD statistics.
40 static NSString * const kARDTurnRequestUrl = 39 static NSString * const kARDTurnRequestUrl =
41 @"https://computeengineondemand.appspot.com" 40 @"https://computeengineondemand.appspot.com"
42 @"/turn?username=iapprtc&key=4080218913"; 41 @"/turn?username=iapprtc&key=4080218913";
43 42
44 static NSString * const kARDAppClientErrorDomain = @"ARDAppClient"; 43 static NSString * const kARDAppClientErrorDomain = @"ARDAppClient";
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 - (void)setShouldGetStats:(BOOL)shouldGetStats { 180 - (void)setShouldGetStats:(BOOL)shouldGetStats {
182 if (_shouldGetStats == shouldGetStats) { 181 if (_shouldGetStats == shouldGetStats) {
183 return; 182 return;
184 } 183 }
185 if (shouldGetStats) { 184 if (shouldGetStats) {
186 __weak ARDAppClient *weakSelf = self; 185 __weak ARDAppClient *weakSelf = self;
187 _statsTimer = [[ARDTimerProxy alloc] initWithInterval:1 186 _statsTimer = [[ARDTimerProxy alloc] initWithInterval:1
188 repeats:YES 187 repeats:YES
189 timerHandler:^{ 188 timerHandler:^{
190 ARDAppClient *strongSelf = weakSelf; 189 ARDAppClient *strongSelf = weakSelf;
191 [strongSelf.peerConnection getStatsWithDelegate:strongSelf 190 [strongSelf.peerConnection statsForTrack:nil
192 mediaStreamTrack:nil 191 statsOutputLevel:RTCStatsOutputLevelDebug
193 statsOutputLevel:RTCStatsOutputLevelDebug]; 192 completionHandler:^(NSArray *stats) {
193 dispatch_async(dispatch_get_main_queue(), ^{
194 ARDAppClient *strongSelf = weakSelf;
195 [strongSelf.delegate appClient:strongSelf didGetStats:stats];
196 });
197 }];
194 }]; 198 }];
195 } else { 199 } else {
196 [_statsTimer invalidate]; 200 [_statsTimer invalidate];
197 _statsTimer = nil; 201 _statsTimer = nil;
198 } 202 }
199 _shouldGetStats = shouldGetStats; 203 _shouldGetStats = shouldGetStats;
200 } 204 }
201 205
202 - (void)setState:(ARDAppClientState)state { 206 - (void)setState:(ARDAppClientState)state {
203 if (_state == state) { 207 if (_state == state) {
(...skipping 18 matching lines...) Expand all
222 NSDocumentDirectory, NSUserDomainMask, YES); 226 NSDocumentDirectory, NSUserDomainMask, YES);
223 NSString *documentsDirPath = paths.firstObject; 227 NSString *documentsDirPath = paths.firstObject;
224 NSString *filePath = 228 NSString *filePath =
225 [documentsDirPath stringByAppendingPathComponent:@"webrtc-trace.txt"]; 229 [documentsDirPath stringByAppendingPathComponent:@"webrtc-trace.txt"];
226 RTCStartInternalCapture(filePath); 230 RTCStartInternalCapture(filePath);
227 } 231 }
228 #endif 232 #endif
229 233
230 // Request TURN. 234 // Request TURN.
231 __weak ARDAppClient *weakSelf = self; 235 __weak ARDAppClient *weakSelf = self;
232 [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, 236 [_turnClient requestServerWithCompletionHandler:^(RTCIceServer *turnServer,
tkchin_webrtc 2016/03/08 19:51:21 This should still return an array.
hjon_webrtc 2016/03/10 03:32:43 Done.
233 NSError *error) { 237 NSError *error) {
234 if (error) { 238 if (error) {
235 RTCLogError("Error retrieving TURN servers: %@", 239 RTCLogError("Error retrieving TURN servers: %@",
236 error.localizedDescription); 240 error.localizedDescription);
237 } 241 }
238 ARDAppClient *strongSelf = weakSelf; 242 ARDAppClient *strongSelf = weakSelf;
239 [strongSelf.iceServers addObjectsFromArray:turnServers]; 243 [strongSelf.iceServers addObject:turnServer];
240 strongSelf.isTurnComplete = YES; 244 strongSelf.isTurnComplete = YES;
241 [strongSelf startSignalingIfReady]; 245 [strongSelf startSignalingIfReady];
242 }]; 246 }];
243 247
244 // Join room on room server. 248 // Join room on room server.
245 [_roomServerClient joinRoomWithRoomId:roomId 249 [_roomServerClient joinRoomWithRoomId:roomId
246 isLoopback:isLoopback 250 isLoopback:isLoopback
247 completionHandler:^(ARDJoinResponse *response, NSError *error) { 251 completionHandler:^(ARDJoinResponse *response, NSError *error) {
248 ARDAppClient *strongSelf = weakSelf; 252 ARDAppClient *strongSelf = weakSelf;
249 if (error) { 253 if (error) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 [self disconnect]; 349 [self disconnect];
346 break; 350 break;
347 } 351 }
348 } 352 }
349 353
350 #pragma mark - RTCPeerConnectionDelegate 354 #pragma mark - RTCPeerConnectionDelegate
351 // Callbacks for this delegate occur on non-main thread and need to be 355 // Callbacks for this delegate occur on non-main thread and need to be
352 // dispatched back to main queue as needed. 356 // dispatched back to main queue as needed.
353 357
354 - (void)peerConnection:(RTCPeerConnection *)peerConnection 358 - (void)peerConnection:(RTCPeerConnection *)peerConnection
355 signalingStateChanged:(RTCSignalingState)stateChanged { 359 didChangeSignalingState:(RTCSignalingState)stateChanged {
356 RTCLog(@"Signaling state changed: %d", stateChanged); 360 RTCLog(@"Signaling state changed: %d", stateChanged);
357 } 361 }
358 362
359 - (void)peerConnection:(RTCPeerConnection *)peerConnection 363 - (void)peerConnection:(RTCPeerConnection *)peerConnection
360 addedStream:(RTCMediaStream *)stream { 364 didAddStream:(RTCMediaStream *)stream {
361 dispatch_async(dispatch_get_main_queue(), ^{ 365 dispatch_async(dispatch_get_main_queue(), ^{
362 RTCLog(@"Received %lu video tracks and %lu audio tracks", 366 RTCLog(@"Received %lu video tracks and %lu audio tracks",
363 (unsigned long)stream.videoTracks.count, 367 (unsigned long)stream.videoTracks.count,
364 (unsigned long)stream.audioTracks.count); 368 (unsigned long)stream.audioTracks.count);
365 if (stream.videoTracks.count) { 369 if (stream.videoTracks.count) {
366 RTCVideoTrack *videoTrack = stream.videoTracks[0]; 370 RTCVideoTrack *videoTrack = stream.videoTracks[0];
367 [_delegate appClient:self didReceiveRemoteVideoTrack:videoTrack]; 371 [_delegate appClient:self didReceiveRemoteVideoTrack:videoTrack];
368 } 372 }
369 }); 373 });
370 } 374 }
371 375
372 - (void)peerConnection:(RTCPeerConnection *)peerConnection 376 - (void)peerConnection:(RTCPeerConnection *)peerConnection
373 removedStream:(RTCMediaStream *)stream { 377 didRemoveStream:(RTCMediaStream *)stream {
374 RTCLog(@"Stream was removed."); 378 RTCLog(@"Stream was removed.");
375 } 379 }
376 380
377 - (void)peerConnectionOnRenegotiationNeeded: 381 - (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection {
378 (RTCPeerConnection *)peerConnection {
379 RTCLog(@"WARNING: Renegotiation needed but unimplemented."); 382 RTCLog(@"WARNING: Renegotiation needed but unimplemented.");
380 } 383 }
381 384
382 - (void)peerConnection:(RTCPeerConnection *)peerConnection 385 - (void)peerConnection:(RTCPeerConnection *)peerConnection
383 iceConnectionChanged:(RTCICEConnectionState)newState { 386 didChangeIceConnectionState:(RTCIceConnectionState)newState {
384 RTCLog(@"ICE state changed: %d", newState); 387 RTCLog(@"ICE state changed: %d", newState);
385 dispatch_async(dispatch_get_main_queue(), ^{ 388 dispatch_async(dispatch_get_main_queue(), ^{
386 [_delegate appClient:self didChangeConnectionState:newState]; 389 [_delegate appClient:self didChangeConnectionState:newState];
387 }); 390 });
388 } 391 }
389 392
390 - (void)peerConnection:(RTCPeerConnection *)peerConnection 393 - (void)peerConnection:(RTCPeerConnection *)peerConnection
391 iceGatheringChanged:(RTCICEGatheringState)newState { 394 didChangeIceGatheringState:(RTCIceGatheringState)newState {
392 RTCLog(@"ICE gathering state changed: %d", newState); 395 RTCLog(@"ICE gathering state changed: %d", newState);
393 } 396 }
394 397
395 - (void)peerConnection:(RTCPeerConnection *)peerConnection 398 - (void)peerConnection:(RTCPeerConnection *)peerConnection
396 gotICECandidate:(RTCICECandidate *)candidate { 399 didGenerateIceCandidate:(RTCIceCandidate *)candidate {
397 dispatch_async(dispatch_get_main_queue(), ^{ 400 dispatch_async(dispatch_get_main_queue(), ^{
398 ARDICECandidateMessage *message = 401 ARDICECandidateMessage *message =
399 [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; 402 [[ARDICECandidateMessage alloc] initWithCandidate:candidate];
400 [self sendSignalingMessage:message]; 403 [self sendSignalingMessage:message];
401 }); 404 });
402 } 405 }
403 406
404 - (void)peerConnection:(RTCPeerConnection *)peerConnection 407 - (void)peerConnection:(RTCPeerConnection *)peerConnection
405 didOpenDataChannel:(RTCDataChannel *)dataChannel { 408 didOpenDataChannel:(RTCDataChannel *)dataChannel {
406 } 409 }
407 410
408 #pragma mark - RTCStatsDelegate
409
410 - (void)peerConnection:(RTCPeerConnection *)peerConnection
411 didGetStats:(NSArray *)stats {
412 dispatch_async(dispatch_get_main_queue(), ^{
413 [_delegate appClient:self didGetStats:stats];
414 });
415 }
416
417 #pragma mark - RTCSessionDescriptionDelegate 411 #pragma mark - RTCSessionDescriptionDelegate
418 // Callbacks for this delegate occur on non-main thread and need to be 412 // Callbacks for this delegate occur on non-main thread and need to be
419 // dispatched back to main queue as needed. 413 // dispatched back to main queue as needed.
420 414
421 - (void)peerConnection:(RTCPeerConnection *)peerConnection 415 - (void)peerConnection:(RTCPeerConnection *)peerConnection
422 didCreateSessionDescription:(RTCSessionDescription *)sdp 416 didCreateSessionDescription:(RTCSessionDescription *)sdp
423 error:(NSError *)error { 417 error:(NSError *)error {
424 dispatch_async(dispatch_get_main_queue(), ^{ 418 dispatch_async(dispatch_get_main_queue(), ^{
425 if (error) { 419 if (error) {
426 RTCLogError(@"Failed to create session description. Error: %@", error); 420 RTCLogError(@"Failed to create session description. Error: %@", error);
427 [self disconnect]; 421 [self disconnect];
428 NSDictionary *userInfo = @{ 422 NSDictionary *userInfo = @{
429 NSLocalizedDescriptionKey: @"Failed to create session description.", 423 NSLocalizedDescriptionKey: @"Failed to create session description.",
430 }; 424 };
431 NSError *sdpError = 425 NSError *sdpError =
432 [[NSError alloc] initWithDomain:kARDAppClientErrorDomain 426 [[NSError alloc] initWithDomain:kARDAppClientErrorDomain
433 code:kARDAppClientErrorCreateSDP 427 code:kARDAppClientErrorCreateSDP
434 userInfo:userInfo]; 428 userInfo:userInfo];
435 [_delegate appClient:self didError:sdpError]; 429 [_delegate appClient:self didError:sdpError];
436 return; 430 return;
437 } 431 }
438 // Prefer H264 if available. 432 // Prefer H264 if available.
439 RTCSessionDescription *sdpPreferringH264 = 433 RTCSessionDescription *sdpPreferringH264 =
440 [ARDSDPUtils descriptionForDescription:sdp 434 [ARDSDPUtils descriptionForDescription:sdp
441 preferredVideoCodec:@"H264"]; 435 preferredVideoCodec:@"H264"];
442 [_peerConnection setLocalDescriptionWithDelegate:self 436 __weak ARDAppClient *weakSelf = self;
443 sessionDescription:sdpPreferringH264]; 437 [_peerConnection setLocalDescription:sdpPreferringH264
438 completionHandler:^(NSError *error) {
439 ARDAppClient *strongSelf = weakSelf;
440 [strongSelf peerConnection:strongSelf.peerConnection
441 didSetSessionDescriptionWithError:error];
442 }];
444 ARDSessionDescriptionMessage *message = 443 ARDSessionDescriptionMessage *message =
445 [[ARDSessionDescriptionMessage alloc] 444 [[ARDSessionDescriptionMessage alloc]
446 initWithDescription:sdpPreferringH264]; 445 initWithDescription:sdpPreferringH264];
447 [self sendSignalingMessage:message]; 446 [self sendSignalingMessage:message];
448 }); 447 });
449 } 448 }
450 449
451 - (void)peerConnection:(RTCPeerConnection *)peerConnection 450 - (void)peerConnection:(RTCPeerConnection *)peerConnection
452 didSetSessionDescriptionWithError:(NSError *)error { 451 didSetSessionDescriptionWithError:(NSError *)error {
453 dispatch_async(dispatch_get_main_queue(), ^{ 452 dispatch_async(dispatch_get_main_queue(), ^{
454 if (error) { 453 if (error) {
455 RTCLogError(@"Failed to set session description. Error: %@", error); 454 RTCLogError(@"Failed to set session description. Error: %@", error);
456 [self disconnect]; 455 [self disconnect];
457 NSDictionary *userInfo = @{ 456 NSDictionary *userInfo = @{
458 NSLocalizedDescriptionKey: @"Failed to set session description.", 457 NSLocalizedDescriptionKey: @"Failed to set session description.",
459 }; 458 };
460 NSError *sdpError = 459 NSError *sdpError =
461 [[NSError alloc] initWithDomain:kARDAppClientErrorDomain 460 [[NSError alloc] initWithDomain:kARDAppClientErrorDomain
462 code:kARDAppClientErrorSetSDP 461 code:kARDAppClientErrorSetSDP
463 userInfo:userInfo]; 462 userInfo:userInfo];
464 [_delegate appClient:self didError:sdpError]; 463 [_delegate appClient:self didError:sdpError];
465 return; 464 return;
466 } 465 }
467 // If we're answering and we've just set the remote offer we need to create 466 // If we're answering and we've just set the remote offer we need to create
468 // an answer and set the local description. 467 // an answer and set the local description.
469 if (!_isInitiator && !_peerConnection.localDescription) { 468 if (!_isInitiator && !_peerConnection.localDescription) {
470 RTCMediaConstraints *constraints = [self defaultAnswerConstraints]; 469 RTCMediaConstraints *constraints = [self defaultAnswerConstraints];
471 [_peerConnection createAnswerWithDelegate:self 470 __weak ARDAppClient *weakSelf = self;
472 constraints:constraints]; 471 [_peerConnection answerForConstraints:constraints
473 472 completionHandler:^(RTCSessionDescription *sdp,
473 NSError *error) {
474 ARDAppClient *strongSelf = weakSelf;
475 [strongSelf peerConnection:strongSelf.peerConnection
476 didCreateSessionDescription:sdp
tkchin_webrtc 2016/03/08 19:51:21 indent (move this line 5 spaces to the right, and
hjon_webrtc 2016/03/10 03:32:43 Done.
477 error:error];
478 }];
474 } 479 }
475 }); 480 });
476 } 481 }
477 482
478 #pragma mark - Private 483 #pragma mark - Private
479 484
480 - (BOOL)hasJoinedRoomServerRoom { 485 - (BOOL)hasJoinedRoomServerRoom {
481 return _clientId.length; 486 return _clientId.length;
482 } 487 }
483 488
484 // Begins the peer connection connection process if we have both joined a room 489 // Begins the peer connection connection process if we have both joined a room
485 // on the room server and tried to obtain a TURN server. Otherwise does nothing. 490 // on the room server and tried to obtain a TURN server. Otherwise does nothing.
486 // A peer connection object will be created with a stream that contains local 491 // A peer connection object will be created with a stream that contains local
487 // audio and video capture. If this client is the caller, an offer is created as 492 // audio and video capture. If this client is the caller, an offer is created as
488 // well, otherwise the client will wait for an offer to arrive. 493 // well, otherwise the client will wait for an offer to arrive.
489 - (void)startSignalingIfReady { 494 - (void)startSignalingIfReady {
490 if (!_isTurnComplete || !self.hasJoinedRoomServerRoom) { 495 if (!_isTurnComplete || !self.hasJoinedRoomServerRoom) {
491 return; 496 return;
492 } 497 }
493 self.state = kARDAppClientStateConnected; 498 self.state = kARDAppClientStateConnected;
494 499
495 // Create peer connection. 500 // Create peer connection.
496 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; 501 RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints];
497 RTCConfiguration *config = [[RTCConfiguration alloc] init]; 502 RTCConfiguration *config = [[RTCConfiguration alloc] init];
498 config.iceServers = _iceServers; 503 config.iceServers = _iceServers;
499 _peerConnection = [_factory peerConnectionWithConfiguration:config 504 _peerConnection = [[RTCPeerConnection alloc] initWithFactory:_factory
500 constraints:constraints 505 configuration:config
501 delegate:self]; 506 constraints:constraints
507 delegate:self];
502 // Create AV media stream and add it to the peer connection. 508 // Create AV media stream and add it to the peer connection.
503 RTCMediaStream *localStream = [self createLocalMediaStream]; 509 RTCMediaStream *localStream = [self createLocalMediaStream];
504 [_peerConnection addStream:localStream]; 510 [_peerConnection addStream:localStream];
505 if (_isInitiator) { 511 if (_isInitiator) {
506 // Send offer. 512 // Send offer.
507 [_peerConnection createOfferWithDelegate:self 513 __weak ARDAppClient *weakSelf = self;
508 constraints:[self defaultOfferConstraints]]; 514 [_peerConnection offerForConstraints:[self defaultOfferConstraints]
515 completionHandler:^(RTCSessionDescription *sdp,
516 NSError *error) {
517 ARDAppClient *strongSelf = weakSelf;
518 [strongSelf peerConnection:strongSelf.peerConnection
519 didCreateSessionDescription:sdp
tkchin_webrtc 2016/03/08 19:51:21 ditto indent
hjon_webrtc 2016/03/10 03:32:43 Done.
520 error:error];
521 }];
509 } else { 522 } else {
510 // Check if we've received an offer. 523 // Check if we've received an offer.
511 [self drainMessageQueueIfReady]; 524 [self drainMessageQueueIfReady];
512 } 525 }
513 } 526 }
514 527
515 // Processes the messages that we've received from the room server and the 528 // Processes the messages that we've received from the room server and the
516 // signaling channel. The offer or answer message must be processed before other 529 // signaling channel. The offer or answer message must be processed before other
517 // signaling messages, however they can arrive out of order. Hence, this method 530 // signaling messages, however they can arrive out of order. Hence, this method
518 // only processes pending messages if there is a peer connection object and 531 // only processes pending messages if there is a peer connection object and
(...skipping 15 matching lines...) Expand all
534 switch (message.type) { 547 switch (message.type) {
535 case kARDSignalingMessageTypeOffer: 548 case kARDSignalingMessageTypeOffer:
536 case kARDSignalingMessageTypeAnswer: { 549 case kARDSignalingMessageTypeAnswer: {
537 ARDSessionDescriptionMessage *sdpMessage = 550 ARDSessionDescriptionMessage *sdpMessage =
538 (ARDSessionDescriptionMessage *)message; 551 (ARDSessionDescriptionMessage *)message;
539 RTCSessionDescription *description = sdpMessage.sessionDescription; 552 RTCSessionDescription *description = sdpMessage.sessionDescription;
540 // Prefer H264 if available. 553 // Prefer H264 if available.
541 RTCSessionDescription *sdpPreferringH264 = 554 RTCSessionDescription *sdpPreferringH264 =
542 [ARDSDPUtils descriptionForDescription:description 555 [ARDSDPUtils descriptionForDescription:description
543 preferredVideoCodec:@"H264"]; 556 preferredVideoCodec:@"H264"];
544 [_peerConnection setRemoteDescriptionWithDelegate:self 557 __weak ARDAppClient *weakSelf = self;
545 sessionDescription:sdpPreferringH264]; 558 [_peerConnection setRemoteDescription:sdpPreferringH264
559 completionHandler:^(NSError *error) {
560 ARDAppClient *strongSelf = weakSelf;
561 [strongSelf peerConnection:strongSelf.peerConnection
562 didSetSessionDescriptionWithError:error];
tkchin_webrtc 2016/03/08 19:51:21 indent
hjon_webrtc 2016/03/10 03:32:43 Done.
563 }];
546 break; 564 break;
547 } 565 }
548 case kARDSignalingMessageTypeCandidate: { 566 case kARDSignalingMessageTypeCandidate: {
549 ARDICECandidateMessage *candidateMessage = 567 ARDICECandidateMessage *candidateMessage =
550 (ARDICECandidateMessage *)message; 568 (ARDICECandidateMessage *)message;
551 [_peerConnection addICECandidate:candidateMessage.candidate]; 569 [_peerConnection addIceCandidate:candidateMessage.candidate];
552 break; 570 break;
553 } 571 }
554 case kARDSignalingMessageTypeBye: 572 case kARDSignalingMessageTypeBye:
555 // Other client disconnected. 573 // Other client disconnected.
556 // TODO(tkchin): support waiting in room for next client. For now just 574 // TODO(tkchin): support waiting in room for next client. For now just
557 // disconnect. 575 // disconnect.
558 [self disconnect]; 576 [self disconnect];
559 break; 577 break;
560 } 578 }
561 } 579 }
(...skipping 20 matching lines...) Expand all
582 [strongSelf.delegate appClient:strongSelf didError:messageError]; 600 [strongSelf.delegate appClient:strongSelf didError:messageError];
583 return; 601 return;
584 } 602 }
585 }]; 603 }];
586 } else { 604 } else {
587 [_channel sendMessage:message]; 605 [_channel sendMessage:message];
588 } 606 }
589 } 607 }
590 608
591 - (RTCMediaStream *)createLocalMediaStream { 609 - (RTCMediaStream *)createLocalMediaStream {
592 RTCMediaStream* localStream = [_factory mediaStreamWithLabel:@"ARDAMS"]; 610 RTCMediaStream *localStream =
593 RTCVideoTrack* localVideoTrack = [self createLocalVideoTrack]; 611 [[RTCMediaStream alloc] initWithFactory:_factory streamId:@"ARDAMS"];
612 RTCVideoTrack *localVideoTrack = [self createLocalVideoTrack];
594 if (localVideoTrack) { 613 if (localVideoTrack) {
595 [localStream addVideoTrack:localVideoTrack]; 614 [localStream addVideoTrack:localVideoTrack];
596 [_delegate appClient:self didReceiveLocalVideoTrack:localVideoTrack]; 615 [_delegate appClient:self didReceiveLocalVideoTrack:localVideoTrack];
597 } 616 }
598 [localStream addAudioTrack:[_factory audioTrackWithID:@"ARDAMSa0"]]; 617 RTCAudioTrack *localAudioTrack =
618 [[RTCAudioTrack alloc] initWithFactory:_factory
619 trackId:@"ARDAMSa0"];
620 [localStream addAudioTrack:localAudioTrack];
599 return localStream; 621 return localStream;
600 } 622 }
601 623
602 - (RTCVideoTrack *)createLocalVideoTrack { 624 - (RTCVideoTrack *)createLocalVideoTrack {
603 RTCVideoTrack* localVideoTrack = nil; 625 RTCVideoTrack* localVideoTrack = nil;
604 // The iOS simulator doesn't provide any sort of camera capture 626 // The iOS simulator doesn't provide any sort of camera capture
605 // support or emulation (http://goo.gl/rHAnC1) so don't bother 627 // support or emulation (http://goo.gl/rHAnC1) so don't bother
606 // trying to open a local stream. 628 // trying to open a local stream.
607 // TODO(tkchin): local video capture for OSX. See 629 // TODO(tkchin): local video capture for OSX. See
608 // https://code.google.com/p/webrtc/issues/detail?id=3417. 630 // https://code.google.com/p/webrtc/issues/detail?id=3417.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 initWithMandatoryConstraints:nil 676 initWithMandatoryConstraints:nil
655 optionalConstraints:nil]; 677 optionalConstraints:nil];
656 return constraints; 678 return constraints;
657 } 679 }
658 680
659 - (RTCMediaConstraints *)defaultAnswerConstraints { 681 - (RTCMediaConstraints *)defaultAnswerConstraints {
660 return [self defaultOfferConstraints]; 682 return [self defaultOfferConstraints];
661 } 683 }
662 684
663 - (RTCMediaConstraints *)defaultOfferConstraints { 685 - (RTCMediaConstraints *)defaultOfferConstraints {
664 NSArray *mandatoryConstraints = @[ 686 NSDictionary *mandatoryConstraints = @{
665 [[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"], 687 @"OfferToReceiveAudio" : @"true",
tkchin_webrtc 2016/03/08 19:51:21 indent 2 instead of 4: = @{ @"Offer..." };
hjon_webrtc 2016/03/10 03:32:43 Done.
666 [[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"] 688 @"OfferToReceiveVideo" : @"true"
667 ]; 689 };
668 RTCMediaConstraints* constraints = 690 RTCMediaConstraints* constraints =
669 [[RTCMediaConstraints alloc] 691 [[RTCMediaConstraints alloc]
670 initWithMandatoryConstraints:mandatoryConstraints 692 initWithMandatoryConstraints:mandatoryConstraints
671 optionalConstraints:nil]; 693 optionalConstraints:nil];
672 return constraints; 694 return constraints;
673 } 695 }
674 696
675 - (RTCMediaConstraints *)defaultPeerConnectionConstraints { 697 - (RTCMediaConstraints *)defaultPeerConnectionConstraints {
676 if (_defaultPeerConnectionConstraints) { 698 if (_defaultPeerConnectionConstraints) {
677 return _defaultPeerConnectionConstraints; 699 return _defaultPeerConnectionConstraints;
678 } 700 }
679 NSString *value = _isLoopback ? @"false" : @"true"; 701 NSString *value = _isLoopback ? @"false" : @"true";
680 NSArray *optionalConstraints = @[ 702 NSDictionary *optionalConstraints = @{ @"DtlsSrtpKeyAgreement" : value };
681 [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:value]
682 ];
683 RTCMediaConstraints* constraints = 703 RTCMediaConstraints* constraints =
684 [[RTCMediaConstraints alloc] 704 [[RTCMediaConstraints alloc]
685 initWithMandatoryConstraints:nil 705 initWithMandatoryConstraints:nil
686 optionalConstraints:optionalConstraints]; 706 optionalConstraints:optionalConstraints];
687 return constraints; 707 return constraints;
688 } 708 }
689 709
690 - (RTCICEServer *)defaultSTUNServer { 710 - (RTCIceServer *)defaultSTUNServer {
691 NSURL *defaultSTUNServerURL = [NSURL URLWithString:kARDDefaultSTUNServerUrl]; 711 return [[RTCIceServer alloc] initWithURLStrings:@[kARDDefaultSTUNServerUrl]
692 return [[RTCICEServer alloc] initWithURI:defaultSTUNServerURL 712 username:@""
693 username:@"" 713 credential:@""];
694 password:@""];
695 } 714 }
696 715
697 #pragma mark - Errors 716 #pragma mark - Errors
698 717
699 + (NSError *)errorForJoinResultType:(ARDJoinResultType)resultType { 718 + (NSError *)errorForJoinResultType:(ARDJoinResultType)resultType {
700 NSError *error = nil; 719 NSError *error = nil;
701 switch (resultType) { 720 switch (resultType) {
702 case kARDJoinResultTypeSuccess: 721 case kARDJoinResultTypeSuccess:
703 break; 722 break;
704 case kARDJoinResultTypeUnknown: { 723 case kARDJoinResultTypeUnknown: {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 code:kARDAppClientErrorInvalidRoom 764 code:kARDAppClientErrorInvalidRoom
746 userInfo:@{ 765 userInfo:@{
747 NSLocalizedDescriptionKey: @"Invalid room.", 766 NSLocalizedDescriptionKey: @"Invalid room.",
748 }]; 767 }];
749 break; 768 break;
750 } 769 }
751 return error; 770 return error;
752 } 771 }
753 772
754 @end 773 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698