Home | History | Annotate | Download | only in AppRTCDemo
      1 /*
      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 
     36 - (void)viewDidLoad {
     37   [super viewDidLoad];
     38   self.textField.delegate = self;
     39 }
     40 
     41 - (void)displayText:(NSString *)text {
     42   dispatch_async(dispatch_get_main_queue(), ^(void) {
     43     NSString *output =
     44         [NSString stringWithFormat:@"%@\n%@", self.textOutput.text, text];
     45     self.textOutput.text = output;
     46   });
     47 }
     48 
     49 - (void)resetUI {
     50   self.textField.text = nil;
     51   self.textField.hidden = NO;
     52   self.textInstructions.hidden = NO;
     53   self.textOutput.hidden = YES;
     54   self.textOutput.text = nil;
     55 }
     56 
     57 #pragma mark - UITextFieldDelegate
     58 
     59 - (void)textFieldDidEndEditing:(UITextField *)textField {
     60   NSString *room = textField.text;
     61   if ([room length] == 0) {
     62     return;
     63   }
     64   textField.hidden = YES;
     65   self.textInstructions.hidden = YES;
     66   self.textOutput.hidden = NO;
     67   // TODO(hughv): Instead of launching a URL with apprtc scheme, change to
     68   // prepopulating the textField with a valid URL missing the room.  This allows
     69   // the user to have the simplicity of just entering the room or the ability to
     70   // override to a custom appspot instance.  Remove apprtc:// when this is done.
     71   NSString *url =
     72       [NSString stringWithFormat:@"apprtc://apprtc.appspot.com/?r=%@", room];
     73   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
     74 }
     75 
     76 - (BOOL)textFieldShouldReturn:(UITextField *)textField {
     77   // There is no other control that can take focus, so manually resign focus
     78   // when return (Join) is pressed to trigger |textFieldDidEndEditing|.
     79   [textField resignFirstResponder];
     80   return YES;
     81 }
     82 
     83 @end
     84