30
30
#import " ARDSettingsModel.h"
31
31
#import " ARDToast.h"
32
32
33
- @import SDAutoLayout;
34
33
@import WebRTC;
35
34
@import kmp_webrtc;
36
35
@@ -40,25 +39,24 @@ @interface CallViewController () <Kmp_webrtcPeerConnectionClientCallback, CFAudi
40
39
@implementation CallViewController {
41
40
ARDSettingsModel* _settingsModel;
42
41
bool _isLandscape;
43
-
42
+
44
43
Kmp_webrtcObjCPeerConnectionClientFactory* _pcClientFactory;
45
44
id <Kmp_webrtcPeerConnectionClient> _pcClient;
46
45
NSTimer * _statsTimer;
47
46
CFAudioMixer* _mixer;
48
-
49
- UIView* _rootLayout;
47
+
50
48
CFEAGLVideoView* _remoteRenderer;
51
49
CFEAGLVideoView* _localRenderer;
52
-
50
+
53
51
UIButton* _leaveButton;
54
52
UIButton* _recordButton;
55
53
UIButton* _mixerButton;
56
54
UIButton* _switchCameraButton;
57
-
55
+
58
56
bool _recording;
59
57
bool _mixingMusic;
60
58
bool _videoEnabled;
61
-
59
+
62
60
bool _sendLastFrame;
63
61
bool _left;
64
62
}
@@ -77,18 +75,47 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
77
75
: UIInterfaceOrientationMaskPortrait;
78
76
}
79
77
80
- - (void )loadView {
81
- CGSize fc = [UIScreen mainScreen ].bounds .size ;
82
- CGFloat fcWidth = _isLandscape ? fc.height : fc.width ;
83
- CGFloat fcHeight = _isLandscape ? fc.width : fc.height ;
78
+ - (void )viewDidLoad {
79
+ [super viewDidLoad ];
84
80
85
- self.view =
86
- [[UIView alloc ] initWithFrame: CGRectMake (0 , 0 , fcWidth, fcHeight)];
81
+ _localRenderer =
82
+ [[CFEAGLVideoView alloc ] initWithFrame: CGRectZero
83
+ andUid: @" test_local"
84
+ andScaleType: CF_SCALE_TYPE_CENTER_CROP];
85
+ _localRenderer.mirror = YES ;
86
+ _localRenderer.autoresizingMask =
87
+ UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
88
+
89
+ _remoteRenderer =
90
+ [[CFEAGLVideoView alloc ] initWithFrame: CGRectZero
91
+ andUid: @" test_remote"
92
+ andScaleType: CF_SCALE_TYPE_CENTER_CROP];
93
+ _remoteRenderer.mirror = NO ;
94
+ _remoteRenderer.autoresizingMask =
95
+ UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
87
96
88
- _rootLayout = [[UIView alloc ] init ];
89
- [self .view addSubview: _rootLayout];
90
- _rootLayout.sd_layout .widthRatioToView (self.view , 1 )
91
- .heightRatioToView (self.view , 1 );
97
+ UIView* localWrapper = [[UIView alloc ] init ];
98
+ [localWrapper addSubview: _localRenderer];
99
+ UIView* remoteWrapper = [[UIView alloc ] init ];
100
+ [remoteWrapper addSubview: _remoteRenderer];
101
+
102
+ UIStackView *mainStackView = [[UIStackView alloc ] init ];
103
+ mainStackView.axis = UILayoutConstraintAxisVertical;
104
+ mainStackView.distribution = UIStackViewDistributionFillEqually;
105
+ mainStackView.alignment = UIStackViewAlignmentFill;
106
+ mainStackView.spacing = 0 ;
107
+ mainStackView.translatesAutoresizingMaskIntoConstraints = NO ;
108
+
109
+ [mainStackView addArrangedSubview: localWrapper];
110
+ [mainStackView addArrangedSubview: remoteWrapper];
111
+ [self .view addSubview: mainStackView];
112
+
113
+ [NSLayoutConstraint activateConstraints: @[
114
+ [mainStackView.leadingAnchor constraintEqualToAnchor: self .view.leadingAnchor],
115
+ [mainStackView.trailingAnchor constraintEqualToAnchor: self .view.trailingAnchor],
116
+ [mainStackView.topAnchor constraintEqualToAnchor: self .view.topAnchor],
117
+ [mainStackView.bottomAnchor constraintEqualToAnchor: self .view.bottomAnchor]
118
+ ]];
92
119
93
120
_recordButton = [UIButton buttonWithType: UIButtonTypeSystem];
94
121
[_recordButton setTitle: _recording ? @" stop record" : @" start record"
@@ -97,11 +124,6 @@ - (void)loadView {
97
124
[_recordButton addTarget: self
98
125
action: @selector (onRecord: )
99
126
forControlEvents: UIControlEventTouchUpInside];
100
- [self .view addSubview: _recordButton];
101
- _recordButton.sd_layout .widthIs (120 )
102
- .heightIs (20 )
103
- .bottomSpaceToView (self.view , 30 )
104
- .leftSpaceToView (self.view , 10 );
105
127
106
128
_mixerButton = [UIButton buttonWithType: UIButtonTypeSystem];
107
129
[_mixerButton setTitle: _mixingMusic ? @" stop mixer" : @" start mixer"
@@ -110,89 +132,72 @@ - (void)loadView {
110
132
[_mixerButton addTarget: self
111
133
action: @selector (onMixer: )
112
134
forControlEvents: UIControlEventTouchUpInside];
113
- [self .view addSubview: _mixerButton];
114
- _mixerButton.sd_layout .widthIs (120 )
115
- .heightIs (20 )
116
- .bottomEqualToView (_recordButton)
117
- .leftSpaceToView (_recordButton, 10 );
118
135
119
136
_leaveButton = [UIButton buttonWithType: UIButtonTypeSystem];
120
137
[_leaveButton setTitle: @" Leave" forState: UIControlStateNormal];
121
138
_leaveButton.titleLabel .font = [UIFont systemFontOfSize: 20.0 ];
122
139
[_leaveButton addTarget: self
123
140
action: @selector (onLeaveCall: )
124
141
forControlEvents: UIControlEventTouchUpInside];
125
- [self .view addSubview: _leaveButton];
126
- _leaveButton.sd_layout .widthIs (80 )
127
- .heightIs (20 )
128
- .bottomEqualToView (_recordButton)
129
- .leftSpaceToView (_mixerButton, 10 );
142
+
143
+ UIStackView *ops1 = [[UIStackView alloc ] init ];
144
+ ops1.axis = UILayoutConstraintAxisHorizontal;
145
+ ops1.distribution = UIStackViewDistributionFillEqually;
146
+ ops1.alignment = UIStackViewAlignmentFill;
147
+ ops1.spacing = 0 ;
148
+ ops1.translatesAutoresizingMaskIntoConstraints = NO ;
149
+
150
+ [ops1 addArrangedSubview: _recordButton];
151
+ [ops1 addArrangedSubview: _mixerButton];
152
+ [ops1 addArrangedSubview: _leaveButton];
153
+ [self .view addSubview: ops1];
154
+
155
+ [NSLayoutConstraint activateConstraints: @[
156
+ [ops1.leadingAnchor constraintEqualToAnchor: self .view.leadingAnchor],
157
+ [ops1.trailingAnchor constraintEqualToAnchor: self .view.trailingAnchor],
158
+ [ops1.bottomAnchor constraintEqualToAnchor: self .view.bottomAnchor],
159
+ [ops1.heightAnchor constraintGreaterThanOrEqualToConstant: 30 ]
160
+ ]];
130
161
131
162
_switchCameraButton = [UIButton buttonWithType: UIButtonTypeSystem];
132
163
[_switchCameraButton setTitle: @" FRONT" forState: UIControlStateNormal];
133
164
_switchCameraButton.titleLabel .font = [UIFont systemFontOfSize: 20.0 ];
134
165
[_switchCameraButton addTarget: self
135
166
action: @selector (onSwitchCamera: )
136
167
forControlEvents: UIControlEventTouchUpInside];
137
- [self .view addSubview: _switchCameraButton];
138
- _switchCameraButton.sd_layout .widthIs (80 )
139
- .heightIs (20 )
140
- .leftEqualToView (_recordButton)
141
- .bottomSpaceToView (_recordButton, 20 );
142
168
143
169
UIButton* videoButton = [UIButton buttonWithType: UIButtonTypeSystem];
144
170
[videoButton setTitle: @" Video" forState: UIControlStateNormal];
145
171
videoButton.titleLabel .font = [UIFont systemFontOfSize: 20.0 ];
146
172
[videoButton addTarget: self
147
173
action: @selector (onToggleVideo: )
148
174
forControlEvents: UIControlEventTouchUpInside];
149
- [self .view addSubview: videoButton];
150
- videoButton.sd_layout .widthIs (80 )
151
- .heightIs (20 )
152
- .bottomEqualToView (_switchCameraButton)
153
- .leftSpaceToView (_switchCameraButton, 10 );
154
175
155
176
UIButton* sendLastFrameButton = [UIButton buttonWithType: UIButtonTypeSystem];
156
177
[sendLastFrameButton setTitle: @" SLF" forState: UIControlStateNormal];
157
178
sendLastFrameButton.titleLabel .font = [UIFont systemFontOfSize: 20.0 ];
158
179
[sendLastFrameButton addTarget: self
159
180
action: @selector (onToggleSendLastFrame: )
160
181
forControlEvents: UIControlEventTouchUpInside];
161
- [self .view addSubview: sendLastFrameButton];
162
- sendLastFrameButton.sd_layout .widthIs (80 )
163
- .heightIs (20 )
164
- .bottomEqualToView (_switchCameraButton)
165
- .leftSpaceToView (videoButton, 10 );
166
-
167
- _localRenderer =
168
- [[CFEAGLVideoView alloc ] initWithFrame: CGRectZero
169
- andUid: @" test_local"
170
- andScaleType: CF_SCALE_TYPE_CENTER_CROP];
171
- _localRenderer.mirror = YES ;
172
- _localRenderer.autoresizingMask =
173
- UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
174
-
175
- _remoteRenderer =
176
- [[CFEAGLVideoView alloc ] initWithFrame: CGRectZero
177
- andUid: @" test_remote"
178
- andScaleType: CF_SCALE_TYPE_CENTER_CROP];
179
- _remoteRenderer.mirror = NO ;
180
- _remoteRenderer.autoresizingMask =
181
- UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
182
182
183
- UIView* wrapper = [[UIView alloc ] init ];
184
- [_rootLayout insertSubview: wrapper atIndex: 0 ];
185
- wrapper.sd_layout .widthRatioToView (_rootLayout, 1 )
186
- .heightRatioToView (_rootLayout, 0.5 )
187
- .topEqualToView (_rootLayout);
188
- [wrapper addSubview: _localRenderer];
189
-
190
- wrapper = [[UIView alloc ] init ];
191
- [_rootLayout insertSubview: wrapper atIndex: 0 ];
192
- wrapper.sd_layout .widthRatioToView (_rootLayout, 1 )
193
- .heightRatioToView (_rootLayout, 0.5 )
194
- .bottomEqualToView (_rootLayout);
195
- [wrapper addSubview: _remoteRenderer];
183
+ UIStackView *ops2 = [[UIStackView alloc ] init ];
184
+ ops2.axis = UILayoutConstraintAxisHorizontal;
185
+ ops2.distribution = UIStackViewDistributionFillEqually;
186
+ ops2.alignment = UIStackViewAlignmentFill;
187
+ ops2.spacing = 0 ;
188
+ ops2.translatesAutoresizingMaskIntoConstraints = NO ;
189
+
190
+ [ops2 addArrangedSubview: _switchCameraButton];
191
+ [ops2 addArrangedSubview: videoButton];
192
+ [ops2 addArrangedSubview: sendLastFrameButton];
193
+ [self .view addSubview: ops2];
194
+
195
+ [NSLayoutConstraint activateConstraints: @[
196
+ [ops2.leadingAnchor constraintEqualToAnchor: self .view.leadingAnchor],
197
+ [ops2.trailingAnchor constraintEqualToAnchor: self .view.trailingAnchor],
198
+ [ops2.bottomAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.bottomAnchor constant: -60 ],
199
+ [ops2.heightAnchor constraintGreaterThanOrEqualToConstant: 30 ]
200
+ ]];
196
201
197
202
[self startLoopback ];
198
203
}
0 commit comments