File: ARDBroadcastSetupViewController.m

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (125 lines) | stat: -rw-r--r-- 4,883 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 *  Copyright 2018 The WebRTC Project Authors. All rights reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#import "ARDBroadcastSetupViewController.h"

@implementation ARDBroadcastSetupViewController {
  UITextField *_roomNameField;
}

- (void)loadView {
  UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  view.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.7];

  UIImageView *imageView =
      [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon-180"]];
  imageView.translatesAutoresizingMaskIntoConstraints = NO;
  [view addSubview:imageView];

  _roomNameField = [[UITextField alloc] initWithFrame:CGRectZero];
  _roomNameField.borderStyle = UITextBorderStyleRoundedRect;
  _roomNameField.font = [UIFont systemFontOfSize:14.0];
  _roomNameField.translatesAutoresizingMaskIntoConstraints = NO;
  _roomNameField.placeholder = @"Room name";
  _roomNameField.returnKeyType = UIReturnKeyDone;
  _roomNameField.delegate = self;
  [view addSubview:_roomNameField];

  UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeSystem];
  doneButton.translatesAutoresizingMaskIntoConstraints = NO;
  doneButton.titleLabel.font = [UIFont systemFontOfSize:20.0];
  [doneButton setTitle:@"Done" forState:UIControlStateNormal];
  [doneButton addTarget:self
                 action:@selector(userDidFinishSetup)
       forControlEvents:UIControlEventTouchUpInside];
  [view addSubview:doneButton];

  UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
  cancelButton.translatesAutoresizingMaskIntoConstraints = NO;
  cancelButton.titleLabel.font = [UIFont systemFontOfSize:20.0];
  [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
  [cancelButton addTarget:self
                   action:@selector(userDidCancelSetup)
         forControlEvents:UIControlEventTouchUpInside];
  [view addSubview:cancelButton];

  UILayoutGuide *margin = view.layoutMarginsGuide;
  [imageView.widthAnchor constraintEqualToConstant:60.0].active = YES;
  [imageView.heightAnchor constraintEqualToConstant:60.0].active = YES;
  [imageView.topAnchor constraintEqualToAnchor:margin.topAnchor constant:20]
      .active = YES;
  [imageView.centerXAnchor constraintEqualToAnchor:view.centerXAnchor].active =
      YES;

  [_roomNameField.leadingAnchor constraintEqualToAnchor:margin.leadingAnchor]
      .active = YES;
  [_roomNameField.topAnchor constraintEqualToAnchor:imageView.bottomAnchor
                                           constant:20]
      .active = YES;
  [_roomNameField.trailingAnchor constraintEqualToAnchor:margin.trailingAnchor]
      .active = YES;

  [doneButton.leadingAnchor constraintEqualToAnchor:margin.leadingAnchor]
      .active = YES;
  [doneButton.bottomAnchor constraintEqualToAnchor:margin.bottomAnchor
                                          constant:-20]
      .active = YES;

  [cancelButton.trailingAnchor constraintEqualToAnchor:margin.trailingAnchor]
      .active = YES;
  [cancelButton.bottomAnchor constraintEqualToAnchor:margin.bottomAnchor
                                            constant:-20]
      .active = YES;

  UITapGestureRecognizer *tgr =
      [[UITapGestureRecognizer alloc] initWithTarget:self
                                              action:@selector(didTap:)];
  [view addGestureRecognizer:tgr];

  self.view = view;
}

- (IBAction)didTap:(id)sender {
  [self.view endEditing:YES];
}

- (void)userDidFinishSetup {
  // URL of the resource where broadcast can be viewed that will be returned to
  // the application
  NSURL *broadcastURL =
      [NSURL URLWithString:[NSString stringWithFormat:@"https://appr.tc/r/%@",
                                                      _roomNameField.text]];

  // Dictionary with setup information that will be provided to broadcast
  // extension when broadcast is started
  NSDictionary *setupInfo = @{@"roomName" : _roomNameField.text};

  // Tell ReplayKit that the extension is finished setting up and can begin
  // broadcasting
  [self.extensionContext completeRequestWithBroadcastURL:broadcastURL
                                               setupInfo:setupInfo];
}

- (void)userDidCancelSetup {
  // Tell ReplayKit that the extension was cancelled by the user
  [self.extensionContext
      cancelRequestWithError:[NSError errorWithDomain:@"com.google.AppRTCMobile"
                                                 code:-1
                                             userInfo:nil]];
}

#pragma mark - UITextFieldDelegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
  [self userDidFinishSetup];
  return YES;
}

@end