• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 *  Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 *
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.
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
36    didInputRoom:(NSString *)room
37      isLoopback:(BOOL)isLoopback
38     isAudioOnly:(BOOL)isAudioOnly {
39  if (!room.length) {
40    [self showAlertWithMessage:@"Missing room name."];
41    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 =
70      [[ARDVideoCallViewController alloc] initForRoom:trimmedRoom
71                                           isLoopback:isLoopback
72                                          isAudioOnly:isAudioOnly];
73  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
92