From 82387e4608ade44546e4a64b61d40de079aa6ed0 Mon Sep 17 00:00:00 2001 From: "fischman@webrtc.org" Date: Mon, 10 Feb 2014 18:47:11 +0000 Subject: [PATCH] Add ability to receive calls for iOS BUG=2701 R=fischman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/7989005 Patch from Sajid Hussain . git-svn-id: http://webrtc.googlecode.com/svn/trunk@5518 4adac7df-926f-26a2-2b94-8c16560cd09d --- AUTHORS | 1 + .../examples/ios/AppRTCDemo/APPRTCAppClient.h | 1 + .../examples/ios/AppRTCDemo/APPRTCAppClient.m | 2 ++ .../ios/AppRTCDemo/APPRTCAppDelegate.m | 36 ++++++++++++++++--- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index f92a9bf592..4d7ba0563f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -20,3 +20,4 @@ MIPS Technologies Mozilla Foundation Opera Software ASA Vonage Holdings Corp. +Temasys Communications diff --git a/talk/examples/ios/AppRTCDemo/APPRTCAppClient.h b/talk/examples/ios/AppRTCDemo/APPRTCAppClient.h index c737beaa99..608ed05051 100644 --- a/talk/examples/ios/AppRTCDemo/APPRTCAppClient.h +++ b/talk/examples/ios/AppRTCDemo/APPRTCAppClient.h @@ -47,6 +47,7 @@ @property(nonatomic, assign) id ICEServerDelegate; @property(nonatomic, assign) id messageHandler; +@property(nonatomic, assign) BOOL initiator; - (void)connectToRoom:(NSURL *)room; - (void)sendData:(NSData *)data; diff --git a/talk/examples/ios/AppRTCDemo/APPRTCAppClient.m b/talk/examples/ios/AppRTCDemo/APPRTCAppClient.m index d6c86d8422..c01ee2507b 100644 --- a/talk/examples/ios/AppRTCDemo/APPRTCAppClient.m +++ b/talk/examples/ios/AppRTCDemo/APPRTCAppClient.m @@ -61,6 +61,7 @@ @synthesize sendQueue = _sendQueue; @synthesize token = _token; @synthesize verboseLogging = _verboseLogging; +@synthesize initiator = _initiator; - (id)init { if (self = [super init]) { @@ -272,6 +273,7 @@ [self maybeLogMessage: [NSString stringWithFormat:@"Base URL: %@", self.baseURL]]; + self.initiator = [[self findVar:@"initiator" strippingQuotes:NO] boolValue]; self.token = [self findVar:@"channelToken" strippingQuotes:YES]; if (!self.token) return; diff --git a/talk/examples/ios/AppRTCDemo/APPRTCAppDelegate.m b/talk/examples/ios/AppRTCDemo/APPRTCAppDelegate.m index 65cdd09794..9b8c96d5f2 100644 --- a/talk/examples/ios/AppRTCDemo/APPRTCAppDelegate.m +++ b/talk/examples/ios/AppRTCDemo/APPRTCAppDelegate.m @@ -229,6 +229,10 @@ #pragma mark - GAEMessageHandler methods - (void)onOpen { + if (!self.client.initiator) { + [self displayLogMessage:@"Callee; waiting for remote offer"]; + return; + } [self displayLogMessage:@"GAE onOpen - create offer."]; RTCPair *audio = [[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"]; @@ -400,10 +404,34 @@ [self displayLogMessage:@"SDP onSuccess() - possibly drain candidates"]; dispatch_async(dispatch_get_main_queue(), ^(void) { - // TODO(hughv): Handle non-initiator case. http://s10/46622051 - if (self.peerConnection.remoteDescription) { - [self displayLogMessage:@"SDP onSuccess - drain candidates"]; - [self drainRemoteCandidates]; + if (!self.client.initiator) { + if (self.peerConnection.remoteDescription + && !self.peerConnection.localDescription) { + [self displayLogMessage:@"Callee, setRemoteDescription succeeded"]; + RTCPair *audio = + [[RTCPair alloc] + initWithKey:@"OfferToReceiveAudio" value:@"true"]; + // TODO(hughv): Add video. + // RTCPair *video = + // [[RTCPair alloc] + // initWithKey:@"OfferToReceiveVideo" value:@"true"]; + NSArray *mandatory = @[ audio /*, video*/ ]; + RTCMediaConstraints *constraints = + [[RTCMediaConstraints alloc] + initWithMandatoryConstraints:mandatory + optionalConstraints:nil]; + [self.peerConnection + createAnswerWithDelegate:self constraints:constraints]; + [self displayLogMessage:@"PC - createAnswer."]; + } else { + [self displayLogMessage:@"SDP onSuccess - drain candidates"]; + [self drainRemoteCandidates]; + } + } else { + if (self.peerConnection.remoteDescription) { + [self displayLogMessage:@"SDP onSuccess - drain candidates"]; + [self drainRemoteCandidates]; + } } }); }