tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 1 | /* |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 2 | * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 3 | * |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #import "APPRTCViewController.h" |
| 12 | |
| 13 | #import <AVFoundation/AVFoundation.h> |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 14 | |
denicija | 124a6fc | 2017-03-31 02:47:29 -0700 | [diff] [blame] | 15 | #import "WebRTC/RTCMTLNSVideoView.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 16 | #import "WebRTC/RTCNSGLVideoView.h" |
| 17 | #import "WebRTC/RTCVideoTrack.h" |
hjon | 79858f8 | 2016-03-13 22:08:26 -0700 | [diff] [blame] | 18 | |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 19 | #import "ARDAppClient.h" |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 20 | #import "ARDCaptureController.h" |
sakal | c4adacf | 2017-03-28 01:22:48 -0700 | [diff] [blame] | 21 | #import "ARDSettingsModel.h" |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 22 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 23 | static NSUInteger const kContentWidth = 900; |
| 24 | static NSUInteger const kRoomFieldWidth = 200; |
| 25 | static NSUInteger const kActionItemHeight = 30; |
| 26 | static NSUInteger const kBottomViewHeight = 200; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 27 | |
| 28 | @class APPRTCMainView; |
| 29 | @protocol APPRTCMainViewDelegate |
| 30 | |
| 31 | - (void)appRTCMainView:(APPRTCMainView*)mainView |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 32 | didEnterRoomId:(NSString*)roomId |
| 33 | loopback:(BOOL)isLoopback; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 34 | |
| 35 | @end |
| 36 | |
| 37 | @interface APPRTCMainView : NSView |
| 38 | |
| 39 | @property(nonatomic, weak) id<APPRTCMainViewDelegate> delegate; |
denicija | 124a6fc | 2017-03-31 02:47:29 -0700 | [diff] [blame] | 40 | @property(nonatomic, readonly) NSView<RTCVideoRenderer>* localVideoView; |
| 41 | @property(nonatomic, readonly) NSView<RTCVideoRenderer>* remoteVideoView; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 42 | |
| 43 | - (void)displayLogMessage:(NSString*)message; |
| 44 | |
| 45 | @end |
| 46 | |
| 47 | @interface APPRTCMainView () <NSTextFieldDelegate, RTCNSGLVideoViewDelegate> |
| 48 | @end |
| 49 | @implementation APPRTCMainView { |
| 50 | NSScrollView* _scrollView; |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 51 | NSView* _actionItemsView; |
| 52 | NSButton* _connectButton; |
| 53 | NSButton* _loopbackButton; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 54 | NSTextField* _roomField; |
| 55 | NSTextView* _logView; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 56 | CGSize _localVideoSize; |
| 57 | CGSize _remoteVideoSize; |
| 58 | } |
| 59 | |
tkchin | 2ddfdba | 2016-08-07 21:37:45 -0700 | [diff] [blame] | 60 | @synthesize delegate = _delegate; |
| 61 | @synthesize localVideoView = _localVideoView; |
| 62 | @synthesize remoteVideoView = _remoteVideoView; |
| 63 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 64 | |
| 65 | - (void)displayLogMessage:(NSString *)message { |
| 66 | _logView.string = |
| 67 | [NSString stringWithFormat:@"%@%@\n", _logView.string, message]; |
| 68 | NSRange range = NSMakeRange(_logView.string.length, 0); |
| 69 | [_logView scrollRangeToVisible:range]; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 70 | } |
| 71 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 72 | #pragma mark - Private |
| 73 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 74 | - (instancetype)initWithFrame:(NSRect)frame { |
| 75 | if (self = [super initWithFrame:frame]) { |
| 76 | [self setupViews]; |
| 77 | } |
| 78 | return self; |
| 79 | } |
| 80 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 81 | + (BOOL)requiresConstraintBasedLayout { |
| 82 | return YES; |
| 83 | } |
| 84 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 85 | - (void)updateConstraints { |
| 86 | NSParameterAssert( |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 87 | _roomField != nil && |
| 88 | _scrollView != nil && |
| 89 | _remoteVideoView != nil && |
| 90 | _localVideoView != nil && |
| 91 | _actionItemsView!= nil && |
| 92 | _connectButton != nil && |
| 93 | _loopbackButton != nil); |
| 94 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 95 | [self removeConstraints:[self constraints]]; |
| 96 | NSDictionary* viewsDictionary = |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 97 | NSDictionaryOfVariableBindings(_roomField, |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 98 | _scrollView, |
kthelgason | 314bc5f | 2016-08-31 10:23:27 -0700 | [diff] [blame] | 99 | _remoteVideoView, |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 100 | _localVideoView, |
| 101 | _actionItemsView, |
| 102 | _connectButton, |
| 103 | _loopbackButton); |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 104 | |
| 105 | NSSize remoteViewSize = [self remoteVideoViewSize]; |
| 106 | NSDictionary* metrics = @{ |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 107 | @"remoteViewWidth" : @(remoteViewSize.width), |
| 108 | @"remoteViewHeight" : @(remoteViewSize.height), |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 109 | @"kBottomViewHeight" : @(kBottomViewHeight), |
| 110 | @"localViewHeight" : @(remoteViewSize.height / 3), |
| 111 | @"localViewWidth" : @(remoteViewSize.width / 3), |
| 112 | @"kRoomFieldWidth" : @(kRoomFieldWidth), |
| 113 | @"kActionItemHeight" : @(kActionItemHeight) |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 114 | }; |
| 115 | // Declare this separately to avoid compiler warning about splitting string |
| 116 | // within an NSArray expression. |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 117 | NSString* verticalConstraintLeft = |
| 118 | @"V:|-[_remoteVideoView(remoteViewHeight)]-[_scrollView(kBottomViewHeight)]-|"; |
| 119 | NSString* verticalConstraintRight = |
| 120 | @"V:|-[_remoteVideoView(remoteViewHeight)]-[_actionItemsView(kBottomViewHeight)]-|"; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 121 | NSArray* constraintFormats = @[ |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 122 | verticalConstraintLeft, |
| 123 | verticalConstraintRight, |
| 124 | @"H:|-[_remoteVideoView(remoteViewWidth)]-|", |
| 125 | @"V:|-[_localVideoView(localViewHeight)]", |
| 126 | @"H:|-[_localVideoView(localViewWidth)]", |
| 127 | @"H:|-[_scrollView(==_actionItemsView)]-[_actionItemsView]-|" |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 128 | ]; |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 129 | |
| 130 | NSArray* actionItemsConstraints = @[ |
| 131 | @"H:|-[_roomField(kRoomFieldWidth)]-[_loopbackButton(kRoomFieldWidth)]", |
| 132 | @"H:|-[_connectButton(kRoomFieldWidth)]", |
| 133 | @"V:|-[_roomField(kActionItemHeight)]-[_connectButton(kActionItemHeight)]", |
| 134 | @"V:|-[_loopbackButton(kActionItemHeight)]", |
| 135 | ]; |
| 136 | |
| 137 | [APPRTCMainView addConstraints:constraintFormats |
| 138 | toView:self |
| 139 | viewsDictionary:viewsDictionary |
| 140 | metrics:metrics]; |
| 141 | [APPRTCMainView addConstraints:actionItemsConstraints |
| 142 | toView:_actionItemsView |
| 143 | viewsDictionary:viewsDictionary |
| 144 | metrics:metrics]; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 145 | [super updateConstraints]; |
| 146 | } |
| 147 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 148 | #pragma mark - Constraints helper |
| 149 | |
| 150 | + (void)addConstraints:(NSArray*)constraints toView:(NSView*)view |
| 151 | viewsDictionary:(NSDictionary*)viewsDictionary |
| 152 | metrics:(NSDictionary*)metrics { |
| 153 | for (NSString* constraintFormat in constraints) { |
| 154 | NSArray* constraints = |
| 155 | [NSLayoutConstraint constraintsWithVisualFormat:constraintFormat |
| 156 | options:0 |
| 157 | metrics:metrics |
| 158 | views:viewsDictionary]; |
| 159 | for (NSLayoutConstraint* constraint in constraints) { |
| 160 | [view addConstraint:constraint]; |
| 161 | } |
| 162 | } |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 163 | } |
| 164 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 165 | #pragma mark - Control actions |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 166 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 167 | - (void)startCall:(id)sender { |
| 168 | NSString* roomString = _roomField.stringValue; |
| 169 | // Generate room id for loopback options. |
| 170 | if (_loopbackButton.intValue && [roomString isEqualToString:@""]) { |
| 171 | roomString = [NSUUID UUID].UUIDString; |
| 172 | roomString = [roomString stringByReplacingOccurrencesOfString:@"-" withString:@""]; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 173 | } |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 174 | [self.delegate appRTCMainView:self |
| 175 | didEnterRoomId:roomString |
| 176 | loopback:_loopbackButton.intValue]; |
denicija | 124a6fc | 2017-03-31 02:47:29 -0700 | [diff] [blame] | 177 | [self setNeedsUpdateConstraints:YES]; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | #pragma mark - RTCNSGLVideoViewDelegate |
| 181 | |
| 182 | - (void)videoView:(RTCNSGLVideoView*)videoView |
| 183 | didChangeVideoSize:(NSSize)size { |
| 184 | if (videoView == _remoteVideoView) { |
| 185 | _remoteVideoSize = size; |
| 186 | } else if (videoView == _localVideoView) { |
| 187 | _localVideoSize = size; |
| 188 | } else { |
| 189 | return; |
| 190 | } |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 191 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 192 | [self setNeedsUpdateConstraints:YES]; |
| 193 | } |
| 194 | |
| 195 | #pragma mark - Private |
| 196 | |
| 197 | - (void)setupViews { |
| 198 | NSParameterAssert([[self subviews] count] == 0); |
| 199 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 200 | _logView = [[NSTextView alloc] initWithFrame:NSZeroRect]; |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 201 | [_logView setMinSize:NSMakeSize(0, kBottomViewHeight)]; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 202 | [_logView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)]; |
| 203 | [_logView setVerticallyResizable:YES]; |
| 204 | [_logView setAutoresizingMask:NSViewWidthSizable]; |
| 205 | NSTextContainer* textContainer = [_logView textContainer]; |
| 206 | NSSize containerSize = NSMakeSize(kContentWidth, FLT_MAX); |
| 207 | [textContainer setContainerSize:containerSize]; |
| 208 | [textContainer setWidthTracksTextView:YES]; |
| 209 | [_logView setEditable:NO]; |
| 210 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 211 | [self setupActionItemsView]; |
| 212 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 213 | _scrollView = [[NSScrollView alloc] initWithFrame:NSZeroRect]; |
| 214 | [_scrollView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 215 | [_scrollView setHasVerticalScroller:YES]; |
| 216 | [_scrollView setDocumentView:_logView]; |
| 217 | [self addSubview:_scrollView]; |
| 218 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 219 | |
denicija | 124a6fc | 2017-03-31 02:47:29 -0700 | [diff] [blame] | 220 | // NOTE (daniela): Ignoring Clang diagonstic here. |
| 221 | // We're performing run time check to make sure class is available on runtime. |
| 222 | // If not we're providing sensible default. |
| 223 | #pragma clang diagnostic push |
| 224 | #pragma clang diagnostic ignored "-Wpartial-availability" |
| 225 | if ([RTCMTLNSVideoView class]) { |
| 226 | _remoteVideoView = [[RTCMTLNSVideoView alloc] initWithFrame:NSZeroRect]; |
| 227 | _localVideoView = [[RTCMTLNSVideoView alloc] initWithFrame:NSZeroRect]; |
| 228 | } else { |
| 229 | NSOpenGLPixelFormatAttribute attributes[] = { |
| 230 | NSOpenGLPFADoubleBuffer, |
| 231 | NSOpenGLPFADepthSize, 24, |
| 232 | NSOpenGLPFAOpenGLProfile, |
| 233 | NSOpenGLProfileVersion3_2Core, |
| 234 | 0 |
| 235 | }; |
| 236 | NSOpenGLPixelFormat* pixelFormat = |
| 237 | [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; |
| 238 | |
| 239 | RTCNSGLVideoView* remote = |
| 240 | [[RTCNSGLVideoView alloc] initWithFrame:NSZeroRect pixelFormat:pixelFormat]; |
| 241 | remote.delegate = self; |
| 242 | _remoteVideoView = remote; |
| 243 | |
| 244 | RTCNSGLVideoView* local = |
| 245 | [[RTCNSGLVideoView alloc] initWithFrame:NSZeroRect pixelFormat:pixelFormat]; |
| 246 | local.delegate = self; |
| 247 | _localVideoView = local; |
| 248 | } |
| 249 | #pragma clang diagnostic pop |
| 250 | |
| 251 | [_remoteVideoView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 252 | [self addSubview:_remoteVideoView]; |
kthelgason | 314bc5f | 2016-08-31 10:23:27 -0700 | [diff] [blame] | 253 | [_localVideoView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
kthelgason | 314bc5f | 2016-08-31 10:23:27 -0700 | [diff] [blame] | 254 | [self addSubview:_localVideoView]; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 255 | } |
| 256 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 257 | - (void)setupActionItemsView { |
| 258 | _actionItemsView = [[NSView alloc] initWithFrame:NSZeroRect]; |
| 259 | [_actionItemsView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 260 | [self addSubview:_actionItemsView]; |
| 261 | |
| 262 | _roomField = [[NSTextField alloc] initWithFrame:NSZeroRect]; |
| 263 | [_roomField setTranslatesAutoresizingMaskIntoConstraints:NO]; |
magjed | a445b9b | 2017-02-20 07:56:53 -0800 | [diff] [blame] | 264 | [[_roomField cell] setPlaceholderString: @"Enter AppRTC room id"]; |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 265 | [_actionItemsView addSubview:_roomField]; |
| 266 | [_roomField setEditable:YES]; |
| 267 | |
| 268 | _connectButton = [[NSButton alloc] initWithFrame:NSZeroRect]; |
| 269 | [_connectButton setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 270 | _connectButton.title = @"Start call"; |
| 271 | _connectButton.bezelStyle = NSRoundedBezelStyle; |
| 272 | _connectButton.target = self; |
| 273 | _connectButton.action = @selector(startCall:); |
| 274 | [_actionItemsView addSubview:_connectButton]; |
| 275 | |
| 276 | _loopbackButton = [[NSButton alloc] initWithFrame:NSZeroRect]; |
| 277 | [_loopbackButton setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 278 | _loopbackButton.title = @"Loopback"; |
| 279 | [_loopbackButton setButtonType:NSSwitchButton]; |
| 280 | [_actionItemsView addSubview:_loopbackButton]; |
| 281 | } |
| 282 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 283 | - (NSSize)remoteVideoViewSize { |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 284 | if (!_remoteVideoView.bounds.size.width) { |
| 285 | return NSMakeSize(kContentWidth, 0); |
| 286 | } |
| 287 | NSInteger width = MAX(_remoteVideoView.bounds.size.width, kContentWidth); |
kthelgason | 314bc5f | 2016-08-31 10:23:27 -0700 | [diff] [blame] | 288 | NSInteger height = (width/16) * 9; |
| 289 | return NSMakeSize(width, height); |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | @end |
| 293 | |
| 294 | @interface APPRTCViewController () |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 295 | <ARDAppClientDelegate, APPRTCMainViewDelegate> |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 296 | @property(nonatomic, readonly) APPRTCMainView* mainView; |
| 297 | @end |
| 298 | |
| 299 | @implementation APPRTCViewController { |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 300 | ARDAppClient* _client; |
tkchin@webrtc.org | 8125744 | 2014-11-04 23:06:15 +0000 | [diff] [blame] | 301 | RTCVideoTrack* _localVideoTrack; |
| 302 | RTCVideoTrack* _remoteVideoTrack; |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 303 | ARDCaptureController* _captureController; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 304 | } |
| 305 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 306 | - (void)dealloc { |
| 307 | [self disconnect]; |
| 308 | } |
| 309 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 310 | - (void)viewDidAppear { |
| 311 | [super viewDidAppear]; |
| 312 | [self displayUsageInstructions]; |
| 313 | } |
| 314 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 315 | - (void)loadView { |
| 316 | APPRTCMainView* view = [[APPRTCMainView alloc] initWithFrame:NSZeroRect]; |
| 317 | [view setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 318 | view.delegate = self; |
| 319 | self.view = view; |
| 320 | } |
| 321 | |
| 322 | - (void)windowWillClose:(NSNotification*)notification { |
| 323 | [self disconnect]; |
| 324 | } |
| 325 | |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 326 | #pragma mark - Usage |
| 327 | |
| 328 | - (void)displayUsageInstructions { |
| 329 | [self.mainView displayLogMessage: |
| 330 | @"To start call:\n" |
| 331 | @"• Enter AppRTC room id (not neccessary for loopback)\n" |
| 332 | @"• Start call"]; |
| 333 | } |
| 334 | |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 335 | #pragma mark - ARDAppClientDelegate |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 336 | |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 337 | - (void)appClient:(ARDAppClient *)client |
| 338 | didChangeState:(ARDAppClientState)state { |
| 339 | switch (state) { |
| 340 | case kARDAppClientStateConnected: |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 341 | [self.mainView displayLogMessage:@"Client connected."]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 342 | break; |
| 343 | case kARDAppClientStateConnecting: |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 344 | [self.mainView displayLogMessage:@"Client connecting."]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 345 | break; |
| 346 | case kARDAppClientStateDisconnected: |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 347 | [self.mainView displayLogMessage:@"Client disconnected."]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 348 | [self resetUI]; |
| 349 | _client = nil; |
| 350 | break; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | - (void)appClient:(ARDAppClient *)client |
hjon | 79858f8 | 2016-03-13 22:08:26 -0700 | [diff] [blame] | 355 | didChangeConnectionState:(RTCIceConnectionState)state { |
tkchin@webrtc.org | 3a63a3c | 2015-01-06 07:21:34 +0000 | [diff] [blame] | 356 | } |
| 357 | |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 358 | - (void)appClient:(ARDAppClient*)client |
| 359 | didCreateLocalCapturer:(RTCCameraVideoCapturer*)localCapturer { |
| 360 | _captureController = |
| 361 | [[ARDCaptureController alloc] initWithCapturer:localCapturer |
| 362 | settings:[[ARDSettingsModel alloc] init]]; |
| 363 | [_captureController startCapture]; |
| 364 | } |
| 365 | |
tkchin@webrtc.org | 3a63a3c | 2015-01-06 07:21:34 +0000 | [diff] [blame] | 366 | - (void)appClient:(ARDAppClient *)client |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 367 | didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack { |
tkchin@webrtc.org | 8125744 | 2014-11-04 23:06:15 +0000 | [diff] [blame] | 368 | _localVideoTrack = localVideoTrack; |
kthelgason | 314bc5f | 2016-08-31 10:23:27 -0700 | [diff] [blame] | 369 | [_localVideoTrack addRenderer:self.mainView.localVideoView]; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 370 | } |
| 371 | |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 372 | - (void)appClient:(ARDAppClient *)client |
| 373 | didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { |
tkchin@webrtc.org | 8125744 | 2014-11-04 23:06:15 +0000 | [diff] [blame] | 374 | _remoteVideoTrack = remoteVideoTrack; |
| 375 | [_remoteVideoTrack addRenderer:self.mainView.remoteVideoView]; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 376 | } |
| 377 | |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 378 | - (void)appClient:(ARDAppClient *)client |
| 379 | didError:(NSError *)error { |
| 380 | [self showAlertWithMessage:[NSString stringWithFormat:@"%@", error]]; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 381 | [self disconnect]; |
| 382 | } |
| 383 | |
Zeke Chin | d332580 | 2015-08-14 11:00:02 -0700 | [diff] [blame] | 384 | - (void)appClient:(ARDAppClient *)client |
| 385 | didGetStats:(NSArray *)stats { |
| 386 | } |
| 387 | |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 388 | #pragma mark - APPRTCMainViewDelegate |
| 389 | |
| 390 | - (void)appRTCMainView:(APPRTCMainView*)mainView |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 391 | didEnterRoomId:(NSString*)roomId |
| 392 | loopback:(BOOL)isLoopback { |
| 393 | |
| 394 | if ([roomId isEqualToString:@""]) { |
| 395 | [self.mainView displayLogMessage:@"Missing room id"]; |
| 396 | return; |
| 397 | } |
| 398 | |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 399 | [self disconnect]; |
sakal | c4adacf | 2017-03-28 01:22:48 -0700 | [diff] [blame] | 400 | ARDAppClient* client = [[ARDAppClient alloc] initWithDelegate:self]; |
tkchin | ab1293a | 2016-08-30 12:35:05 -0700 | [diff] [blame] | 401 | [client connectToRoomWithId:roomId |
sakal | c4adacf | 2017-03-28 01:22:48 -0700 | [diff] [blame] | 402 | settings:[[ARDSettingsModel alloc] init] // Use default settings. |
denicija | 647915f | 2016-10-20 01:46:41 -0700 | [diff] [blame] | 403 | isLoopback:isLoopback |
tkchin | ab1293a | 2016-08-30 12:35:05 -0700 | [diff] [blame] | 404 | isAudioOnly:NO |
| 405 | shouldMakeAecDump:NO |
| 406 | shouldUseLevelControl:NO]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 407 | _client = client; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | #pragma mark - Private |
| 411 | |
| 412 | - (APPRTCMainView*)mainView { |
| 413 | return (APPRTCMainView*)self.view; |
| 414 | } |
| 415 | |
| 416 | - (void)showAlertWithMessage:(NSString*)message { |
| 417 | NSAlert* alert = [[NSAlert alloc] init]; |
| 418 | [alert setMessageText:message]; |
| 419 | [alert runModal]; |
| 420 | } |
| 421 | |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 422 | - (void)resetUI { |
tkchin@webrtc.org | 8125744 | 2014-11-04 23:06:15 +0000 | [diff] [blame] | 423 | [_remoteVideoTrack removeRenderer:self.mainView.remoteVideoView]; |
kthelgason | 314bc5f | 2016-08-31 10:23:27 -0700 | [diff] [blame] | 424 | [_localVideoTrack removeRenderer:self.mainView.localVideoView]; |
tkchin@webrtc.org | 8125744 | 2014-11-04 23:06:15 +0000 | [diff] [blame] | 425 | _remoteVideoTrack = nil; |
kthelgason | 314bc5f | 2016-08-31 10:23:27 -0700 | [diff] [blame] | 426 | _localVideoTrack = nil; |
tkchin@webrtc.org | 8125744 | 2014-11-04 23:06:15 +0000 | [diff] [blame] | 427 | [self.mainView.remoteVideoView renderFrame:nil]; |
kthelgason | 314bc5f | 2016-08-31 10:23:27 -0700 | [diff] [blame] | 428 | [self.mainView.localVideoView renderFrame:nil]; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | - (void)disconnect { |
| 432 | [self resetUI]; |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 433 | [_captureController stopCapture]; |
| 434 | _captureController = nil; |
tkchin@webrtc.org | 87776a8 | 2014-12-09 19:32:35 +0000 | [diff] [blame] | 435 | [_client disconnect]; |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | @end |