• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 *  Copyright 2018 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 "ARDBroadcastSetupViewController.h"
12
13@implementation ARDBroadcastSetupViewController {
14  UITextField *_roomNameField;
15}
16
17- (void)loadView {
18  UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
19  view.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.7];
20
21  UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon-180"]];
22  imageView.translatesAutoresizingMaskIntoConstraints = NO;
23  [view addSubview:imageView];
24
25  _roomNameField = [[UITextField alloc] initWithFrame:CGRectZero];
26  _roomNameField.borderStyle = UITextBorderStyleRoundedRect;
27  _roomNameField.font = [UIFont systemFontOfSize:14.0];
28  _roomNameField.translatesAutoresizingMaskIntoConstraints = NO;
29  _roomNameField.placeholder = @"Room name";
30  _roomNameField.returnKeyType = UIReturnKeyDone;
31  _roomNameField.delegate = self;
32  [view addSubview:_roomNameField];
33
34  UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeSystem];
35  doneButton.translatesAutoresizingMaskIntoConstraints = NO;
36  doneButton.titleLabel.font = [UIFont systemFontOfSize:20.0];
37  [doneButton setTitle:@"Done" forState:UIControlStateNormal];
38  [doneButton addTarget:self
39                 action:@selector(userDidFinishSetup)
40       forControlEvents:UIControlEventTouchUpInside];
41  [view addSubview:doneButton];
42
43  UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
44  cancelButton.translatesAutoresizingMaskIntoConstraints = NO;
45  cancelButton.titleLabel.font = [UIFont systemFontOfSize:20.0];
46  [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
47  [cancelButton addTarget:self
48                   action:@selector(userDidCancelSetup)
49         forControlEvents:UIControlEventTouchUpInside];
50  [view addSubview:cancelButton];
51
52  UILayoutGuide *margin = view.layoutMarginsGuide;
53  [imageView.widthAnchor constraintEqualToConstant:60.0].active = YES;
54  [imageView.heightAnchor constraintEqualToConstant:60.0].active = YES;
55  [imageView.topAnchor constraintEqualToAnchor:margin.topAnchor constant:20].active = YES;
56  [imageView.centerXAnchor constraintEqualToAnchor:view.centerXAnchor].active = YES;
57
58  [_roomNameField.leadingAnchor constraintEqualToAnchor:margin.leadingAnchor].active = YES;
59  [_roomNameField.topAnchor constraintEqualToAnchor:imageView.bottomAnchor constant:20].active =
60      YES;
61  [_roomNameField.trailingAnchor constraintEqualToAnchor:margin.trailingAnchor].active = YES;
62
63  [doneButton.leadingAnchor constraintEqualToAnchor:margin.leadingAnchor].active = YES;
64  [doneButton.bottomAnchor constraintEqualToAnchor:margin.bottomAnchor constant:-20].active = YES;
65
66  [cancelButton.trailingAnchor constraintEqualToAnchor:margin.trailingAnchor].active = YES;
67  [cancelButton.bottomAnchor constraintEqualToAnchor:margin.bottomAnchor constant:-20].active = YES;
68
69  UITapGestureRecognizer *tgr =
70      [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)];
71  [view addGestureRecognizer:tgr];
72
73  self.view = view;
74}
75
76- (IBAction)didTap:(id)sender {
77  [self.view endEditing:YES];
78}
79
80- (void)userDidFinishSetup {
81  // URL of the resource where broadcast can be viewed that will be returned to the application
82  NSURL *broadcastURL = [NSURL
83      URLWithString:[NSString stringWithFormat:@"https://appr.tc/r/%@", _roomNameField.text]];
84
85  // Dictionary with setup information that will be provided to broadcast extension when broadcast
86  // is started
87  NSDictionary *setupInfo = @{@"roomName" : _roomNameField.text};
88
89  // Tell ReplayKit that the extension is finished setting up and can begin broadcasting
90  [self.extensionContext completeRequestWithBroadcastURL:broadcastURL setupInfo:setupInfo];
91}
92
93- (void)userDidCancelSetup {
94  // Tell ReplayKit that the extension was cancelled by the user
95  [self.extensionContext cancelRequestWithError:[NSError errorWithDomain:@"com.google.AppRTCMobile"
96                                                                    code:-1
97                                                                userInfo:nil]];
98}
99
100#pragma mark - UITextFieldDelegate
101
102- (BOOL)textFieldShouldReturn:(UITextField *)textField {
103  [self userDidFinishSetup];
104  return YES;
105}
106
107@end
108