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

Side by Side Diff: webrtc/examples/objc/AppRTCDemo/ios/ARDMainView.m

Issue 1334003002: Loopback mode for AppRTCDemo on iOS. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add call options header and start call button Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #import "ARDMainView.h" 11 #import "ARDMainView.h"
12 12
13 #import "UIImage+ARDUtilities.h" 13 #import "UIImage+ARDUtilities.h"
14 14
15 // TODO(tkchin): retrieve status bar height dynamically. 15 // TODO(tkchin): retrieve status bar height dynamically.
16 static CGFloat const kStatusBarHeight = 20; 16 static CGFloat const kStatusBarHeight = 20;
17 17
18 static CGFloat const kRoomTextButtonSize = 40; 18 static CGFloat const kRoomTextButtonSize = 40;
19 static CGFloat const kRoomTextFieldHeight = 40; 19 static CGFloat const kRoomTextFieldHeight = 40;
20 static CGFloat const kRoomTextFieldMargin = 8; 20 static CGFloat const kRoomTextFieldMargin = 8;
21 static CGFloat const kCallControlMargin = 8;
21 static CGFloat const kAppLabelHeight = 20; 22 static CGFloat const kAppLabelHeight = 20;
22 23
23 @class ARDRoomTextField; 24 @class ARDRoomTextField;
24 @protocol ARDRoomTextFieldDelegate <NSObject> 25 @protocol ARDRoomTextFieldDelegate <NSObject>
25 - (void)roomTextField:(ARDRoomTextField *)roomTextField 26 - (void)roomTextField:(ARDRoomTextField *)roomTextField
26 didInputRoom:(NSString *)room; 27 didInputRoom:(NSString *)room;
27 @end 28 @end
28 29
29 // Helper view that contains a text field and a clear button. 30 // Helper view that contains a text field and a clear button.
30 @interface ARDRoomTextField : UIView <UITextFieldDelegate> 31 @interface ARDRoomTextField : UIView <UITextFieldDelegate>
31 @property(nonatomic, weak) id<ARDRoomTextFieldDelegate> delegate; 32 @property(nonatomic, weak) id<ARDRoomTextFieldDelegate> delegate;
33 @property(nonatomic, readonly) NSString *roomText;
32 @end 34 @end
33 35
34 @implementation ARDRoomTextField { 36 @implementation ARDRoomTextField {
35 UITextField *_roomText; 37 UITextField *_roomText;
36 UIButton *_clearButton; 38 UIButton *_clearButton;
37 } 39 }
38 40
39 @synthesize delegate = _delegate; 41 @synthesize delegate = _delegate;
40 42
41 - (instancetype)initWithFrame:(CGRect)frame { 43 - (instancetype)initWithFrame:(CGRect)frame {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 CGRectGetMinX(_clearButton.frame) - CGRectGetMinX(bounds) - 83 CGRectGetMinX(_clearButton.frame) - CGRectGetMinX(bounds) -
82 kRoomTextFieldMargin, 84 kRoomTextFieldMargin,
83 kRoomTextFieldHeight); 85 kRoomTextFieldHeight);
84 } 86 }
85 87
86 - (CGSize)sizeThatFits:(CGSize)size { 88 - (CGSize)sizeThatFits:(CGSize)size {
87 size.height = kRoomTextFieldHeight; 89 size.height = kRoomTextFieldHeight;
88 return size; 90 return size;
89 } 91 }
90 92
93 - (NSString *)roomText {
94 return _roomText.text;
95 }
96
91 #pragma mark - UITextFieldDelegate 97 #pragma mark - UITextFieldDelegate
92 98
93 - (void)textFieldDidEndEditing:(UITextField *)textField { 99 - (void)textFieldDidEndEditing:(UITextField *)textField {
94 [_delegate roomTextField:self didInputRoom:textField.text]; 100 [_delegate roomTextField:self didInputRoom:textField.text];
95 } 101 }
96 102
97 - (BOOL)textFieldShouldReturn:(UITextField *)textField { 103 - (BOOL)textFieldShouldReturn:(UITextField *)textField {
98 // There is no other control that can take focus, so manually resign focus 104 // There is no other control that can take focus, so manually resign focus
99 // when return (Join) is pressed to trigger |textFieldDidEndEditing|. 105 // when return (Join) is pressed to trigger |textFieldDidEndEditing|.
100 [textField resignFirstResponder]; 106 [textField resignFirstResponder];
(...skipping 17 matching lines...) Expand all
118 } 124 }
119 125
120 @end 126 @end
121 127
122 @interface ARDMainView () <ARDRoomTextFieldDelegate> 128 @interface ARDMainView () <ARDRoomTextFieldDelegate>
123 @end 129 @end
124 130
125 @implementation ARDMainView { 131 @implementation ARDMainView {
126 UILabel *_appLabel; 132 UILabel *_appLabel;
127 ARDRoomTextField *_roomText; 133 ARDRoomTextField *_roomText;
134 UILabel *_callOptionsLabel;
135 UISwitch *_audioOnlySwitch;
136 UILabel *_audioOnlyLabel;
137 UISwitch *_loopbackSwitch;
138 UILabel *_loopbackLabel;
139 UIButton *_startCallButton;
128 } 140 }
129 141
130 @synthesize delegate = _delegate; 142 @synthesize delegate = _delegate;
131 143
132 - (instancetype)initWithFrame:(CGRect)frame { 144 - (instancetype)initWithFrame:(CGRect)frame {
133 if (self = [super initWithFrame:frame]) { 145 if (self = [super initWithFrame:frame]) {
134 _appLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 146 _appLabel = [[UILabel alloc] initWithFrame:CGRectZero];
135 _appLabel.text = @"AppRTCDemo"; 147 _appLabel.text = @"AppRTCDemo";
136 _appLabel.font = [UIFont fontWithName:@"Roboto" size:34]; 148 _appLabel.font = [UIFont fontWithName:@"Roboto" size:34];
137 _appLabel.textColor = [UIColor colorWithWhite:0 alpha:.2]; 149 _appLabel.textColor = [UIColor colorWithWhite:0 alpha:.2];
138 [_appLabel sizeToFit]; 150 [_appLabel sizeToFit];
139 [self addSubview:_appLabel]; 151 [self addSubview:_appLabel];
140 152
141 _roomText = [[ARDRoomTextField alloc] initWithFrame:CGRectZero]; 153 _roomText = [[ARDRoomTextField alloc] initWithFrame:CGRectZero];
142 _roomText.delegate = self; 154 _roomText.delegate = self;
143 [self addSubview:_roomText]; 155 [self addSubview:_roomText];
144 156
157 UIFont *controlFont = [UIFont fontWithName:@"Roboto" size:20];
158 UIColor *controlFontColor = [UIColor colorWithWhite:0 alpha:.6];
159
160 _callOptionsLabel = [[UILabel alloc] initWithFrame:CGRectZero];
161 _callOptionsLabel.text = @"Call Options";
162 _callOptionsLabel.font = controlFont;
163 _callOptionsLabel.textColor = controlFontColor;
164 [_callOptionsLabel sizeToFit];
165 [self addSubview:_callOptionsLabel];
166
167 _audioOnlySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
168 [_audioOnlySwitch sizeToFit];
169 [self addSubview:_audioOnlySwitch];
170
171 _audioOnlyLabel = [[UILabel alloc] initWithFrame:CGRectZero];
172 _audioOnlyLabel.text = @"Audio only";
173 _audioOnlyLabel.font = controlFont;
174 _audioOnlyLabel.textColor = controlFontColor;
175 [_audioOnlyLabel sizeToFit];
176 [self addSubview:_audioOnlyLabel];
177
178 _loopbackSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
179 [_loopbackSwitch sizeToFit];
180 [self addSubview:_loopbackSwitch];
181
182 _loopbackLabel = [[UILabel alloc] initWithFrame:CGRectZero];
183 _loopbackLabel.text = @"Loopback mode";
184 _loopbackLabel.font = controlFont;
185 _loopbackLabel.textColor = controlFontColor;
186 [_loopbackLabel sizeToFit];
187 [self addSubview:_loopbackLabel];
188
189 _startCallButton = [[UIButton alloc] initWithFrame:CGRectZero];
tkchin_webrtc 2015/10/01 20:11:01 nits: make it look like a button: _startCallB
Chuck 2015/10/02 14:27:08 Done.
190 [_startCallButton setTitle:@"Start call"
191 forState:UIControlStateNormal];
192 _startCallButton.titleLabel.font = controlFont;
193 [_startCallButton setTitleColor:controlFontColor
194 forState:UIControlStateNormal];
195 [_startCallButton sizeToFit];
196 [_startCallButton addTarget:self
197 action:@selector(onStartCall:)
198 forControlEvents:UIControlEventTouchUpInside];
199 [self addSubview:_startCallButton];
200
145 self.backgroundColor = [UIColor whiteColor]; 201 self.backgroundColor = [UIColor whiteColor];
146 } 202 }
147 return self; 203 return self;
148 } 204 }
149 205
150 - (void)layoutSubviews { 206 - (void)layoutSubviews {
151 CGRect bounds = self.bounds; 207 CGRect bounds = self.bounds;
152 CGFloat roomTextWidth = bounds.size.width - 2 * kRoomTextFieldMargin; 208 CGFloat roomTextWidth = bounds.size.width - 2 * kRoomTextFieldMargin;
153 CGFloat roomTextHeight = [_roomText sizeThatFits:bounds.size].height; 209 CGFloat roomTextHeight = [_roomText sizeThatFits:bounds.size].height;
154 _roomText.frame = CGRectMake(kRoomTextFieldMargin, 210 _roomText.frame = CGRectMake(kRoomTextFieldMargin,
155 kStatusBarHeight + kRoomTextFieldMargin, 211 kStatusBarHeight + kRoomTextFieldMargin,
156 roomTextWidth, 212 roomTextWidth,
157 roomTextHeight); 213 roomTextHeight);
158 _appLabel.center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); 214 _appLabel.center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
215
216 CGFloat callOptionsLabelTop =
217 CGRectGetMaxY(_roomText.frame) + kCallControlMargin * 4;
218 _callOptionsLabel.frame = CGRectMake(kCallControlMargin,
219 callOptionsLabelTop,
220 _callOptionsLabel.frame.size.width,
221 _callOptionsLabel.frame.size.height);
222
223 CGFloat audioOnlyTop =
224 CGRectGetMaxY(_callOptionsLabel.frame) + kCallControlMargin * 2;
225 CGRect audioOnlyRect = CGRectMake(kCallControlMargin * 3,
226 audioOnlyTop,
tkchin_webrtc 2015/10/01 20:11:01 align args
Chuck 2015/10/02 14:27:08 Done.
227 _audioOnlySwitch.frame.size.width,
228 _audioOnlySwitch.frame.size.height);
229 _audioOnlySwitch.frame = audioOnlyRect;
230 CGFloat audioOnlyLabelCenterX = CGRectGetMaxX(audioOnlyRect) +
231 kCallControlMargin + _audioOnlyLabel.frame.size.width / 2;
232 _audioOnlyLabel.center = CGPointMake(audioOnlyLabelCenterX,
233 CGRectGetMidY(audioOnlyRect));
234
235 CGFloat loopbackModeTop =
236 CGRectGetMaxY(_audioOnlySwitch.frame) + kCallControlMargin;
237 CGRect loopbackModeRect = CGRectMake(kCallControlMargin * 3,
238 loopbackModeTop,
239 _loopbackSwitch.frame.size.width,
240 _loopbackSwitch.frame.size.height);
241 _loopbackSwitch.frame = loopbackModeRect;
242 CGFloat loopbackModeLabelCenterX = CGRectGetMaxX(loopbackModeRect) +
243 kCallControlMargin + _loopbackLabel.frame.size.width / 2;
244 _loopbackLabel.center = CGPointMake(loopbackModeLabelCenterX,
245 CGRectGetMidY(loopbackModeRect));
246
247 CGFloat startCallTop =
248 CGRectGetMaxY(loopbackModeRect) + kCallControlMargin * 3;
249 _startCallButton.frame = CGRectMake(kCallControlMargin * 4,
tkchin_webrtc 2015/10/01 20:11:01 nit: align button to left, and align args. _sta
Chuck 2015/10/02 14:27:08 Done.
250 startCallTop,
251 _startCallButton.frame.size.width,
252 _startCallButton.frame.size.height);
159 } 253 }
160 254
161 #pragma mark - ARDRoomTextFieldDelegate 255 #pragma mark - ARDRoomTextFieldDelegate
162 256
163 - (void)roomTextField:(ARDRoomTextField *)roomTextField 257 - (void)roomTextField:(ARDRoomTextField *)roomTextField
164 didInputRoom:(NSString *)room { 258 didInputRoom:(NSString *)room {
165 [_delegate mainView:self didInputRoom:room]; 259 [_delegate mainView:self
260 didInputRoom:room
261 isLoopback:NO
262 isAudioOnly:_audioOnlySwitch.isOn];
263 }
264
265 #pragma mark - Private
266
267 - (void)onStartCall:(id)sender {
268 NSString *room = _roomText.roomText;
269 // If this is a loopback call, allow a generated room name.
270 if (!room.length && _loopbackSwitch.isOn) {
271 room = [[NSUUID UUID] UUIDString];
272 }
273 room = [room stringByReplacingOccurrencesOfString:@"-" withString:@""];
274 [_delegate mainView:self
275 didInputRoom:room
276 isLoopback:_loopbackSwitch.isOn
277 isAudioOnly:_audioOnlySwitch.isOn];
166 } 278 }
167 279
168 @end 280 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698