tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 1 | /* |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame^] | 2 | * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +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 | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #import "ARDMainViewController.h" |
| 12 | |
| 13 | #import "ARDAppClient.h" |
| 14 | #import "ARDMainView.h" |
| 15 | #import "ARDVideoCallViewController.h" |
| 16 | |
| 17 | @interface ARDMainViewController () <ARDMainViewDelegate> |
| 18 | @end |
| 19 | |
| 20 | @implementation ARDMainViewController |
| 21 | |
| 22 | - (void)loadView { |
| 23 | ARDMainView *mainView = [[ARDMainView alloc] initWithFrame:CGRectZero]; |
| 24 | mainView.delegate = self; |
| 25 | self.view = mainView; |
| 26 | } |
| 27 | |
| 28 | - (void)applicationWillResignActive:(UIApplication *)application { |
| 29 | // Terminate any calls when we aren't active. |
| 30 | [self dismissViewControllerAnimated:NO completion:nil]; |
| 31 | } |
| 32 | |
| 33 | #pragma mark - ARDMainViewDelegate |
| 34 | |
| 35 | - (void)mainView:(ARDMainView *)mainView didInputRoom:(NSString *)room { |
| 36 | if (!room.length) { |
| 37 | return; |
| 38 | } |
| 39 | // Trim whitespaces. |
| 40 | NSCharacterSet *whitespaceSet = [NSCharacterSet whitespaceCharacterSet]; |
| 41 | NSString *trimmedRoom = [room stringByTrimmingCharactersInSet:whitespaceSet]; |
| 42 | |
| 43 | // Check that room name is valid. |
| 44 | NSError *error = nil; |
| 45 | NSRegularExpressionOptions options = NSRegularExpressionCaseInsensitive; |
| 46 | NSRegularExpression *regex = |
| 47 | [NSRegularExpression regularExpressionWithPattern:@"\\w+" |
| 48 | options:options |
| 49 | error:&error]; |
| 50 | if (error) { |
| 51 | [self showAlertWithMessage:error.localizedDescription]; |
| 52 | return; |
| 53 | } |
| 54 | NSRange matchRange = |
| 55 | [regex rangeOfFirstMatchInString:trimmedRoom |
| 56 | options:0 |
| 57 | range:NSMakeRange(0, trimmedRoom.length)]; |
| 58 | if (matchRange.location == NSNotFound || |
| 59 | matchRange.length != trimmedRoom.length) { |
| 60 | [self showAlertWithMessage:@"Invalid room name."]; |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | // Kick off the video call. |
| 65 | ARDVideoCallViewController *videoCallViewController = |
| 66 | [[ARDVideoCallViewController alloc] initForRoom:trimmedRoom]; |
| 67 | videoCallViewController.modalTransitionStyle = |
| 68 | UIModalTransitionStyleCrossDissolve; |
| 69 | [self presentViewController:videoCallViewController |
| 70 | animated:YES |
| 71 | completion:nil]; |
| 72 | } |
| 73 | |
| 74 | #pragma mark - Private |
| 75 | |
| 76 | - (void)showAlertWithMessage:(NSString*)message { |
| 77 | UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil |
| 78 | message:message |
| 79 | delegate:nil |
| 80 | cancelButtonTitle:@"OK" |
| 81 | otherButtonTitles:nil]; |
| 82 | [alertView show]; |
| 83 | } |
| 84 | |
| 85 | @end |