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