Implement mac version of AppRTCDemo.
- Refactored and moved AppRTCDemo to support sharing AppRTC connection code between iOS and mac counterparts.
- Refactored OpenGL rendering code to be shared between iOS and mac counterparts.
- iOS AppRTCDemo now respects video aspect ratio.
BUG=2168
R=fischman@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/17589004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@6291 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/examples/objc/AppRTCDemo/APPRTCAppClient.h b/talk/examples/objc/AppRTCDemo/APPRTCAppClient.h
new file mode 100644
index 0000000..b69b517
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/APPRTCAppClient.h
@@ -0,0 +1,68 @@
+/*
+ * libjingle
+ * Copyright 2013, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+
+#import "GAEChannelClient.h"
+
+@class APPRTCAppClient;
+@protocol APPRTCAppClientDelegate
+
+- (void)appClient:(APPRTCAppClient*)appClient
+ didErrorWithMessage:(NSString*)message;
+- (void)appClient:(APPRTCAppClient*)appClient
+ didReceiveICEServers:(NSArray*)servers;
+
+@end
+
+@class RTCMediaConstraints;
+
+// Negotiates signaling for chatting with apprtc.appspot.com "rooms".
+// Uses the client<->server specifics of the apprtc AppEngine webapp.
+//
+// To use: create an instance of this object (registering a message handler) and
+// call connectToRoom(). apprtc.appspot.com will signal that is successful via
+// onOpen through the browser channel. Then you should call sendData() and wait
+// for the registered handler to be called with received messages.
+@interface APPRTCAppClient : NSObject<NSURLConnectionDataDelegate>
+
+@property(nonatomic) BOOL initiator;
+@property(nonatomic, copy, readonly) RTCMediaConstraints* videoConstraints;
+@property(nonatomic, weak) id<APPRTCAppClientDelegate> delegate;
+
+- (id)initWithDelegate:(id<APPRTCAppClientDelegate>)delegate
+ messageHandler:(id<GAEMessageHandler>)handler;
+- (void)connectToRoom:(NSURL*)room;
+- (void)sendData:(NSData*)data;
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+// Disallow init and don't add to documentation
+- (id)init __attribute__((
+ unavailable("init is not a supported initializer for this class.")));
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/APPRTCAppClient.m b/talk/examples/objc/AppRTCDemo/APPRTCAppClient.m
new file mode 100644
index 0000000..c412aef
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/APPRTCAppClient.m
@@ -0,0 +1,353 @@
+/*
+ * libjingle
+ * Copyright 2013, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+#import "APPRTCAppClient.h"
+
+#import <dispatch/dispatch.h>
+
+#import "GAEChannelClient.h"
+#import "RTCICEServer.h"
+#import "RTCMediaConstraints.h"
+#import "RTCPair.h"
+
+@interface APPRTCAppClient ()
+
+@property(nonatomic, weak, readonly) id<GAEMessageHandler> messageHandler;
+@property(nonatomic, copy) NSString* baseURL;
+@property(nonatomic, strong) GAEChannelClient* gaeChannel;
+@property(nonatomic, copy) NSString* postMessageUrl;
+@property(nonatomic, copy) NSString* pcConfig;
+@property(nonatomic, strong) NSMutableString* roomHtml;
+@property(atomic, strong) NSMutableArray* sendQueue;
+@property(nonatomic, copy) NSString* token;
+
+@property(nonatomic, assign) BOOL verboseLogging;
+
+@end
+
+@implementation APPRTCAppClient {
+ dispatch_queue_t _backgroundQueue;
+}
+
+- (id)initWithDelegate:(id<APPRTCAppClientDelegate>)delegate
+ messageHandler:(id<GAEMessageHandler>)handler {
+ if (self = [super init]) {
+ _delegate = delegate;
+ _messageHandler = handler;
+ _backgroundQueue = dispatch_queue_create("RTCBackgroundQueue",
+ DISPATCH_QUEUE_SERIAL);
+ _sendQueue = [NSMutableArray array];
+ // Uncomment to see Request/Response logging.
+ // _verboseLogging = YES;
+ }
+ return self;
+}
+
+#pragma mark - Public methods
+
+- (void)connectToRoom:(NSURL*)url {
+ self.roomHtml = [NSMutableString stringWithCapacity:20000];
+ NSURLRequest* request = [NSURLRequest requestWithURL:url];
+ [NSURLConnection connectionWithRequest:request delegate:self];
+}
+
+- (void)sendData:(NSData*)data {
+ [self maybeLogMessage:@"Send message"];
+
+ dispatch_async(_backgroundQueue, ^{
+ [self.sendQueue addObject:[data copy]];
+
+ if ([self.postMessageUrl length] < 1) {
+ return;
+ }
+ for (NSData* data in self.sendQueue) {
+ NSString* url =
+ [NSString stringWithFormat:@"%@/%@",
+ self.baseURL, self.postMessageUrl];
+ [self sendData:data withUrl:url];
+ }
+ [self.sendQueue removeAllObjects];
+ });
+}
+
+#pragma mark - Internal methods
+
+- (NSString*)findVar:(NSString*)name strippingQuotes:(BOOL)strippingQuotes {
+ NSError* error;
+ NSString* pattern =
+ [NSString stringWithFormat:@".*\n *var %@ = ([^\n]*);\n.*", name];
+ NSRegularExpression* regexp =
+ [NSRegularExpression regularExpressionWithPattern:pattern
+ options:0
+ error:&error];
+ NSAssert(!error,
+ @"Unexpected error compiling regex: ",
+ error.localizedDescription);
+
+ NSRange fullRange = NSMakeRange(0, [self.roomHtml length]);
+ NSArray* matches =
+ [regexp matchesInString:self.roomHtml options:0 range:fullRange];
+ if ([matches count] != 1) {
+ NSString* format = @"%lu matches for %@ in %@";
+ NSString* message = [NSString stringWithFormat:format,
+ (unsigned long)[matches count], name, self.roomHtml];
+ [self.delegate appClient:self didErrorWithMessage:message];
+ return nil;
+ }
+ NSRange matchRange = [matches[0] rangeAtIndex:1];
+ NSString* value = [self.roomHtml substringWithRange:matchRange];
+ if (strippingQuotes) {
+ NSAssert([value length] > 2,
+ @"Can't strip quotes from short string: [%@]",
+ value);
+ NSAssert(([value characterAtIndex:0] == '\'' &&
+ [value characterAtIndex:[value length] - 1] == '\''),
+ @"Can't strip quotes from unquoted string: [%@]",
+ value);
+ value = [value substringWithRange:NSMakeRange(1, [value length] - 2)];
+ }
+ return value;
+}
+
+- (void)maybeLogMessage:(NSString*)message {
+ if (self.verboseLogging) {
+ NSLog(@"%@", message);
+ }
+}
+
+- (void)sendData:(NSData*)data withUrl:(NSString*)url {
+ NSMutableURLRequest* request =
+ [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
+ request.HTTPMethod = @"POST";
+ [request setHTTPBody:data];
+ NSURLResponse* response;
+ NSError* error;
+ NSData* responseData = [NSURLConnection sendSynchronousRequest:request
+ returningResponse:&response
+ error:&error];
+ NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
+ int status = [httpResponse statusCode];
+ NSAssert(status == 200,
+ @"Bad response [%d] to message: %@\n\n%@",
+ status,
+ [NSString stringWithUTF8String:[data bytes]],
+ [NSString stringWithUTF8String:[responseData bytes]]);
+}
+
+- (void)updateICEServers:(NSMutableArray*)ICEServers
+ withTurnServer:(NSString*)turnServerUrl {
+ if ([turnServerUrl length] < 1) {
+ [self.delegate appClient:self didReceiveICEServers:ICEServers];
+ return;
+ }
+ dispatch_async(_backgroundQueue, ^(void) {
+ NSMutableURLRequest* request = [NSMutableURLRequest
+ requestWithURL:[NSURL URLWithString:turnServerUrl]];
+ [request addValue:@"Mozilla/5.0" forHTTPHeaderField:@"user-agent"];
+ [request addValue:@"https://apprtc.appspot.com"
+ forHTTPHeaderField:@"origin"];
+ NSURLResponse* response;
+ NSError* error;
+ NSData* responseData = [NSURLConnection sendSynchronousRequest:request
+ returningResponse:&response
+ error:&error];
+ if (!error) {
+ NSDictionary* json =
+ [NSJSONSerialization JSONObjectWithData:responseData
+ options:0
+ error:&error];
+ NSAssert(!error, @"Unable to parse. %@", error.localizedDescription);
+ NSString* username = json[@"username"];
+ NSString* password = json[@"password"];
+ NSArray* uris = json[@"uris"];
+ for (int i = 0; i < [uris count]; ++i) {
+ NSString* turnServer = [uris objectAtIndex:i];
+ RTCICEServer* ICEServer =
+ [[RTCICEServer alloc] initWithURI:[NSURL URLWithString:turnServer]
+ username:username
+ password:password];
+ NSLog(@"Added ICE Server: %@", ICEServer);
+ [ICEServers addObject:ICEServer];
+ }
+ } else {
+ NSLog(@"Unable to get TURN server. Error: %@", error.description);
+ }
+
+ dispatch_async(dispatch_get_main_queue(), ^(void) {
+ [self.delegate appClient:self didReceiveICEServers:ICEServers];
+ });
+ });
+}
+
+#pragma mark - NSURLConnectionDataDelegate methods
+
+- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {
+ NSString* roomHtml = [NSString stringWithUTF8String:[data bytes]];
+ NSString* message =
+ [NSString stringWithFormat:@"Received %lu chars",
+ (unsigned long)[roomHtml length]];
+ [self maybeLogMessage:message];
+ [self.roomHtml appendString:roomHtml];
+}
+
+- (void)connection:(NSURLConnection*)connection
+ didReceiveResponse:(NSURLResponse*)response {
+ NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
+ int statusCode = [httpResponse statusCode];
+ [self
+ maybeLogMessage:
+ [NSString stringWithFormat:
+ @"Response received\nURL\n%@\nStatus [%d]\nHeaders\n%@",
+ [httpResponse URL],
+ statusCode,
+ [httpResponse allHeaderFields]]];
+ NSAssert(statusCode == 200, @"Invalid response of %d received.", statusCode);
+}
+
+- (void)connectionDidFinishLoading:(NSURLConnection*)connection {
+ NSString* message =
+ [NSString stringWithFormat:@"finished loading %lu chars",
+ (unsigned long)[self.roomHtml length]];
+ [self maybeLogMessage:message];
+ NSRegularExpression* fullRegex =
+ [NSRegularExpression regularExpressionWithPattern:@"room is full"
+ options:0
+ error:nil];
+ if ([fullRegex
+ numberOfMatchesInString:self.roomHtml
+ options:0
+ range:NSMakeRange(0, [self.roomHtml length])]) {
+ NSString* message = @"Room full, dropping peerconnection.";
+ [self.delegate appClient:self didErrorWithMessage:message];
+ return;
+ }
+
+ NSString* fullUrl = [[[connection originalRequest] URL] absoluteString];
+ NSRange queryRange = [fullUrl rangeOfString:@"?"];
+ self.baseURL = [fullUrl substringToIndex:queryRange.location];
+ [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;
+ [self maybeLogMessage:[NSString stringWithFormat:@"Token: %@", self.token]];
+
+ NSString* roomKey = [self findVar:@"roomKey" strippingQuotes:YES];
+ NSString* me = [self findVar:@"me" strippingQuotes:YES];
+ if (!roomKey || !me)
+ return;
+ self.postMessageUrl =
+ [NSString stringWithFormat:@"/message?r=%@&u=%@", roomKey, me];
+ [self maybeLogMessage:[NSString stringWithFormat:@"POST message URL: %@",
+ self.postMessageUrl]];
+
+ NSString* pcConfig = [self findVar:@"pcConfig" strippingQuotes:NO];
+ if (!pcConfig)
+ return;
+ [self maybeLogMessage:[NSString
+ stringWithFormat:@"PC Config JSON: %@", pcConfig]];
+
+ NSString* turnServerUrl = [self findVar:@"turnUrl" strippingQuotes:YES];
+ if (turnServerUrl) {
+ [self maybeLogMessage:[NSString
+ stringWithFormat:@"TURN server request URL: %@",
+ turnServerUrl]];
+ }
+
+ NSError* error;
+ NSData* pcData = [pcConfig dataUsingEncoding:NSUTF8StringEncoding];
+ NSDictionary* json =
+ [NSJSONSerialization JSONObjectWithData:pcData options:0 error:&error];
+ NSAssert(!error, @"Unable to parse. %@", error.localizedDescription);
+ NSArray* servers = [json objectForKey:@"iceServers"];
+ NSMutableArray* ICEServers = [NSMutableArray array];
+ for (NSDictionary* server in servers) {
+ NSString* url = [server objectForKey:@"urls"];
+ NSString* username = json[@"username"];
+ NSString* credential = [server objectForKey:@"credential"];
+ if (!username) {
+ username = @"";
+ }
+ if (!credential) {
+ credential = @"";
+ }
+ [self maybeLogMessage:[NSString
+ stringWithFormat:@"url [%@] - credential [%@]",
+ url,
+ credential]];
+ RTCICEServer* ICEServer =
+ [[RTCICEServer alloc] initWithURI:[NSURL URLWithString:url]
+ username:username
+ password:credential];
+ NSLog(@"Added ICE Server: %@", ICEServer);
+ [ICEServers addObject:ICEServer];
+ }
+ [self updateICEServers:ICEServers withTurnServer:turnServerUrl];
+
+ NSString* mc = [self findVar:@"mediaConstraints" strippingQuotes:NO];
+ if (mc) {
+ error = nil;
+ NSData* mcData = [mc dataUsingEncoding:NSUTF8StringEncoding];
+ json =
+ [NSJSONSerialization JSONObjectWithData:mcData options:0 error:&error];
+ NSAssert(!error, @"Unable to parse. %@", error.localizedDescription);
+ id video = json[@"video"];
+ if ([video isKindOfClass:[NSDictionary class]]) {
+ NSDictionary* mandatory = video[@"mandatory"];
+ NSMutableArray* mandatoryContraints =
+ [NSMutableArray arrayWithCapacity:[mandatory count]];
+ [mandatory enumerateKeysAndObjectsUsingBlock:^(
+ id key, id obj, BOOL* stop) {
+ [mandatoryContraints addObject:[[RTCPair alloc] initWithKey:key
+ value:obj]];
+ }];
+ // TODO(tkchin): figure out json formats for optional constraints.
+ _videoConstraints =
+ [[RTCMediaConstraints alloc]
+ initWithMandatoryConstraints:mandatoryContraints
+ optionalConstraints:nil];
+ } else if ([video isKindOfClass:[NSNumber class]] && [video boolValue]) {
+ _videoConstraints = [[RTCMediaConstraints alloc] init];
+ }
+ }
+
+ [self
+ maybeLogMessage:[NSString
+ stringWithFormat:@"About to open GAE with token: %@",
+ self.token]];
+ self.gaeChannel =
+ [[GAEChannelClient alloc] initWithToken:self.token
+ delegate:self.messageHandler];
+}
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/APPRTCConnectionManager.h b/talk/examples/objc/AppRTCDemo/APPRTCConnectionManager.h
new file mode 100644
index 0000000..98fe755
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/APPRTCConnectionManager.h
@@ -0,0 +1,66 @@
+/*
+ * libjingle
+ * Copyright 2014, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+
+// Used to log messages to destination like UI.
+@protocol APPRTCLogger<NSObject>
+- (void)logMessage:(NSString*)message;
+@end
+
+@class RTCVideoTrack;
+@class APPRTCConnectionManager;
+
+// Used to provide AppRTC connection information.
+@protocol APPRTCConnectionManagerDelegate<NSObject>
+
+- (void)connectionManager:(APPRTCConnectionManager*)manager
+ didReceiveLocalVideoTrack:(RTCVideoTrack*)localVideoTrack;
+
+- (void)connectionManager:(APPRTCConnectionManager*)manager
+ didReceiveRemoteVideoTrack:(RTCVideoTrack*)remoteVideoTrack;
+
+- (void)connectionManagerDidReceiveHangup:(APPRTCConnectionManager*)manager;
+
+- (void)connectionManager:(APPRTCConnectionManager*)manager
+ didErrorWithMessage:(NSString*)errorMessage;
+
+@end
+
+// Abstracts the network connection aspect of AppRTC. The delegate will receive
+// information about connection status as changes occur.
+@interface APPRTCConnectionManager : NSObject
+
+@property(nonatomic, weak) id<APPRTCConnectionManagerDelegate> delegate;
+@property(nonatomic, weak) id<APPRTCLogger> logger;
+
+- (instancetype)initWithDelegate:(id<APPRTCConnectionManagerDelegate>)delegate
+ logger:(id<APPRTCLogger>)logger;
+- (BOOL)connectToRoomWithURL:(NSURL*)url;
+- (void)disconnect;
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/APPRTCConnectionManager.m b/talk/examples/objc/AppRTCDemo/APPRTCConnectionManager.m
new file mode 100644
index 0000000..6d0a5a2
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/APPRTCConnectionManager.m
@@ -0,0 +1,494 @@
+/*
+ * libjingle
+ * Copyright 2014, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "APPRTCConnectionManager.h"
+
+#import <AVFoundation/AVFoundation.h>
+#import "APPRTCAppClient.h"
+#import "GAEChannelClient.h"
+#import "RTCICECandidate.h"
+#import "RTCMediaConstraints.h"
+#import "RTCMediaStream.h"
+#import "RTCPair.h"
+#import "RTCPeerConnection.h"
+#import "RTCPeerConnectionDelegate.h"
+#import "RTCPeerConnectionFactory.h"
+#import "RTCSessionDescription.h"
+#import "RTCSessionDescriptionDelegate.h"
+#import "RTCStatsDelegate.h"
+#import "RTCVideoCapturer.h"
+#import "RTCVideoSource.h"
+
+@interface APPRTCConnectionManager ()
+ <APPRTCAppClientDelegate, GAEMessageHandler, RTCPeerConnectionDelegate,
+ RTCSessionDescriptionDelegate, RTCStatsDelegate>
+
+@property(nonatomic, strong) APPRTCAppClient* client;
+@property(nonatomic, strong) RTCPeerConnection* peerConnection;
+@property(nonatomic, strong) RTCPeerConnectionFactory* peerConnectionFactory;
+@property(nonatomic, strong) RTCVideoSource* videoSource;
+@property(nonatomic, strong) NSMutableArray* queuedRemoteCandidates;
+
+@end
+
+@implementation APPRTCConnectionManager {
+ NSTimer* _statsTimer;
+}
+
+- (instancetype)initWithDelegate:(id<APPRTCConnectionManagerDelegate>)delegate
+ logger:(id<APPRTCLogger>)logger {
+ if (self = [super init]) {
+ self.delegate = delegate;
+ self.logger = logger;
+ self.peerConnectionFactory = [[RTCPeerConnectionFactory alloc] init];
+ // TODO(tkchin): turn this into a button.
+ // Uncomment for stat logs.
+ // _statsTimer =
+ // [NSTimer scheduledTimerWithTimeInterval:10
+ // target:self
+ // selector:@selector(didFireStatsTimer:)
+ // userInfo:nil
+ // repeats:YES];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [self disconnect];
+}
+
+- (BOOL)connectToRoomWithURL:(NSURL*)url {
+ if (self.client) {
+ // Already have a connection.
+ return NO;
+ }
+ self.client = [[APPRTCAppClient alloc] initWithDelegate:self
+ messageHandler:self];
+ [self.client connectToRoom:url];
+ return YES;
+}
+
+- (void)disconnect {
+ if (!self.client) {
+ return;
+ }
+ [self.client
+ sendData:[@"{\"type\": \"bye\"}" dataUsingEncoding:NSUTF8StringEncoding]];
+ [self.peerConnection close];
+ self.peerConnection = nil;
+ self.client = nil;
+ self.queuedRemoteCandidates = nil;
+}
+
+#pragma mark - APPRTCAppClientDelegate
+
+- (void)appClient:(APPRTCAppClient*)appClient
+ didErrorWithMessage:(NSString*)message {
+ [self.delegate connectionManager:self
+ didErrorWithMessage:message];
+}
+
+- (void)appClient:(APPRTCAppClient*)appClient
+ didReceiveICEServers:(NSArray*)servers {
+ self.queuedRemoteCandidates = [NSMutableArray array];
+ RTCMediaConstraints* constraints = [[RTCMediaConstraints alloc]
+ initWithMandatoryConstraints:
+ @[
+ [[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"],
+ [[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"]
+ ]
+ optionalConstraints:
+ @[
+ [[RTCPair alloc] initWithKey:@"internalSctpDataChannels"
+ value:@"true"],
+ [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement"
+ value:@"true"]
+ ]];
+ self.peerConnection =
+ [self.peerConnectionFactory peerConnectionWithICEServers:servers
+ constraints:constraints
+ delegate:self];
+ RTCMediaStream* lms =
+ [self.peerConnectionFactory mediaStreamWithLabel:@"ARDAMS"];
+
+ // The iOS simulator doesn't provide any sort of camera capture
+ // support or emulation (http://goo.gl/rHAnC1) so don't bother
+ // trying to open a local stream.
+ RTCVideoTrack* localVideoTrack;
+
+ // TODO(tkchin): local video capture for OSX. See
+ // https://code.google.com/p/webrtc/issues/detail?id=3417.
+#if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE
+ NSString* cameraID = nil;
+ for (AVCaptureDevice* captureDevice in
+ [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
+ if (captureDevice.position == AVCaptureDevicePositionFront) {
+ cameraID = [captureDevice localizedName];
+ break;
+ }
+ }
+ NSAssert(cameraID, @"Unable to get the front camera id");
+
+ RTCVideoCapturer* capturer =
+ [RTCVideoCapturer capturerWithDeviceName:cameraID];
+ self.videoSource = [self.peerConnectionFactory
+ videoSourceWithCapturer:capturer
+ constraints:self.client.videoConstraints];
+ localVideoTrack =
+ [self.peerConnectionFactory videoTrackWithID:@"ARDAMSv0"
+ source:self.videoSource];
+ if (localVideoTrack) {
+ [lms addVideoTrack:localVideoTrack];
+ }
+ [self.delegate connectionManager:self
+ didReceiveLocalVideoTrack:localVideoTrack];
+#endif
+
+ [lms addAudioTrack:[self.peerConnectionFactory audioTrackWithID:@"ARDAMSa0"]];
+ [self.peerConnection addStream:lms constraints:constraints];
+ [self.logger logMessage:@"onICEServers - added local stream."];
+}
+
+#pragma mark - GAEMessageHandler methods
+
+- (void)onOpen {
+ if (!self.client.initiator) {
+ [self.logger logMessage:@"Callee; waiting for remote offer"];
+ return;
+ }
+ [self.logger logMessage:@"GAE onOpen - create offer."];
+ RTCPair* audio =
+ [[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"];
+ RTCPair* video =
+ [[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"];
+ NSArray* mandatory = @[ audio, video ];
+ RTCMediaConstraints* constraints =
+ [[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatory
+ optionalConstraints:nil];
+ [self.peerConnection createOfferWithDelegate:self constraints:constraints];
+ [self.logger logMessage:@"PC - createOffer."];
+}
+
+- (void)onMessage:(NSDictionary*)messageData {
+ NSString* type = messageData[@"type"];
+ NSAssert(type, @"Missing type: %@", messageData);
+ [self.logger logMessage:[NSString stringWithFormat:@"GAE onMessage type - %@",
+ type]];
+ if ([type isEqualToString:@"candidate"]) {
+ NSString* mid = messageData[@"id"];
+ NSNumber* sdpLineIndex = messageData[@"label"];
+ NSString* sdp = messageData[@"candidate"];
+ RTCICECandidate* candidate =
+ [[RTCICECandidate alloc] initWithMid:mid
+ index:sdpLineIndex.intValue
+ sdp:sdp];
+ if (self.queuedRemoteCandidates) {
+ [self.queuedRemoteCandidates addObject:candidate];
+ } else {
+ [self.peerConnection addICECandidate:candidate];
+ }
+ } else if ([type isEqualToString:@"offer"] ||
+ [type isEqualToString:@"answer"]) {
+ NSString* sdpString = messageData[@"sdp"];
+ RTCSessionDescription* sdp = [[RTCSessionDescription alloc]
+ initWithType:type
+ sdp:[[self class] preferISAC:sdpString]];
+ [self.peerConnection setRemoteDescriptionWithDelegate:self
+ sessionDescription:sdp];
+ [self.logger logMessage:@"PC - setRemoteDescription."];
+ } else if ([type isEqualToString:@"bye"]) {
+ [self.delegate connectionManagerDidReceiveHangup:self];
+ } else {
+ NSAssert(NO, @"Invalid message: %@", messageData);
+ }
+}
+
+- (void)onClose {
+ [self.logger logMessage:@"GAE onClose."];
+ [self.delegate connectionManagerDidReceiveHangup:self];
+}
+
+- (void)onError:(int)code withDescription:(NSString*)description {
+ NSString* message = [NSString stringWithFormat:@"GAE onError: %d, %@",
+ code, description];
+ [self.logger logMessage:message];
+ [self.delegate connectionManager:self
+ didErrorWithMessage:message];
+}
+
+#pragma mark - RTCPeerConnectionDelegate
+
+- (void)peerConnectionOnError:(RTCPeerConnection*)peerConnection {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSString* message = @"PeerConnection error";
+ NSLog(@"%@", message);
+ NSAssert(NO, @"PeerConnection failed.");
+ [self.delegate connectionManager:self
+ didErrorWithMessage:message];
+ });
+}
+
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+ signalingStateChanged:(RTCSignalingState)stateChanged {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSLog(@"PCO onSignalingStateChange: %d", stateChanged);
+ });
+}
+
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+ addedStream:(RTCMediaStream*)stream {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSLog(@"PCO onAddStream.");
+ NSAssert([stream.audioTracks count] == 1 || [stream.videoTracks count] == 1,
+ @"Expected audio or video track");
+ NSAssert([stream.audioTracks count] <= 1,
+ @"Expected at most 1 audio stream");
+ NSAssert([stream.videoTracks count] <= 1,
+ @"Expected at most 1 video stream");
+ if ([stream.videoTracks count] != 0) {
+ [self.delegate connectionManager:self
+ didReceiveRemoteVideoTrack:stream.videoTracks[0]];
+ }
+ });
+}
+
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+ removedStream:(RTCMediaStream*)stream {
+ dispatch_async(dispatch_get_main_queue(),
+ ^{ NSLog(@"PCO onRemoveStream."); });
+}
+
+- (void)peerConnectionOnRenegotiationNeeded:(RTCPeerConnection*)peerConnection {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSLog(@"PCO onRenegotiationNeeded - ignoring because AppRTC has a "
+ "predefined negotiation strategy");
+ });
+}
+
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+ gotICECandidate:(RTCICECandidate*)candidate {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSLog(@"PCO onICECandidate.\n Mid[%@] Index[%li] Sdp[%@]",
+ candidate.sdpMid,
+ (long)candidate.sdpMLineIndex,
+ candidate.sdp);
+ NSDictionary* json = @{
+ @"type" : @"candidate",
+ @"label" : @(candidate.sdpMLineIndex),
+ @"id" : candidate.sdpMid,
+ @"candidate" : candidate.sdp
+ };
+ NSError* error;
+ NSData* data =
+ [NSJSONSerialization dataWithJSONObject:json options:0 error:&error];
+ if (!error) {
+ [self.client sendData:data];
+ } else {
+ NSAssert(NO,
+ @"Unable to serialize JSON object with error: %@",
+ error.localizedDescription);
+ }
+ });
+}
+
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+ iceGatheringChanged:(RTCICEGatheringState)newState {
+ dispatch_async(dispatch_get_main_queue(),
+ ^{ NSLog(@"PCO onIceGatheringChange. %d", newState); });
+}
+
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+ iceConnectionChanged:(RTCICEConnectionState)newState {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSLog(@"PCO onIceConnectionChange. %d", newState);
+ if (newState == RTCICEConnectionConnected)
+ [self.logger logMessage:@"ICE Connection Connected."];
+ NSAssert(newState != RTCICEConnectionFailed, @"ICE Connection failed!");
+ });
+}
+
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+ didOpenDataChannel:(RTCDataChannel*)dataChannel {
+ NSAssert(NO, @"AppRTC doesn't use DataChannels");
+}
+
+#pragma mark - RTCSessionDescriptionDelegate
+
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+ didCreateSessionDescription:(RTCSessionDescription*)origSdp
+ error:(NSError*)error {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (error) {
+ [self.logger logMessage:@"SDP onFailure."];
+ NSAssert(NO, error.description);
+ return;
+ }
+ [self.logger logMessage:@"SDP onSuccess(SDP) - set local description."];
+ RTCSessionDescription* sdp = [[RTCSessionDescription alloc]
+ initWithType:origSdp.type
+ sdp:[[self class] preferISAC:origSdp.description]];
+ [self.peerConnection setLocalDescriptionWithDelegate:self
+ sessionDescription:sdp];
+ [self.logger logMessage:@"PC setLocalDescription."];
+ NSDictionary* json = @{@"type" : sdp.type, @"sdp" : sdp.description};
+ NSError* jsonError;
+ NSData* data = [NSJSONSerialization dataWithJSONObject:json
+ options:0
+ error:&jsonError];
+ NSAssert(!jsonError, @"Error: %@", jsonError.description);
+ [self.client sendData:data];
+ });
+}
+
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+ didSetSessionDescriptionWithError:(NSError*)error {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (error) {
+ [self.logger logMessage:@"SDP onFailure."];
+ NSAssert(NO, error.description);
+ return;
+ }
+ [self.logger logMessage:@"SDP onSuccess() - possibly drain candidates"];
+ if (!self.client.initiator) {
+ if (self.peerConnection.remoteDescription &&
+ !self.peerConnection.localDescription) {
+ [self.logger logMessage:@"Callee, setRemoteDescription succeeded"];
+ RTCPair* audio = [[RTCPair alloc] initWithKey:@"OfferToReceiveAudio"
+ value:@"true"];
+ 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.logger logMessage:@"PC - createAnswer."];
+ } else {
+ [self.logger logMessage:@"SDP onSuccess - drain candidates"];
+ [self drainRemoteCandidates];
+ }
+ } else {
+ if (self.peerConnection.remoteDescription) {
+ [self.logger logMessage:@"SDP onSuccess - drain candidates"];
+ [self drainRemoteCandidates];
+ }
+ }
+ });
+}
+
+#pragma mark - RTCStatsDelegate methods
+
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+ didGetStats:(NSArray*)stats {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSString* message = [NSString stringWithFormat:@"Stats:\n %@", stats];
+ [self.logger logMessage:message];
+ });
+}
+
+#pragma mark - Private
+
+// Match |pattern| to |string| and return the first group of the first
+// match, or nil if no match was found.
++ (NSString*)firstMatch:(NSRegularExpression*)pattern
+ withString:(NSString*)string {
+ NSTextCheckingResult* result =
+ [pattern firstMatchInString:string
+ options:0
+ range:NSMakeRange(0, [string length])];
+ if (!result)
+ return nil;
+ return [string substringWithRange:[result rangeAtIndex:1]];
+}
+
+// Mangle |origSDP| to prefer the ISAC/16k audio codec.
++ (NSString*)preferISAC:(NSString*)origSDP {
+ int mLineIndex = -1;
+ NSString* isac16kRtpMap = nil;
+ NSArray* lines = [origSDP componentsSeparatedByString:@"\n"];
+ NSRegularExpression* isac16kRegex = [NSRegularExpression
+ regularExpressionWithPattern:@"^a=rtpmap:(\\d+) ISAC/16000[\r]?$"
+ options:0
+ error:nil];
+ for (int i = 0;
+ (i < [lines count]) && (mLineIndex == -1 || isac16kRtpMap == nil);
+ ++i) {
+ NSString* line = [lines objectAtIndex:i];
+ if ([line hasPrefix:@"m=audio "]) {
+ mLineIndex = i;
+ continue;
+ }
+ isac16kRtpMap = [self firstMatch:isac16kRegex withString:line];
+ }
+ if (mLineIndex == -1) {
+ NSLog(@"No m=audio line, so can't prefer iSAC");
+ return origSDP;
+ }
+ if (isac16kRtpMap == nil) {
+ NSLog(@"No ISAC/16000 line, so can't prefer iSAC");
+ return origSDP;
+ }
+ NSArray* origMLineParts =
+ [[lines objectAtIndex:mLineIndex] componentsSeparatedByString:@" "];
+ NSMutableArray* newMLine =
+ [NSMutableArray arrayWithCapacity:[origMLineParts count]];
+ int origPartIndex = 0;
+ // Format is: m=<media> <port> <proto> <fmt> ...
+ [newMLine addObject:[origMLineParts objectAtIndex:origPartIndex++]];
+ [newMLine addObject:[origMLineParts objectAtIndex:origPartIndex++]];
+ [newMLine addObject:[origMLineParts objectAtIndex:origPartIndex++]];
+ [newMLine addObject:isac16kRtpMap];
+ for (; origPartIndex < [origMLineParts count]; ++origPartIndex) {
+ if (![isac16kRtpMap
+ isEqualToString:[origMLineParts objectAtIndex:origPartIndex]]) {
+ [newMLine addObject:[origMLineParts objectAtIndex:origPartIndex]];
+ }
+ }
+ NSMutableArray* newLines = [NSMutableArray arrayWithCapacity:[lines count]];
+ [newLines addObjectsFromArray:lines];
+ [newLines replaceObjectAtIndex:mLineIndex
+ withObject:[newMLine componentsJoinedByString:@" "]];
+ return [newLines componentsJoinedByString:@"\n"];
+}
+
+- (void)drainRemoteCandidates {
+ for (RTCICECandidate* candidate in self.queuedRemoteCandidates) {
+ [self.peerConnection addICECandidate:candidate];
+ }
+ self.queuedRemoteCandidates = nil;
+}
+
+- (void)didFireStatsTimer:(NSTimer*)timer {
+ if (self.peerConnection) {
+ [self.peerConnection getStatsWithDelegate:self
+ mediaStreamTrack:nil
+ statsOutputLevel:RTCStatsOutputLevelDebug];
+ }
+}
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/GAEChannelClient.h b/talk/examples/objc/AppRTCDemo/GAEChannelClient.h
new file mode 100644
index 0000000..2eac214
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/GAEChannelClient.h
@@ -0,0 +1,49 @@
+/*
+ * libjingle
+ * Copyright 2013, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+
+// These methods will be called by the AppEngine chanel. The documentation
+// for these methods is found here. (Yes, it is a JS API.)
+// https://developers.google.com/appengine/docs/java/channel/javascript
+@protocol GAEMessageHandler<NSObject>
+
+- (void)onOpen;
+- (void)onMessage:(NSDictionary*)data;
+- (void)onClose;
+- (void)onError:(int)code withDescription:(NSString*)description;
+
+@end
+
+// Initialize with a token for an AppRTC data channel. This will load
+// ios_channel.html and use the token to establish a data channel between the
+// application and AppEngine.
+@interface GAEChannelClient : NSObject
+
+- (id)initWithToken:(NSString*)token delegate:(id<GAEMessageHandler>)delegate;
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/GAEChannelClient.m b/talk/examples/objc/AppRTCDemo/GAEChannelClient.m
new file mode 100644
index 0000000..6146043
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/GAEChannelClient.m
@@ -0,0 +1,167 @@
+/*
+ * libjingle
+ * Copyright 2013, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "GAEChannelClient.h"
+
+#import "RTCPeerConnectionFactory.h"
+
+#if TARGET_OS_IPHONE
+
+#import <UIKit/UIKit.h>
+
+@interface GAEChannelClient () <UIWebViewDelegate>
+
+@property(nonatomic, strong) UIWebView* webView;
+
+#else
+
+#import <WebKit/WebKit.h>
+
+@interface GAEChannelClient ()
+
+@property(nonatomic, strong) WebView* webView;
+
+#endif
+
+@property(nonatomic, assign) id<GAEMessageHandler> delegate;
+
+@end
+
+@implementation GAEChannelClient
+
+- (id)initWithToken:(NSString*)token delegate:(id<GAEMessageHandler>)delegate {
+ self = [super init];
+ if (self) {
+#if TARGET_OS_IPHONE
+ _webView = [[UIWebView alloc] init];
+ _webView.delegate = self;
+#else
+ _webView = [[WebView alloc] init];
+ _webView.policyDelegate = self;
+#endif
+ _delegate = delegate;
+ NSString* htmlPath =
+ [[NSBundle mainBundle] pathForResource:@"channel" ofType:@"html"];
+ NSURL* htmlUrl = [NSURL fileURLWithPath:htmlPath];
+ NSString* path = [NSString
+ stringWithFormat:@"%@?token=%@", [htmlUrl absoluteString], token];
+
+#if TARGET_OS_IPHONE
+ [_webView
+#else
+ [[_webView mainFrame]
+#endif
+ loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:path]]];
+ }
+ return self;
+}
+
+- (void)dealloc {
+#if TARGET_OS_IPHONE
+ _webView.delegate = nil;
+ [_webView stopLoading];
+#else
+ _webView.policyDelegate = nil;
+ [[_webView mainFrame] stopLoading];
+#endif
+}
+
+#if TARGET_OS_IPHONE
+#pragma mark - UIWebViewDelegate
+
+- (BOOL)webView:(UIWebView*)webView
+ shouldStartLoadWithRequest:(NSURLRequest*)request
+ navigationType:(UIWebViewNavigationType)navigationType {
+#else
+// WebPolicyDelegate is an informal delegate.
+#pragma mark - WebPolicyDelegate
+
+- (void)webView:(WebView*)webView
+ decidePolicyForNavigationAction:(NSDictionary*)actionInformation
+ request:(NSURLRequest*)request
+ frame:(WebFrame*)frame
+ decisionListener:(id<WebPolicyDecisionListener>)listener {
+#endif
+ NSString* scheme = [request.URL scheme];
+ NSAssert(scheme, @"scheme is nil: %@", request);
+ if (![scheme isEqualToString:@"js-frame"]) {
+#if TARGET_OS_IPHONE
+ return YES;
+#else
+ [listener use];
+ return;
+#endif
+ }
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSString* queuedMessage = [webView
+ stringByEvaluatingJavaScriptFromString:@"popQueuedMessage();"];
+ NSAssert([queuedMessage length], @"Empty queued message from JS");
+
+ NSDictionary* queuedMessageDict =
+ [GAEChannelClient jsonStringToDictionary:queuedMessage];
+ NSString* method = queuedMessageDict[@"type"];
+ NSAssert(method, @"Missing method: %@", queuedMessageDict);
+ NSDictionary* payload = queuedMessageDict[@"payload"]; // May be nil.
+
+ if ([method isEqualToString:@"onopen"]) {
+ [self.delegate onOpen];
+ } else if ([method isEqualToString:@"onmessage"]) {
+ NSDictionary* payloadData =
+ [GAEChannelClient jsonStringToDictionary:payload[@"data"]];
+ [self.delegate onMessage:payloadData];
+ } else if ([method isEqualToString:@"onclose"]) {
+ [self.delegate onClose];
+ } else if ([method isEqualToString:@"onerror"]) {
+ NSNumber* codeNumber = payload[@"code"];
+ int code = [codeNumber intValue];
+ NSAssert([codeNumber isEqualToNumber:[NSNumber numberWithInt:code]],
+ @"Unexpected non-integral code: %@", payload);
+ [self.delegate onError:code withDescription:payload[@"description"]];
+ } else {
+ NSAssert(NO, @"Invalid message sent from UIWebView: %@", queuedMessage);
+ }
+ });
+#if TARGET_OS_IPHONE
+ return NO;
+#else
+ [listener ignore];
+ return;
+#endif
+}
+
+#pragma mark - Private
+
++ (NSDictionary*)jsonStringToDictionary:(NSString*)str {
+ NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
+ NSError* error;
+ NSDictionary* dict =
+ [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
+ NSAssert(!error, @"Invalid JSON? %@", str);
+ return dict;
+}
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/channel.html b/talk/examples/objc/AppRTCDemo/channel.html
new file mode 100644
index 0000000..86846dd
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/channel.html
@@ -0,0 +1,94 @@
+<html>
+ <head>
+ <script src="http://apprtc.appspot.com/_ah/channel/jsapi"></script>
+ </head>
+ <!--
+ Helper HTML that redirects Google AppEngine's Channel API to Objective C.
+ This is done by hosting this page in an iOS application. The hosting
+ class creates a UIWebView control and implements the UIWebViewDelegate
+ protocol. Then when there is a channel message it is queued in JS,
+ and an IFRAME is added to the DOM, triggering a navigation event
+ |shouldStartLoadWithRequest| in Objective C which can then fetch the
+ message using |popQueuedMessage|. This queuing is necessary to avoid URL
+ length limits in UIWebView (which are undocumented).
+ -->
+ <body onbeforeunload="closeSocket()" onload="openSocket()">
+ <script type="text/javascript">
+ // QueryString is copy/pasta from
+ // chromium's chrome/test/data/media/html/utils.js.
+ var QueryString = function () {
+ // Allows access to query parameters on the URL; e.g., given a URL like:
+ // http://<url>/my.html?test=123&bob=123
+ // parameters can now be accessed via QueryString.test or
+ // QueryString.bob.
+ var params = {};
+
+ // RegEx to split out values by &.
+ var r = /([^&=]+)=?([^&]*)/g;
+
+ // Lambda function for decoding extracted match values. Replaces '+'
+ // with space so decodeURIComponent functions properly.
+ function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); }
+
+ var match;
+ while (match = r.exec(window.location.search.substring(1)))
+ params[d(match[1])] = d(match[2]);
+
+ return params;
+ } ();
+
+ var channel = null;
+ var socket = null;
+ // In-order queue of messages to be delivered to ObjectiveC.
+ // Each is a JSON.stringify()'d dictionary containing a 'type'
+ // field and optionally a 'payload'.
+ var messageQueue = [];
+
+ function openSocket() {
+ if (!QueryString.token || !QueryString.token.match(/^[A-z0-9_-]+$/)) {
+ // Send error back to ObjC. This will assert in GAEChannelClient.m.
+ sendMessageToObjC("JSError:Missing/malformed token parameter " +
+ QueryString.token);
+ throw "Missing/malformed token parameter: " + QueryString.token;
+ }
+ channel = new goog.appengine.Channel(QueryString.token);
+ socket = channel.open({
+ 'onopen': function() {
+ sendMessageToObjC("onopen");
+ },
+ 'onmessage': function(msg) {
+ sendMessageToObjC("onmessage", msg);
+ },
+ 'onclose': function() {
+ sendMessageToObjC("onclose");
+ },
+ 'onerror': function(err) {
+ sendMessageToObjC("onerror", err);
+ }
+ });
+ }
+
+ function closeSocket() {
+ socket.close();
+ }
+
+ // Add an IFRAME to the DOM to trigger a navigation event. Then remove
+ // it as it is no longer needed. Only one event is generated.
+ function sendMessageToObjC(type, payload) {
+ messageQueue.push(JSON.stringify({'type': type, 'payload': payload}));
+ var iframe = document.createElement("IFRAME");
+ iframe.setAttribute("src", "js-frame:");
+ // For some reason we need to set a non-empty size for the iOS6
+ // simulator...
+ iframe.setAttribute("height", "1px");
+ iframe.setAttribute("width", "1px");
+ document.documentElement.appendChild(iframe);
+ iframe.parentNode.removeChild(iframe);
+ }
+
+ function popQueuedMessage() {
+ return messageQueue.shift();
+ }
+ </script>
+ </body>
+</html>
diff --git a/talk/examples/objc/AppRTCDemo/ios/APPRTCAppDelegate.h b/talk/examples/objc/AppRTCDemo/ios/APPRTCAppDelegate.h
new file mode 100644
index 0000000..196b39f
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/ios/APPRTCAppDelegate.h
@@ -0,0 +1,34 @@
+/*
+ * libjingle
+ * Copyright 2013, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <UIKit/UIKit.h>
+
+// The main application class of the AppRTCDemo iOS app demonstrating
+// interoperability between the Objective C implementation of PeerConnection
+// and the apprtc.appspot.com demo webapp.
+@interface APPRTCAppDelegate : NSObject<UIApplicationDelegate>
+@end
diff --git a/talk/examples/objc/AppRTCDemo/ios/APPRTCAppDelegate.m b/talk/examples/objc/AppRTCDemo/ios/APPRTCAppDelegate.m
new file mode 100644
index 0000000..58963d5
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/ios/APPRTCAppDelegate.m
@@ -0,0 +1,65 @@
+/*
+ * libjingle
+ * Copyright 2013, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "APPRTCAppDelegate.h"
+
+#import "APPRTCViewController.h"
+#import "RTCPeerConnectionFactory.h"
+
+@implementation APPRTCAppDelegate {
+ UIWindow* _window;
+}
+
+#pragma mark - UIApplicationDelegate methods
+
+- (BOOL)application:(UIApplication*)application
+ didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
+ [RTCPeerConnectionFactory initializeSSL];
+ _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ APPRTCViewController* viewController =
+ [[APPRTCViewController alloc] initWithNibName:@"APPRTCViewController"
+ bundle:nil];
+ _window.rootViewController = viewController;
+ [_window makeKeyAndVisible];
+ return YES;
+}
+
+- (void)applicationWillResignActive:(UIApplication*)application {
+ [[self appRTCViewController] applicationWillResignActive:application];
+}
+
+- (void)applicationWillTerminate:(UIApplication*)application {
+ [RTCPeerConnectionFactory deinitializeSSL];
+}
+
+#pragma mark - Private
+
+- (APPRTCViewController*)appRTCViewController {
+ return (APPRTCViewController*)_window.rootViewController;
+}
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/ios/APPRTCViewController.h b/talk/examples/objc/AppRTCDemo/ios/APPRTCViewController.h
new file mode 100644
index 0000000..5b10199
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/ios/APPRTCViewController.h
@@ -0,0 +1,40 @@
+/*
+ * libjingle
+ * Copyright 2013, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <UIKit/UIKit.h>
+
+// The view controller that is displayed when AppRTCDemo is loaded.
+@interface APPRTCViewController : UIViewController<UITextFieldDelegate>
+
+@property(weak, nonatomic) IBOutlet UITextField* roomInput;
+@property(weak, nonatomic) IBOutlet UITextView* instructionsView;
+@property(weak, nonatomic) IBOutlet UITextView* logView;
+@property(weak, nonatomic) IBOutlet UIView* blackView;
+
+- (void)applicationWillResignActive:(UIApplication*)application;
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/ios/APPRTCViewController.m b/talk/examples/objc/AppRTCDemo/ios/APPRTCViewController.m
new file mode 100644
index 0000000..a4a0bd3
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/ios/APPRTCViewController.m
@@ -0,0 +1,231 @@
+/*
+ * libjingle
+ * Copyright 2013, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+#import "APPRTCViewController.h"
+
+#import <AVFoundation/AVFoundation.h>
+#import "APPRTCConnectionManager.h"
+#import "RTCEAGLVideoView.h"
+
+// Padding space for local video view with its parent.
+static CGFloat const kLocalViewPadding = 20;
+
+@interface APPRTCViewController ()
+<APPRTCConnectionManagerDelegate, APPRTCLogger, RTCEAGLVideoViewDelegate>
+@property(nonatomic, assign) UIInterfaceOrientation statusBarOrientation;
+@property(nonatomic, strong) RTCEAGLVideoView* localVideoView;
+@property(nonatomic, strong) RTCEAGLVideoView* remoteVideoView;
+@end
+
+@implementation APPRTCViewController {
+ APPRTCConnectionManager* _connectionManager;
+ CGSize _localVideoSize;
+ CGSize _remoteVideoSize;
+}
+
+- (instancetype)initWithNibName:(NSString*)nibName
+ bundle:(NSBundle*)bundle {
+ if (self = [super initWithNibName:nibName bundle:bundle]) {
+ _connectionManager =
+ [[APPRTCConnectionManager alloc] initWithDelegate:self
+ logger:self];
+ }
+ return self;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ self.statusBarOrientation =
+ [UIApplication sharedApplication].statusBarOrientation;
+ self.roomInput.delegate = self;
+ [self.roomInput becomeFirstResponder];
+}
+
+- (void)viewDidLayoutSubviews {
+ if (self.statusBarOrientation !=
+ [UIApplication sharedApplication].statusBarOrientation) {
+ self.statusBarOrientation =
+ [UIApplication sharedApplication].statusBarOrientation;
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:@"StatusBarOrientationDidChange"
+ object:nil];
+ }
+}
+
+- (void)applicationWillResignActive:(UIApplication*)application {
+ [self logMessage:@"Application lost focus, connection broken."];
+ [self disconnect];
+}
+
+#pragma mark - APPRTCConnectionManagerDelegate
+
+- (void)connectionManager:(APPRTCConnectionManager*)manager
+ didReceiveLocalVideoTrack:(RTCVideoTrack*)localVideoTrack {
+ self.localVideoView.hidden = NO;
+ self.localVideoView.videoTrack = localVideoTrack;
+}
+
+- (void)connectionManager:(APPRTCConnectionManager*)manager
+ didReceiveRemoteVideoTrack:(RTCVideoTrack*)remoteVideoTrack {
+ self.remoteVideoView.videoTrack = remoteVideoTrack;
+}
+
+- (void)connectionManagerDidReceiveHangup:(APPRTCConnectionManager*)manager {
+ [self showAlertWithMessage:@"Remote hung up."];
+ [self disconnect];
+}
+
+- (void)connectionManager:(APPRTCConnectionManager*)manager
+ didErrorWithMessage:(NSString*)message {
+ [self showAlertWithMessage:message];
+ [self disconnect];
+}
+
+#pragma mark - APPRTCLogger
+
+- (void)logMessage:(NSString*)message {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSString* output =
+ [NSString stringWithFormat:@"%@\n%@", self.logView.text, message];
+ self.logView.text = output;
+ [self.logView
+ scrollRangeToVisible:NSMakeRange([self.logView.text length], 0)];
+ });
+}
+
+#pragma mark - RTCEAGLVideoViewDelegate
+
+- (void)videoView:(RTCEAGLVideoView*)videoView
+ didChangeVideoSize:(CGSize)size {
+ if (videoView == self.localVideoView) {
+ _localVideoSize = size;
+ } else if (videoView == self.remoteVideoView) {
+ _remoteVideoSize = size;
+ } else {
+ NSParameterAssert(NO);
+ }
+ [self updateVideoViewLayout];
+}
+
+#pragma mark - UITextFieldDelegate
+
+- (void)textFieldDidEndEditing:(UITextField*)textField {
+ NSString* room = textField.text;
+ if ([room length] == 0) {
+ return;
+ }
+ textField.hidden = YES;
+ self.instructionsView.hidden = YES;
+ self.logView.hidden = NO;
+ NSString* url =
+ [NSString stringWithFormat:@"https://apprtc.appspot.com/?r=%@", room];
+ [_connectionManager connectToRoomWithURL:[NSURL URLWithString:url]];
+ [self setupCaptureSession];
+}
+
+- (BOOL)textFieldShouldReturn:(UITextField*)textField {
+ // There is no other control that can take focus, so manually resign focus
+ // when return (Join) is pressed to trigger |textFieldDidEndEditing|.
+ [textField resignFirstResponder];
+ return YES;
+}
+
+#pragma mark - Private
+
+- (void)disconnect {
+ [self resetUI];
+ [_connectionManager disconnect];
+}
+
+- (void)showAlertWithMessage:(NSString*)message {
+ UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil
+ message:message
+ delegate:nil
+ cancelButtonTitle:@"OK"
+ otherButtonTitles:nil];
+ [alertView show];
+}
+
+- (void)resetUI {
+ [self.roomInput resignFirstResponder];
+ self.roomInput.text = nil;
+ self.roomInput.hidden = NO;
+ self.instructionsView.hidden = NO;
+ self.logView.hidden = YES;
+ self.logView.text = nil;
+ self.blackView.hidden = YES;
+ [self.remoteVideoView removeFromSuperview];
+ self.remoteVideoView = nil;
+ [self.localVideoView removeFromSuperview];
+ self.localVideoView = nil;
+}
+
+- (void)setupCaptureSession {
+ self.blackView.hidden = NO;
+ self.remoteVideoView =
+ [[RTCEAGLVideoView alloc] initWithFrame:self.blackView.bounds];
+ self.remoteVideoView.delegate = self;
+ self.remoteVideoView.transform = CGAffineTransformMakeScale(-1, 1);
+ [self.blackView addSubview:self.remoteVideoView];
+
+ self.localVideoView =
+ [[RTCEAGLVideoView alloc] initWithFrame:self.blackView.bounds];
+ self.localVideoView.delegate = self;
+ [self.blackView addSubview:self.localVideoView];
+ [self updateVideoViewLayout];
+}
+
+- (void)updateVideoViewLayout {
+ // TODO(tkchin): handle rotation.
+ CGSize defaultAspectRatio = CGSizeMake(4, 3);
+ CGSize localAspectRatio = CGSizeEqualToSize(_localVideoSize, CGSizeZero) ?
+ defaultAspectRatio : _localVideoSize;
+ CGSize remoteAspectRatio = CGSizeEqualToSize(_remoteVideoSize, CGSizeZero) ?
+ defaultAspectRatio : _remoteVideoSize;
+
+ CGRect remoteVideoFrame =
+ AVMakeRectWithAspectRatioInsideRect(remoteAspectRatio,
+ self.blackView.bounds);
+ self.remoteVideoView.frame = remoteVideoFrame;
+
+ CGRect localVideoFrame =
+ AVMakeRectWithAspectRatioInsideRect(localAspectRatio,
+ self.blackView.bounds);
+ localVideoFrame.size.width = localVideoFrame.size.width / 3;
+ localVideoFrame.size.height = localVideoFrame.size.height / 3;
+ localVideoFrame.origin.x = CGRectGetMaxX(self.blackView.bounds)
+ - localVideoFrame.size.width - kLocalViewPadding;
+ localVideoFrame.origin.y = CGRectGetMaxY(self.blackView.bounds)
+ - localVideoFrame.size.height - kLocalViewPadding;
+ self.localVideoView.frame = localVideoFrame;
+}
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/ios/AppRTCDemo-Prefix.pch b/talk/examples/objc/AppRTCDemo/ios/AppRTCDemo-Prefix.pch
new file mode 100644
index 0000000..3ac2c3b
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/ios/AppRTCDemo-Prefix.pch
@@ -0,0 +1,40 @@
+/*
+ * libjingle
+ * Copyright 2013, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+//
+// Prefix header for all source files of the 'AppRTCDemo' target in the
+// 'AppRTCDemo' project
+//
+
+#import <Availability.h>
+
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
+#warning "This project uses features only available in iOS SDK 6.0 and later."
+#endif
+
+#import <UIKit/UIKit.h>
+#import <Foundation/Foundation.h>
diff --git a/talk/examples/objc/AppRTCDemo/ios/Default.png b/talk/examples/objc/AppRTCDemo/ios/Default.png
new file mode 100644
index 0000000..4c8ca6f6
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/ios/Default.png
Binary files differ
diff --git a/talk/examples/objc/AppRTCDemo/ios/Info.plist b/talk/examples/objc/AppRTCDemo/ios/Info.plist
new file mode 100644
index 0000000..b616480
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/ios/Info.plist
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>BuildMachineOSBuild</key>
+ <string>12E55</string>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>AppRTCDemo</string>
+ <key>CFBundleExecutable</key>
+ <string>AppRTCDemo</string>
+ <key>CFBundleIcons</key>
+ <dict>
+ <key>CFBundlePrimaryIcon</key>
+ <dict>
+ <key>CFBundleIconFiles</key>
+ <array>
+ <string>Icon.png</string>
+ </array>
+ </dict>
+ </dict>
+ <key>CFBundleIdentifier</key>
+ <string>com.google.AppRTCDemo</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>AppRTCDemo</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleResourceSpecification</key>
+ <string>ResourceRules.plist</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleSupportedPlatforms</key>
+ <array>
+ <string>iPhoneOS</string>
+ </array>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>UIRequiredDeviceCapabilities</key>
+ <array>
+ <string>armv7</string>
+ </array>
+ <key>UIStatusBarTintParameters</key>
+ <dict>
+ <key>UINavigationBar</key>
+ <dict>
+ <key>Style</key>
+ <string>UIBarStyleDefault</string>
+ <key>Translucent</key>
+ <false/>
+ </dict>
+ </dict>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ </array>
+</dict>
+</plist>
diff --git a/talk/examples/objc/AppRTCDemo/ios/ResourceRules.plist b/talk/examples/objc/AppRTCDemo/ios/ResourceRules.plist
new file mode 100644
index 0000000..e7ec329
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/ios/ResourceRules.plist
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>rules</key>
+ <dict>
+ <key>.*</key>
+ <true/>
+ <key>Info.plist</key>
+ <dict>
+ <key>omit</key>
+ <true/>
+ <key>weight</key>
+ <real>10</real>
+ </dict>
+ <key>ResourceRules.plist</key>
+ <dict>
+ <key>omit</key>
+ <true/>
+ <key>weight</key>
+ <real>100</real>
+ </dict>
+ </dict>
+</dict>
+</plist>
diff --git a/talk/examples/objc/AppRTCDemo/ios/en.lproj/APPRTCViewController.xib b/talk/examples/objc/AppRTCDemo/ios/en.lproj/APPRTCViewController.xib
new file mode 100644
index 0000000..cb2dc83
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/ios/en.lproj/APPRTCViewController.xib
@@ -0,0 +1,716 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
+ <data>
+ <int key="IBDocument.SystemTarget">1536</int>
+ <string key="IBDocument.SystemVersion">13B42</string>
+ <string key="IBDocument.InterfaceBuilderVersion">4514</string>
+ <string key="IBDocument.AppKitVersion">1265</string>
+ <string key="IBDocument.HIToolboxVersion">696.00</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="NS.object.0">3747</string>
+ </object>
+ <array key="IBDocument.IntegratedClassDependencies">
+ <string>IBNSLayoutConstraint</string>
+ <string>IBProxyObject</string>
+ <string>IBUITextField</string>
+ <string>IBUITextView</string>
+ <string>IBUIView</string>
+ </array>
+ <array key="IBDocument.PluginDependencies">
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </array>
+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
+ <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
+ <integer value="1" key="NS.object.0"/>
+ </object>
+ <array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <object class="IBProxyObject" id="372490531">
+ <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBProxyObject" id="843779117">
+ <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUIView" id="774585933">
+ <reference key="NSNextResponder"/>
+ <int key="NSvFlags">274</int>
+ <array class="NSMutableArray" key="NSSubviews">
+ <object class="IBUITextView" id="176994284">
+ <reference key="NSNextResponder" ref="774585933"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{20, 20}, {280, 141}}</string>
+ <reference key="NSSuperview" ref="774585933"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="634862110"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <object class="NSColor" key="IBUIBackgroundColor" id="621995359">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MSAxIDEAA</bytes>
+ </object>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <bool key="IBUIUserInteractionEnabled">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <string key="IBUIText">Enter the room below to connect to apprtc.</string>
+ <object class="IBUITextInputTraits" key="IBUITextInputTraits">
+ <int key="IBUIAutocapitalizationType">2</int>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUIFontDescription" key="IBUIFontDescription" id="166497611">
+ <int key="type">1</int>
+ <double key="pointSize">14</double>
+ </object>
+ <object class="NSFont" key="IBUIFont" id="144501234">
+ <string key="NSName">HelveticaNeue</string>
+ <double key="NSSize">14</double>
+ <int key="NSfFlags">16</int>
+ </object>
+ </object>
+ <object class="IBUITextField" id="546385578">
+ <reference key="NSNextResponder" ref="774585933"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{20, 180}, {280, 30}}</string>
+ <reference key="NSSuperview" ref="774585933"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="261050959"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <int key="IBUIContentVerticalAlignment">0</int>
+ <string key="IBUIText"/>
+ <int key="IBUIBorderStyle">3</int>
+ <string key="IBUIPlaceholder">apprtc room</string>
+ <object class="NSColor" key="IBUITextColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MAA</bytes>
+ <object class="NSColorSpace" key="NSCustomColorSpace" id="14071810">
+ <int key="NSID">2</int>
+ </object>
+ </object>
+ <bool key="IBUIAdjustsFontSizeToFit">YES</bool>
+ <float key="IBUIMinimumFontSize">17</float>
+ <object class="IBUITextInputTraits" key="IBUITextInputTraits">
+ <int key="IBUIKeyboardType">2</int>
+ <int key="IBUIReturnKeyType">3</int>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <reference key="IBUIFontDescription" ref="166497611"/>
+ <reference key="IBUIFont" ref="144501234"/>
+ </object>
+ <object class="IBUITextView" id="634862110">
+ <reference key="NSNextResponder" ref="774585933"/>
+ <int key="NSvFlags">-2147483356</int>
+ <string key="NSFrame">{{20, 20}, {280, 190}}</string>
+ <reference key="NSSuperview" ref="774585933"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="546385578"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <reference key="IBUIBackgroundColor" ref="621995359"/>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <bool key="IBUIMultipleTouchEnabled">YES</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <bool key="IBUIEditable">NO</bool>
+ <string key="IBUIText"/>
+ <object class="IBUITextInputTraits" key="IBUITextInputTraits">
+ <int key="IBUIAutocapitalizationType">2</int>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <reference key="IBUIFontDescription" ref="166497611"/>
+ <reference key="IBUIFont" ref="144501234"/>
+ </object>
+ <object class="IBUIView" id="261050959">
+ <reference key="NSNextResponder" ref="774585933"/>
+ <int key="NSvFlags">-2147483356</int>
+ <string key="NSFrame">{{20, 228}, {280, 300}}</string>
+ <reference key="NSSuperview" ref="774585933"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <object class="NSColor" key="IBUIBackgroundColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MAA</bytes>
+ </object>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ </array>
+ <string key="NSFrame">{{0, 20}, {320, 548}}</string>
+ <reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="176994284"/>
+ <object class="NSColor" key="IBUIBackgroundColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC43NQA</bytes>
+ <reference key="NSCustomColorSpace" ref="14071810"/>
+ </object>
+ <bool key="IBUIClearsContextBeforeDrawing">NO</bool>
+ <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
+ <object class="IBUIScreenMetrics" key="IBUISimulatedDestinationMetrics">
+ <string key="IBUISimulatedSizeMetricsClass">IBUIScreenMetrics</string>
+ <object class="NSMutableDictionary" key="IBUINormalizedOrientationToSizeMap">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <array key="dict.sortedKeys">
+ <integer value="1"/>
+ <integer value="3"/>
+ </array>
+ <array key="dict.values">
+ <string>{320, 568}</string>
+ <string>{568, 320}</string>
+ </array>
+ </object>
+ <string key="IBUITargetRuntime">IBCocoaTouchFramework</string>
+ <string key="IBUIDisplayName">Retina 4-inch Full Screen</string>
+ <int key="IBUIType">2</int>
+ </object>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ </array>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <array class="NSMutableArray" key="connectionRecords">
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">view</string>
+ <reference key="source" ref="372490531"/>
+ <reference key="destination" ref="774585933"/>
+ </object>
+ <int key="connectionID">7</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">roomInput</string>
+ <reference key="source" ref="372490531"/>
+ <reference key="destination" ref="546385578"/>
+ </object>
+ <int key="connectionID">108</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">instructionsView</string>
+ <reference key="source" ref="372490531"/>
+ <reference key="destination" ref="176994284"/>
+ </object>
+ <int key="connectionID">127</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">logView</string>
+ <reference key="source" ref="372490531"/>
+ <reference key="destination" ref="634862110"/>
+ </object>
+ <int key="connectionID">138</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">blackView</string>
+ <reference key="source" ref="372490531"/>
+ <reference key="destination" ref="261050959"/>
+ </object>
+ <int key="connectionID">151</int>
+ </object>
+ </array>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <array key="orderedObjects">
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <array key="object" id="0"/>
+ <reference key="children" ref="1000"/>
+ <nil key="parent"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="372490531"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">File's Owner</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="843779117"/>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6</int>
+ <reference key="object" ref="774585933"/>
+ <array class="NSMutableArray" key="children">
+ <object class="IBNSLayoutConstraint" id="933872207">
+ <reference key="firstItem" ref="774585933"/>
+ <int key="firstAttribute">4</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="261050959"/>
+ <int key="secondAttribute">4</int>
+ <float key="multiplier">1</float>
+ <object class="IBNSLayoutSymbolicConstant" key="constant">
+ <double key="value">20</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">8</int>
+ <float key="scoringTypeFloat">23</float>
+ <int key="contentType">3</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="863471211">
+ <reference key="firstItem" ref="261050959"/>
+ <int key="firstAttribute">3</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="774585933"/>
+ <int key="secondAttribute">3</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">228</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">3</int>
+ <float key="scoringTypeFloat">9</float>
+ <int key="contentType">3</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="590654550">
+ <reference key="firstItem" ref="546385578"/>
+ <int key="firstAttribute">5</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="261050959"/>
+ <int key="secondAttribute">5</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">0.0</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">6</int>
+ <float key="scoringTypeFloat">24</float>
+ <int key="contentType">2</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="734153049">
+ <reference key="firstItem" ref="546385578"/>
+ <int key="firstAttribute">6</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="261050959"/>
+ <int key="secondAttribute">6</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">0.0</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">6</int>
+ <float key="scoringTypeFloat">24</float>
+ <int key="contentType">2</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="117610664">
+ <reference key="firstItem" ref="774585933"/>
+ <int key="firstAttribute">6</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="546385578"/>
+ <int key="secondAttribute">6</int>
+ <float key="multiplier">1</float>
+ <object class="IBNSLayoutSymbolicConstant" key="constant">
+ <double key="value">20</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">0</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="860801955">
+ <reference key="firstItem" ref="546385578"/>
+ <int key="firstAttribute">5</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="774585933"/>
+ <int key="secondAttribute">5</int>
+ <float key="multiplier">1</float>
+ <object class="IBNSLayoutSymbolicConstant" key="constant">
+ <double key="value">20</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">0</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="544488581">
+ <reference key="firstItem" ref="634862110"/>
+ <int key="firstAttribute">4</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="546385578"/>
+ <int key="secondAttribute">4</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">0.0</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">6</int>
+ <float key="scoringTypeFloat">24</float>
+ <int key="contentType">2</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="19985792">
+ <reference key="firstItem" ref="634862110"/>
+ <int key="firstAttribute">3</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="774585933"/>
+ <int key="secondAttribute">3</int>
+ <float key="multiplier">1</float>
+ <object class="IBNSLayoutSymbolicConstant" key="constant">
+ <double key="value">20</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">0</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="1001701893">
+ <reference key="firstItem" ref="774585933"/>
+ <int key="firstAttribute">6</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="634862110"/>
+ <int key="secondAttribute">6</int>
+ <float key="multiplier">1</float>
+ <object class="IBNSLayoutSymbolicConstant" key="constant">
+ <double key="value">20</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">0</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="858545289">
+ <reference key="firstItem" ref="634862110"/>
+ <int key="firstAttribute">5</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="774585933"/>
+ <int key="secondAttribute">5</int>
+ <float key="multiplier">1</float>
+ <object class="IBNSLayoutSymbolicConstant" key="constant">
+ <double key="value">20</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">0</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="1039342825">
+ <reference key="firstItem" ref="774585933"/>
+ <int key="firstAttribute">6</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="176994284"/>
+ <int key="secondAttribute">6</int>
+ <float key="multiplier">1</float>
+ <object class="IBNSLayoutSymbolicConstant" key="constant">
+ <double key="value">20</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">0</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="663764352">
+ <reference key="firstItem" ref="176994284"/>
+ <int key="firstAttribute">3</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="774585933"/>
+ <int key="secondAttribute">3</int>
+ <float key="multiplier">1</float>
+ <object class="IBNSLayoutSymbolicConstant" key="constant">
+ <double key="value">20</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">0</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <object class="IBNSLayoutConstraint" id="46028745">
+ <reference key="firstItem" ref="176994284"/>
+ <int key="firstAttribute">5</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="774585933"/>
+ <int key="secondAttribute">5</int>
+ <float key="multiplier">1</float>
+ <object class="IBNSLayoutSymbolicConstant" key="constant">
+ <double key="value">20</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="774585933"/>
+ <int key="scoringType">0</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ <reference ref="176994284"/>
+ <reference ref="546385578"/>
+ <reference ref="634862110"/>
+ <reference ref="261050959"/>
+ </array>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">57</int>
+ <reference key="object" ref="176994284"/>
+ <array class="NSMutableArray" key="children">
+ <object class="IBNSLayoutConstraint" id="234302232">
+ <reference key="firstItem" ref="176994284"/>
+ <int key="firstAttribute">8</int>
+ <int key="relation">0</int>
+ <nil key="secondItem"/>
+ <int key="secondAttribute">0</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">141</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="176994284"/>
+ <int key="scoringType">3</int>
+ <float key="scoringTypeFloat">9</float>
+ <int key="contentType">1</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ </array>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">62</int>
+ <reference key="object" ref="46028745"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">63</int>
+ <reference key="object" ref="663764352"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">66</int>
+ <reference key="object" ref="1039342825"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">104</int>
+ <reference key="object" ref="546385578"/>
+ <array class="NSMutableArray" key="children"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">107</int>
+ <reference key="object" ref="860801955"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">123</int>
+ <reference key="object" ref="234302232"/>
+ <reference key="parent" ref="176994284"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">126</int>
+ <reference key="object" ref="117610664"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">128</int>
+ <reference key="object" ref="634862110"/>
+ <array class="NSMutableArray" key="children">
+ <object class="IBNSLayoutConstraint" id="988159807">
+ <reference key="firstItem" ref="634862110"/>
+ <int key="firstAttribute">8</int>
+ <int key="relation">0</int>
+ <nil key="secondItem"/>
+ <int key="secondAttribute">0</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">190</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="634862110"/>
+ <int key="scoringType">3</int>
+ <float key="scoringTypeFloat">9</float>
+ <int key="contentType">1</int>
+ <bool key="placeholder">NO</bool>
+ </object>
+ </array>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">133</int>
+ <reference key="object" ref="858545289"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">137</int>
+ <reference key="object" ref="1001701893"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">139</int>
+ <reference key="object" ref="19985792"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">141</int>
+ <reference key="object" ref="988159807"/>
+ <reference key="parent" ref="634862110"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">142</int>
+ <reference key="object" ref="261050959"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">148</int>
+ <reference key="object" ref="734153049"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">149</int>
+ <reference key="object" ref="590654550"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">153</int>
+ <reference key="object" ref="863471211"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">154</int>
+ <reference key="object" ref="933872207"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">155</int>
+ <reference key="object" ref="544488581"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ </array>
+ </object>
+ <dictionary class="NSMutableDictionary" key="flattenedProperties">
+ <string key="-1.CustomClassName">APPRTCViewController</string>
+ <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="-2.CustomClassName">UIResponder</string>
+ <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="104.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <boolean value="NO" key="104.IBViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
+ <string key="107.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="123.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="126.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="128.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <array key="128.IBViewMetadataConstraints">
+ <reference ref="988159807"/>
+ </array>
+ <boolean value="NO" key="128.IBViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
+ <string key="133.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="137.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="139.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="141.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="142.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <boolean value="NO" key="142.IBViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
+ <string key="148.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="149.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="153.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="154.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="155.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="57.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <array class="NSMutableArray" key="57.IBViewMetadataConstraints">
+ <reference ref="234302232"/>
+ </array>
+ <boolean value="NO" key="57.IBViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
+ <string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <array class="NSMutableArray" key="6.IBViewMetadataConstraints">
+ <reference ref="46028745"/>
+ <reference ref="663764352"/>
+ <reference ref="1039342825"/>
+ <reference ref="858545289"/>
+ <reference ref="1001701893"/>
+ <reference ref="19985792"/>
+ <reference ref="544488581"/>
+ <reference ref="860801955"/>
+ <reference ref="117610664"/>
+ <reference ref="734153049"/>
+ <reference ref="590654550"/>
+ <reference ref="863471211"/>
+ <reference ref="933872207"/>
+ </array>
+ <string key="62.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="63.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="66.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
+ <nil key="activeLocalization"/>
+ <dictionary class="NSMutableDictionary" key="localizations"/>
+ <nil key="sourceID"/>
+ <int key="maxID">155</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <array class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <object class="IBPartialClassDescription">
+ <string key="className">APPRTCViewController</string>
+ <string key="superclassName">UIViewController</string>
+ <dictionary class="NSMutableDictionary" key="outlets">
+ <string key="blackView">UIView</string>
+ <string key="roomInput">UITextField</string>
+ <string key="instructionsView">UITextView</string>
+ <string key="logView">UITextView</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="blackView">
+ <string key="name">blackView</string>
+ <string key="candidateClassName">UIView</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="roomInput">
+ <string key="name">roomInput</string>
+ <string key="candidateClassName">UITextField</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="instructionsView">
+ <string key="name">instructionsView</string>
+ <string key="candidateClassName">UITextView</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="logView">
+ <string key="name">logView</string>
+ <string key="candidateClassName">UITextView</string>
+ </object>
+ </dictionary>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/APPRTCViewController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSLayoutConstraint</string>
+ <string key="superclassName">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/NSLayoutConstraint.h</string>
+ </object>
+ </object>
+ </array>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <bool key="IBDocument.previouslyAttemptedUpgradeToXcode5">YES</bool>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
+ <real value="1536" key="NS.object.0"/>
+ </object>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
+ <integer value="4600" key="NS.object.0"/>
+ </object>
+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ <bool key="IBDocument.UseAutolayout">YES</bool>
+ <string key="IBCocoaTouchPluginVersion">3747</string>
+ </data>
+</archive>
diff --git a/talk/examples/objc/AppRTCDemo/ios/main.m b/talk/examples/objc/AppRTCDemo/ios/main.m
new file mode 100644
index 0000000..e9a1f63
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/ios/main.m
@@ -0,0 +1,37 @@
+/*
+ * libjingle
+ * Copyright 2013, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <UIKit/UIKit.h>
+
+#import "APPRTCAppDelegate.h"
+
+int main(int argc, char* argv[]) {
+ @autoreleasepool {
+ return UIApplicationMain(
+ argc, argv, nil, NSStringFromClass([APPRTCAppDelegate class]));
+ }
+}
diff --git a/talk/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.h b/talk/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.h
new file mode 100644
index 0000000..77011f1
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.h
@@ -0,0 +1,31 @@
+/*
+ * libjingle
+ * Copyright 2014, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface APPRTCAppDelegate : NSObject<NSApplicationDelegate>
+@end
diff --git a/talk/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.m b/talk/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.m
new file mode 100644
index 0000000..d6bd4fc
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/mac/APPRTCAppDelegate.m
@@ -0,0 +1,77 @@
+/*
+ * libjingle
+ * Copyright 2014, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+#import "APPRTCAppDelegate.h"
+
+#import "APPRTCViewController.h"
+#import "RTCPeerConnectionFactory.h"
+
+@interface APPRTCAppDelegate () <NSWindowDelegate>
+@end
+
+@implementation APPRTCAppDelegate {
+ APPRTCViewController* _viewController;
+ NSWindow* _window;
+}
+
+#pragma mark - NSApplicationDelegate
+
+- (void)applicationDidFinishLaunching:(NSNotification*)notification {
+ [RTCPeerConnectionFactory initializeSSL];
+ NSScreen* screen = [NSScreen mainScreen];
+ NSRect visibleRect = [screen visibleFrame];
+ NSRect windowRect = NSMakeRect(NSMidX(visibleRect),
+ NSMidY(visibleRect),
+ 1320,
+ 1140);
+ NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask;
+ _window = [[NSWindow alloc] initWithContentRect:windowRect
+ styleMask:styleMask
+ backing:NSBackingStoreBuffered
+ defer:NO];
+ _window.delegate = self;
+ [_window makeKeyAndOrderFront:self];
+ [_window makeMainWindow];
+ _viewController = [[APPRTCViewController alloc] initWithNibName:nil
+ bundle:nil];
+ [_window setContentView:[_viewController view]];
+}
+
+#pragma mark - NSWindow
+
+- (void)windowWillClose:(NSNotification*)notification {
+ [_viewController windowWillClose:notification];
+ [RTCPeerConnectionFactory deinitializeSSL];
+ [NSApp terminate:self];
+}
+
+@end
+
diff --git a/talk/examples/objc/AppRTCDemo/mac/APPRTCViewController.h b/talk/examples/objc/AppRTCDemo/mac/APPRTCViewController.h
new file mode 100644
index 0000000..3ef058c
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/mac/APPRTCViewController.h
@@ -0,0 +1,34 @@
+/*
+ * libjingle
+ * Copyright 2014, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface APPRTCViewController : NSViewController
+
+- (void)windowWillClose:(NSNotification*)notification;
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/mac/APPRTCViewController.m b/talk/examples/objc/AppRTCDemo/mac/APPRTCViewController.m
new file mode 100644
index 0000000..cf5b836
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/mac/APPRTCViewController.m
@@ -0,0 +1,312 @@
+/*
+ * libjingle
+ * Copyright 2014, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "APPRTCViewController.h"
+
+#import <AVFoundation/AVFoundation.h>
+#import "APPRTCConnectionManager.h"
+#import "RTCNSGLVideoView.h"
+
+static NSUInteger const kContentWidth = 1280;
+static NSUInteger const kContentHeight = 720;
+static NSUInteger const kRoomFieldWidth = 80;
+static NSUInteger const kLogViewHeight = 280;
+
+@class APPRTCMainView;
+@protocol APPRTCMainViewDelegate
+
+- (void)appRTCMainView:(APPRTCMainView*)mainView
+ didEnterRoomId:(NSString*)roomId;
+
+@end
+
+@interface APPRTCMainView : NSView
+
+@property(nonatomic, weak) id<APPRTCMainViewDelegate> delegate;
+@property(nonatomic, readonly) RTCNSGLVideoView* localVideoView;
+@property(nonatomic, readonly) RTCNSGLVideoView* remoteVideoView;
+
+- (void)displayLogMessage:(NSString*)message;
+
+@end
+
+@interface APPRTCMainView () <NSTextFieldDelegate, RTCNSGLVideoViewDelegate>
+@end
+@implementation APPRTCMainView {
+ NSScrollView* _scrollView;
+ NSTextField* _roomLabel;
+ NSTextField* _roomField;
+ NSTextView* _logView;
+ RTCNSGLVideoView* _localVideoView;
+ RTCNSGLVideoView* _remoteVideoView;
+ CGSize _localVideoSize;
+ CGSize _remoteVideoSize;
+}
+
++ (BOOL)requiresConstraintBasedLayout {
+ return YES;
+}
+
+- (instancetype)initWithFrame:(NSRect)frame {
+ if (self = [super initWithFrame:frame]) {
+ [self setupViews];
+ }
+ return self;
+}
+
+- (void)updateConstraints {
+ NSParameterAssert(
+ _roomField != nil && _scrollView != nil && _remoteVideoView != nil);
+ [self removeConstraints:[self constraints]];
+ NSDictionary* viewsDictionary =
+ NSDictionaryOfVariableBindings(_roomLabel,
+ _roomField,
+ _scrollView,
+ _remoteVideoView);
+
+ NSSize remoteViewSize = [self remoteVideoViewSize];
+ NSDictionary* metrics = @{
+ @"kLogViewHeight" : @(kLogViewHeight),
+ @"kRoomFieldWidth" : @(kRoomFieldWidth),
+ @"remoteViewWidth" : @(remoteViewSize.width),
+ @"remoteViewHeight" : @(remoteViewSize.height),
+ };
+ // Declare this separately to avoid compiler warning about splitting string
+ // within an NSArray expression.
+ NSString* verticalConstraint =
+ @"V:|-[_roomLabel]-[_roomField]-[_scrollView(kLogViewHeight)]"
+ "-[_remoteVideoView(remoteViewHeight)]-|";
+ NSArray* constraintFormats = @[
+ verticalConstraint,
+ @"|-[_roomLabel]",
+ @"|-[_roomField(kRoomFieldWidth)]",
+ @"|-[_scrollView(remoteViewWidth)]-|",
+ @"|-[_remoteVideoView(remoteViewWidth)]-|",
+ ];
+ for (NSString* constraintFormat in constraintFormats) {
+ NSArray* constraints =
+ [NSLayoutConstraint constraintsWithVisualFormat:constraintFormat
+ options:0
+ metrics:metrics
+ views:viewsDictionary];
+ for (NSLayoutConstraint* constraint in constraints) {
+ [self addConstraint:constraint];
+ }
+ }
+ [super updateConstraints];
+}
+
+- (void)displayLogMessage:(NSString*)message {
+ _logView.string =
+ [NSString stringWithFormat:@"%@%@\n", _logView.string, message];
+ NSRange range = NSMakeRange([_logView.string length], 0);
+ [_logView scrollRangeToVisible:range];
+}
+
+#pragma mark - NSControl delegate
+
+- (void)controlTextDidEndEditing:(NSNotification*)notification {
+ NSDictionary* userInfo = [notification userInfo];
+ NSInteger textMovement = [userInfo[@"NSTextMovement"] intValue];
+ if (textMovement == NSReturnTextMovement) {
+ [self.delegate appRTCMainView:self didEnterRoomId:_roomField.stringValue];
+ }
+}
+
+#pragma mark - RTCNSGLVideoViewDelegate
+
+- (void)videoView:(RTCNSGLVideoView*)videoView
+ didChangeVideoSize:(NSSize)size {
+ if (videoView == _remoteVideoView) {
+ _remoteVideoSize = size;
+ } else if (videoView == _localVideoView) {
+ _localVideoSize = size;
+ } else {
+ return;
+ }
+ [self setNeedsUpdateConstraints:YES];
+}
+
+#pragma mark - Private
+
+- (void)setupViews {
+ NSParameterAssert([[self subviews] count] == 0);
+
+ _roomLabel = [[NSTextField alloc] initWithFrame:NSZeroRect];
+ [_roomLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [_roomLabel setBezeled:NO];
+ [_roomLabel setDrawsBackground:NO];
+ [_roomLabel setEditable:NO];
+ [_roomLabel setStringValue:@"Enter AppRTC room id:"];
+ [self addSubview:_roomLabel];
+
+ _roomField = [[NSTextField alloc] initWithFrame:NSZeroRect];
+ [_roomField setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [self addSubview:_roomField];
+ [_roomField setEditable:YES];
+ [_roomField setDelegate:self];
+
+ _logView = [[NSTextView alloc] initWithFrame:NSZeroRect];
+ [_logView setMinSize:NSMakeSize(0, kLogViewHeight)];
+ [_logView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
+ [_logView setVerticallyResizable:YES];
+ [_logView setAutoresizingMask:NSViewWidthSizable];
+ NSTextContainer* textContainer = [_logView textContainer];
+ NSSize containerSize = NSMakeSize(kContentWidth, FLT_MAX);
+ [textContainer setContainerSize:containerSize];
+ [textContainer setWidthTracksTextView:YES];
+ [_logView setEditable:NO];
+
+ _scrollView = [[NSScrollView alloc] initWithFrame:NSZeroRect];
+ [_scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [_scrollView setHasVerticalScroller:YES];
+ [_scrollView setDocumentView:_logView];
+ [self addSubview:_scrollView];
+
+ NSOpenGLPixelFormatAttribute attributes[] = {
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFADepthSize, 24,
+ NSOpenGLPFAOpenGLProfile,
+ NSOpenGLProfileVersion3_2Core,
+ 0
+ };
+ NSOpenGLPixelFormat* pixelFormat =
+ [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
+ _remoteVideoView = [[RTCNSGLVideoView alloc] initWithFrame:NSZeroRect
+ pixelFormat:pixelFormat];
+ [_remoteVideoView setTranslatesAutoresizingMaskIntoConstraints:NO];
+ _remoteVideoView.delegate = self;
+ [self addSubview:_remoteVideoView];
+
+ // TODO(tkchin): create local video view.
+ // https://code.google.com/p/webrtc/issues/detail?id=3417.
+}
+
+- (NSSize)remoteVideoViewSize {
+ if (_remoteVideoSize.width > 0 && _remoteVideoSize.height > 0) {
+ return _remoteVideoSize;
+ } else {
+ return NSMakeSize(kContentWidth, kContentHeight);
+ }
+}
+
+- (NSSize)localVideoViewSize {
+ return NSZeroSize;
+}
+
+@end
+
+@interface APPRTCViewController ()
+ <APPRTCConnectionManagerDelegate, APPRTCMainViewDelegate, APPRTCLogger>
+@property(nonatomic, readonly) APPRTCMainView* mainView;
+@end
+
+@implementation APPRTCViewController {
+ APPRTCConnectionManager* _connectionManager;
+}
+
+- (instancetype)initWithNibName:(NSString*)nibName
+ bundle:(NSBundle*)bundle {
+ if (self = [super initWithNibName:nibName bundle:bundle]) {
+ _connectionManager =
+ [[APPRTCConnectionManager alloc] initWithDelegate:self
+ logger:self];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [self disconnect];
+}
+
+- (void)loadView {
+ APPRTCMainView* view = [[APPRTCMainView alloc] initWithFrame:NSZeroRect];
+ [view setTranslatesAutoresizingMaskIntoConstraints:NO];
+ view.delegate = self;
+ self.view = view;
+}
+
+- (void)windowWillClose:(NSNotification*)notification {
+ [self disconnect];
+}
+
+#pragma mark - APPRTCConnectionManagerDelegate
+
+- (void)connectionManager:(APPRTCConnectionManager*)manager
+ didReceiveLocalVideoTrack:(RTCVideoTrack*)localVideoTrack {
+ self.mainView.localVideoView.videoTrack = localVideoTrack;
+}
+
+- (void)connectionManager:(APPRTCConnectionManager*)manager
+ didReceiveRemoteVideoTrack:(RTCVideoTrack*)remoteVideoTrack {
+ self.mainView.remoteVideoView.videoTrack = remoteVideoTrack;
+}
+
+- (void)connectionManagerDidReceiveHangup:(APPRTCConnectionManager*)manager {
+ [self showAlertWithMessage:@"Remote closed connection"];
+ [self disconnect];
+}
+
+- (void)connectionManager:(APPRTCConnectionManager*)manager
+ didErrorWithMessage:(NSString*)message {
+ [self showAlertWithMessage:message];
+ [self disconnect];
+}
+
+#pragma mark - APPRTCLogger
+
+- (void)logMessage:(NSString*)message {
+ [self.mainView displayLogMessage:message];
+}
+
+#pragma mark - APPRTCMainViewDelegate
+
+- (void)appRTCMainView:(APPRTCMainView*)mainView
+ didEnterRoomId:(NSString*)roomId {
+ NSString* urlString =
+ [NSString stringWithFormat:@"https://apprtc.appspot.com/?r=%@", roomId];
+ [_connectionManager connectToRoomWithURL:[NSURL URLWithString:urlString]];
+}
+
+#pragma mark - Private
+
+- (APPRTCMainView*)mainView {
+ return (APPRTCMainView*)self.view;
+}
+
+- (void)showAlertWithMessage:(NSString*)message {
+ NSAlert* alert = [[NSAlert alloc] init];
+ [alert setMessageText:message];
+ [alert runModal];
+}
+
+- (void)disconnect {
+ self.mainView.remoteVideoView.videoTrack = nil;
+ [_connectionManager disconnect];
+}
+
+@end
diff --git a/talk/examples/objc/AppRTCDemo/mac/Info.plist b/talk/examples/objc/AppRTCDemo/mac/Info.plist
new file mode 100644
index 0000000..4dcb240
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/mac/Info.plist
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.Google.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>${MACOSX_DEPLOYMENT_TARGET}</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
\ No newline at end of file
diff --git a/talk/examples/objc/AppRTCDemo/mac/main.m b/talk/examples/objc/AppRTCDemo/mac/main.m
new file mode 100644
index 0000000..9ce3de2
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/mac/main.m
@@ -0,0 +1,39 @@
+/*
+ * libjingle
+ * Copyright 2014, Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+#import "APPRTCAppDelegate.h"
+
+int main(int argc, char* argv[]) {
+ @autoreleasepool {
+ [NSApplication sharedApplication];
+ APPRTCAppDelegate* delegate = [[APPRTCAppDelegate alloc] init];
+ [NSApp setDelegate:delegate];
+ [NSApp run];
+ }
+}