blob: 8de6f6a12d2a03cbc05936be19ad388ea1aad608 [file] [log] [blame]
tkchin@webrtc.orgef2a5dd2015-01-15 22:38:21 +00001/*
Donald E Curtisa8736442015-08-05 15:48:13 -07002 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
tkchin@webrtc.orgef2a5dd2015-01-15 22:38:21 +00003 *
Donald E Curtisa8736442015-08-05 15:48:13 -07004 * 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.orgef2a5dd2015-01-15 22:38:21 +00009 */
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
haysc913e6452015-10-02 11:44:03 -070035- (void)mainView:(ARDMainView *)mainView
36 didInputRoom:(NSString *)room
37 isLoopback:(BOOL)isLoopback
38 isAudioOnly:(BOOL)isAudioOnly {
tkchin@webrtc.orgef2a5dd2015-01-15 22:38:21 +000039 if (!room.length) {
haysc913e6452015-10-02 11:44:03 -070040 [self showAlertWithMessage:@"Missing room name."];
tkchin@webrtc.orgef2a5dd2015-01-15 22:38:21 +000041 return;
42 }
43 // Trim whitespaces.
44 NSCharacterSet *whitespaceSet = [NSCharacterSet whitespaceCharacterSet];
45 NSString *trimmedRoom = [room stringByTrimmingCharactersInSet:whitespaceSet];
46
47 // Check that room name is valid.
48 NSError *error = nil;
49 NSRegularExpressionOptions options = NSRegularExpressionCaseInsensitive;
50 NSRegularExpression *regex =
51 [NSRegularExpression regularExpressionWithPattern:@"\\w+"
52 options:options
53 error:&error];
54 if (error) {
55 [self showAlertWithMessage:error.localizedDescription];
56 return;
57 }
58 NSRange matchRange =
59 [regex rangeOfFirstMatchInString:trimmedRoom
60 options:0
61 range:NSMakeRange(0, trimmedRoom.length)];
62 if (matchRange.location == NSNotFound ||
63 matchRange.length != trimmedRoom.length) {
64 [self showAlertWithMessage:@"Invalid room name."];
65 return;
66 }
67
68 // Kick off the video call.
69 ARDVideoCallViewController *videoCallViewController =
haysc913e6452015-10-02 11:44:03 -070070 [[ARDVideoCallViewController alloc] initForRoom:trimmedRoom
71 isLoopback:isLoopback
72 isAudioOnly:isAudioOnly];
tkchin@webrtc.orgef2a5dd2015-01-15 22:38:21 +000073 videoCallViewController.modalTransitionStyle =
74 UIModalTransitionStyleCrossDissolve;
75 [self presentViewController:videoCallViewController
76 animated:YES
77 completion:nil];
78}
79
80#pragma mark - Private
81
82- (void)showAlertWithMessage:(NSString*)message {
83 UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil
84 message:message
85 delegate:nil
86 cancelButtonTitle:@"OK"
87 otherButtonTitles:nil];
88 [alertView show];
89}
90
91@end