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