3030#import " ARDSettingsModel.h"
3131#import " ARDToast.h"
3232
33- @import SDAutoLayout;
3433@import WebRTC;
3534@import kmp_webrtc;
3635
@@ -40,25 +39,24 @@ @interface CallViewController () <Kmp_webrtcPeerConnectionClientCallback, CFAudi
4039@implementation CallViewController {
4140 ARDSettingsModel* _settingsModel;
4241 bool _isLandscape;
43-
42+
4443 Kmp_webrtcObjCPeerConnectionClientFactory* _pcClientFactory;
4544 id <Kmp_webrtcPeerConnectionClient> _pcClient;
4645 NSTimer * _statsTimer;
4746 CFAudioMixer* _mixer;
48-
49- UIView* _rootLayout;
47+
5048 CFEAGLVideoView* _remoteRenderer;
5149 CFEAGLVideoView* _localRenderer;
52-
50+
5351 UIButton* _leaveButton;
5452 UIButton* _recordButton;
5553 UIButton* _mixerButton;
5654 UIButton* _switchCameraButton;
57-
55+
5856 bool _recording;
5957 bool _mixingMusic;
6058 bool _videoEnabled;
61-
59+
6260 bool _sendLastFrame;
6361 bool _left;
6462}
@@ -77,18 +75,47 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
7775 : UIInterfaceOrientationMaskPortrait;
7876}
7977
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 ];
8480
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;
8796
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+ ]];
92119
93120 _recordButton = [UIButton buttonWithType: UIButtonTypeSystem];
94121 [_recordButton setTitle: _recording ? @" stop record" : @" start record"
@@ -97,11 +124,6 @@ - (void)loadView {
97124 [_recordButton addTarget: self
98125 action: @selector (onRecord: )
99126 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 );
105127
106128 _mixerButton = [UIButton buttonWithType: UIButtonTypeSystem];
107129 [_mixerButton setTitle: _mixingMusic ? @" stop mixer" : @" start mixer"
@@ -110,89 +132,72 @@ - (void)loadView {
110132 [_mixerButton addTarget: self
111133 action: @selector (onMixer: )
112134 forControlEvents: UIControlEventTouchUpInside];
113- [self .view addSubview: _mixerButton];
114- _mixerButton.sd_layout .widthIs (120 )
115- .heightIs (20 )
116- .bottomEqualToView (_recordButton)
117- .leftSpaceToView (_recordButton, 10 );
118135
119136 _leaveButton = [UIButton buttonWithType: UIButtonTypeSystem];
120137 [_leaveButton setTitle: @" Leave" forState: UIControlStateNormal];
121138 _leaveButton.titleLabel .font = [UIFont systemFontOfSize: 20.0 ];
122139 [_leaveButton addTarget: self
123140 action: @selector (onLeaveCall: )
124141 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+ ]];
130161
131162 _switchCameraButton = [UIButton buttonWithType: UIButtonTypeSystem];
132163 [_switchCameraButton setTitle: @" FRONT" forState: UIControlStateNormal];
133164 _switchCameraButton.titleLabel .font = [UIFont systemFontOfSize: 20.0 ];
134165 [_switchCameraButton addTarget: self
135166 action: @selector (onSwitchCamera: )
136167 forControlEvents: UIControlEventTouchUpInside];
137- [self .view addSubview: _switchCameraButton];
138- _switchCameraButton.sd_layout .widthIs (80 )
139- .heightIs (20 )
140- .leftEqualToView (_recordButton)
141- .bottomSpaceToView (_recordButton, 20 );
142168
143169 UIButton* videoButton = [UIButton buttonWithType: UIButtonTypeSystem];
144170 [videoButton setTitle: @" Video" forState: UIControlStateNormal];
145171 videoButton.titleLabel .font = [UIFont systemFontOfSize: 20.0 ];
146172 [videoButton addTarget: self
147173 action: @selector (onToggleVideo: )
148174 forControlEvents: UIControlEventTouchUpInside];
149- [self .view addSubview: videoButton];
150- videoButton.sd_layout .widthIs (80 )
151- .heightIs (20 )
152- .bottomEqualToView (_switchCameraButton)
153- .leftSpaceToView (_switchCameraButton, 10 );
154175
155176 UIButton* sendLastFrameButton = [UIButton buttonWithType: UIButtonTypeSystem];
156177 [sendLastFrameButton setTitle: @" SLF" forState: UIControlStateNormal];
157178 sendLastFrameButton.titleLabel .font = [UIFont systemFontOfSize: 20.0 ];
158179 [sendLastFrameButton addTarget: self
159180 action: @selector (onToggleSendLastFrame: )
160181 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;
182182
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+ ]];
196201
197202 [self startLoopback ];
198203}
0 commit comments