blob: bd346efcd3a710c56c1b265e7e049f7c3b5ca35c [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2013, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#import "APPRTCViewController.h"
29
30@interface APPRTCViewController ()
31
32@end
33
34@implementation APPRTCViewController
35
fischman@webrtc.org9ca93a82013-10-29 00:14:15 +000036@synthesize textField = _textField;
37@synthesize textInstructions = _textInstructions;
38@synthesize textOutput = _textOutput;
39
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040- (void)viewDidLoad {
41 [super viewDidLoad];
42 self.textField.delegate = self;
fischman@webrtc.orgc31d4d02013-09-05 21:49:58 +000043 [self.textField becomeFirstResponder];
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044}
45
46- (void)displayText:(NSString *)text {
47 dispatch_async(dispatch_get_main_queue(), ^(void) {
48 NSString *output =
49 [NSString stringWithFormat:@"%@\n%@", self.textOutput.text, text];
50 self.textOutput.text = output;
51 });
52}
53
54- (void)resetUI {
55 self.textField.text = nil;
56 self.textField.hidden = NO;
57 self.textInstructions.hidden = NO;
58 self.textOutput.hidden = YES;
59 self.textOutput.text = nil;
60}
61
62#pragma mark - UITextFieldDelegate
63
64- (void)textFieldDidEndEditing:(UITextField *)textField {
65 NSString *room = textField.text;
66 if ([room length] == 0) {
67 return;
68 }
69 textField.hidden = YES;
70 self.textInstructions.hidden = YES;
71 self.textOutput.hidden = NO;
72 // TODO(hughv): Instead of launching a URL with apprtc scheme, change to
73 // prepopulating the textField with a valid URL missing the room. This allows
74 // the user to have the simplicity of just entering the room or the ability to
75 // override to a custom appspot instance. Remove apprtc:// when this is done.
76 NSString *url =
77 [NSString stringWithFormat:@"apprtc://apprtc.appspot.com/?r=%@", room];
78 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
79}
80
81- (BOOL)textFieldShouldReturn:(UITextField *)textField {
82 // There is no other control that can take focus, so manually resign focus
83 // when return (Join) is pressed to trigger |textFieldDidEndEditing|.
84 [textField resignFirstResponder];
85 return YES;
86}
87
88@end