You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
7.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #import "ARDMainView.h"
  11. #import "UIImage+ARDUtilities.h"
  12. static CGFloat const kRoomTextFieldHeight = 40;
  13. static CGFloat const kRoomTextFieldMargin = 8;
  14. static CGFloat const kCallControlMargin = 8;
  15. // Helper view that contains a text field and a clear button.
  16. @interface ARDRoomTextField : UIView <UITextFieldDelegate>
  17. @property(nonatomic, readonly) NSString *roomText;
  18. @end
  19. @implementation ARDRoomTextField {
  20. UITextField *_roomText;
  21. }
  22. - (instancetype)initWithFrame:(CGRect)frame {
  23. if (self = [super initWithFrame:frame]) {
  24. _roomText = [[UITextField alloc] initWithFrame:CGRectZero];
  25. _roomText.borderStyle = UITextBorderStyleNone;
  26. _roomText.font = [UIFont systemFontOfSize:12];
  27. _roomText.placeholder = @"Room name";
  28. _roomText.autocorrectionType = UITextAutocorrectionTypeNo;
  29. _roomText.autocapitalizationType = UITextAutocapitalizationTypeNone;
  30. _roomText.clearButtonMode = UITextFieldViewModeAlways;
  31. _roomText.delegate = self;
  32. [self addSubview:_roomText];
  33. // Give rounded corners and a light gray border.
  34. self.layer.borderWidth = 1;
  35. self.layer.borderColor = [[UIColor lightGrayColor] CGColor];
  36. self.layer.cornerRadius = 2;
  37. }
  38. return self;
  39. }
  40. - (void)layoutSubviews {
  41. _roomText.frame =
  42. CGRectMake(kRoomTextFieldMargin, 0, CGRectGetWidth(self.bounds) - kRoomTextFieldMargin,
  43. kRoomTextFieldHeight);
  44. }
  45. - (CGSize)sizeThatFits:(CGSize)size {
  46. size.height = kRoomTextFieldHeight;
  47. return size;
  48. }
  49. - (NSString *)roomText {
  50. return _roomText.text;
  51. }
  52. #pragma mark - UITextFieldDelegate
  53. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  54. // There is no other control that can take focus, so manually resign focus
  55. // when return (Join) is pressed to trigger |textFieldDidEndEditing|.
  56. [textField resignFirstResponder];
  57. return YES;
  58. }
  59. @end
  60. @implementation ARDMainView {
  61. ARDRoomTextField *_roomText;
  62. UIButton *_startRegularCallButton;
  63. UIButton *_startLoopbackCallButton;
  64. UIButton *_audioLoopButton;
  65. }
  66. @synthesize delegate = _delegate;
  67. @synthesize isAudioLoopPlaying = _isAudioLoopPlaying;
  68. - (instancetype)initWithFrame:(CGRect)frame {
  69. if (self = [super initWithFrame:frame]) {
  70. _roomText = [[ARDRoomTextField alloc] initWithFrame:CGRectZero];
  71. [self addSubview:_roomText];
  72. UIFont *controlFont = [UIFont boldSystemFontOfSize:18.0];
  73. UIColor *controlFontColor = [UIColor whiteColor];
  74. _startRegularCallButton = [UIButton buttonWithType:UIButtonTypeSystem];
  75. _startRegularCallButton.titleLabel.font = controlFont;
  76. [_startRegularCallButton setTitleColor:controlFontColor forState:UIControlStateNormal];
  77. _startRegularCallButton.backgroundColor
  78. = [UIColor colorWithRed:66.0/255.0 green:200.0/255.0 blue:90.0/255.0 alpha:1.0];
  79. [_startRegularCallButton setTitle:@"Call room" forState:UIControlStateNormal];
  80. [_startRegularCallButton addTarget:self
  81. action:@selector(onStartRegularCall:)
  82. forControlEvents:UIControlEventTouchUpInside];
  83. [self addSubview:_startRegularCallButton];
  84. _startLoopbackCallButton = [UIButton buttonWithType:UIButtonTypeSystem];
  85. _startLoopbackCallButton.titleLabel.font = controlFont;
  86. [_startLoopbackCallButton setTitleColor:controlFontColor forState:UIControlStateNormal];
  87. _startLoopbackCallButton.backgroundColor =
  88. [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0];
  89. [_startLoopbackCallButton setTitle:@"Loopback call" forState:UIControlStateNormal];
  90. [_startLoopbackCallButton addTarget:self
  91. action:@selector(onStartLoopbackCall:)
  92. forControlEvents:UIControlEventTouchUpInside];
  93. [self addSubview:_startLoopbackCallButton];
  94. // Used to test what happens to sounds when calls are in progress.
  95. _audioLoopButton = [UIButton buttonWithType:UIButtonTypeSystem];
  96. _audioLoopButton.titleLabel.font = controlFont;
  97. [_audioLoopButton setTitleColor:controlFontColor forState:UIControlStateNormal];
  98. _audioLoopButton.backgroundColor =
  99. [UIColor colorWithRed:1.0 green:149.0/255.0 blue:0.0 alpha:1.0];
  100. [self updateAudioLoopButton];
  101. [_audioLoopButton addTarget:self
  102. action:@selector(onToggleAudioLoop:)
  103. forControlEvents:UIControlEventTouchUpInside];
  104. [self addSubview:_audioLoopButton];
  105. self.backgroundColor = [UIColor whiteColor];
  106. }
  107. return self;
  108. }
  109. - (void)setIsAudioLoopPlaying:(BOOL)isAudioLoopPlaying {
  110. if (_isAudioLoopPlaying == isAudioLoopPlaying) {
  111. return;
  112. }
  113. _isAudioLoopPlaying = isAudioLoopPlaying;
  114. [self updateAudioLoopButton];
  115. }
  116. - (void)layoutSubviews {
  117. CGRect bounds = self.bounds;
  118. CGFloat roomTextWidth = bounds.size.width - 2 * kRoomTextFieldMargin;
  119. CGFloat roomTextHeight = [_roomText sizeThatFits:bounds.size].height;
  120. _roomText.frame =
  121. CGRectMake(kRoomTextFieldMargin, kRoomTextFieldMargin, roomTextWidth,
  122. roomTextHeight);
  123. CGFloat buttonHeight =
  124. (CGRectGetMaxY(self.bounds) - CGRectGetMaxY(_roomText.frame) - kCallControlMargin * 4) / 3;
  125. CGFloat regularCallFrameTop = CGRectGetMaxY(_roomText.frame) + kCallControlMargin;
  126. CGRect regularCallFrame = CGRectMake(kCallControlMargin,
  127. regularCallFrameTop,
  128. bounds.size.width - 2*kCallControlMargin,
  129. buttonHeight);
  130. CGFloat loopbackCallFrameTop = CGRectGetMaxY(regularCallFrame) + kCallControlMargin;
  131. CGRect loopbackCallFrame = CGRectMake(kCallControlMargin,
  132. loopbackCallFrameTop,
  133. bounds.size.width - 2*kCallControlMargin,
  134. buttonHeight);
  135. CGFloat audioLoopTop = CGRectGetMaxY(loopbackCallFrame) + kCallControlMargin;
  136. CGRect audioLoopFrame = CGRectMake(kCallControlMargin,
  137. audioLoopTop,
  138. bounds.size.width - 2*kCallControlMargin,
  139. buttonHeight);
  140. _startRegularCallButton.frame = regularCallFrame;
  141. _startLoopbackCallButton.frame = loopbackCallFrame;
  142. _audioLoopButton.frame = audioLoopFrame;
  143. }
  144. #pragma mark - Private
  145. - (void)updateAudioLoopButton {
  146. if (_isAudioLoopPlaying) {
  147. [_audioLoopButton setTitle:@"Stop sound" forState:UIControlStateNormal];
  148. } else {
  149. [_audioLoopButton setTitle:@"Play sound" forState:UIControlStateNormal];
  150. }
  151. }
  152. - (void)onToggleAudioLoop:(id)sender {
  153. [_delegate mainViewDidToggleAudioLoop:self];
  154. }
  155. - (void)onStartRegularCall:(id)sender {
  156. [_delegate mainView:self didInputRoom:_roomText.roomText isLoopback:NO];
  157. }
  158. - (void)onStartLoopbackCall:(id)sender {
  159. [_delegate mainView:self didInputRoom:_roomText.roomText isLoopback:YES];
  160. }
  161. @end