@@ -98,10 +98,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
98
98
checkPermissionsAndInitEngine ();
99
99
}
100
100
101
+ /**
102
+ * switch the front or back camera
103
+ */
101
104
private void onSwitchCamera () {
102
105
this .mRtcEngine .switchCamera ();
103
106
}
104
107
108
+ /**
109
+ * Check that the permissions are enabled otherwise ask to the user
110
+ * Init agora if permissions are enabled
111
+ */
105
112
private void checkPermissionsAndInitEngine () {
106
113
ArrayList <String > permissions = new ArrayList <>();
107
114
permissions .add (Manifest .permission .RECORD_AUDIO );
@@ -119,13 +126,20 @@ private void checkPermissionsAndInitEngine() {
119
126
}
120
127
}
121
128
129
+ /**
130
+ * Send a notification to the called user and update the database such that
131
+ * the callee has access to the room name
132
+ */
122
133
private void sendNotification () {
123
134
FcmNotificationsSender sender = new FcmNotificationsSender (this .user .getToken (), NOTIFICATION_TITLE ,
124
135
NOTIFICATION_BODY , getApplicationContext (), CallActivity .this );
125
136
sender .sendNotifications ();
126
137
reference .document (this .user .getId ()).update (ROOM_NAME , currUserID );
127
138
}
128
139
140
+ /**
141
+ * Join the channel corresponding to the room name in the db
142
+ */
129
143
private void joinChannel () {
130
144
reference .document (Auth .getUid ()).get ().addOnSuccessListener (res -> {
131
145
if (res .exists ()) {
@@ -151,6 +165,10 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
151
165
}
152
166
}
153
167
168
+ /**
169
+ * Create the agora engine and
170
+ * If the user is the caller join the channel and send notif otherwise just join the channel
171
+ */
154
172
private void initAgoraEngine () {
155
173
try {
156
174
this .mRtcEngine = RtcEngine .create (getApplicationContext (), getString (R .string .agora_app_id ), mRtcEventHandler );
@@ -165,6 +183,9 @@ private void initAgoraEngine() {
165
183
}
166
184
}
167
185
186
+ /**
187
+ * Initialize basics of the RTC engine (video, audio...)
188
+ */
168
189
private void setupSession () {
169
190
this .mRtcEngine .setChannelProfile (io .agora .rtc .Constants .CHANNEL_PROFILE_COMMUNICATION );
170
191
this .mRtcEngine .enableVideo ();
@@ -174,6 +195,10 @@ private void setupSession() {
174
195
VideoEncoderConfiguration .ORIENTATION_MODE .ORIENTATION_MODE_FIXED_PORTRAIT ));
175
196
}
176
197
198
+ /**
199
+ * Set up the video of the local user and all the layout that
200
+ * follows from that
201
+ */
177
202
private void setupLocalVideoFeed () {
178
203
this .mRtcEngine .setChannelProfile (CHANNEL_PROFILE_LIVE_BROADCASTING );
179
204
this .mRtcEngine .enableVideo ();
@@ -190,6 +215,12 @@ private void setupLocalVideoFeed() {
190
215
this .mRtcEngine .setupLocalVideo (new VideoCanvas (videoSurface , VideoCanvas .RENDER_MODE_FIT , 0 ));
191
216
}
192
217
218
+ /**
219
+ * Set up the video of the remote user and all the layout that
220
+ * follows from that
221
+ *
222
+ * @param uid of the user who joined the call
223
+ */
193
224
private void setupRemoteVideoStream (int uid ) {
194
225
FrameLayout videoContainer = findViewById (R .id .bg_video_container );
195
226
SurfaceView videoSurface = RtcEngine .CreateRendererView (getBaseContext ());
@@ -198,26 +229,45 @@ private void setupRemoteVideoStream(int uid) {
198
229
this .mRtcEngine .setRemoteSubscribeFallbackOption (io .agora .rtc .Constants .STREAM_FALLBACK_OPTION_AUDIO_ONLY );
199
230
}
200
231
232
+ /**
233
+ * CHange the layout if the remote user change his camera from selfie to field
234
+ * or from field to selfie
235
+ *
236
+ * @param state selfie or field mode
237
+ */
201
238
private void onRemoteUserVideoToggle (int state ) {
202
239
FrameLayout videoContainer = findViewById (R .id .bg_video_container );
203
240
SurfaceView videoSurface = (SurfaceView ) videoContainer .getChildAt (0 );
204
241
videoSurface .setVisibility (state == 0 ? View .GONE : View .VISIBLE );
205
242
}
206
243
244
+ /**
245
+ * init token, set room name and local video when user joined
246
+ * channel
247
+ */
207
248
private void onJoinChannelClicked () {
208
249
String channelName = currUserID ;
209
250
initToken (channelName );
210
251
this .mRtcEngine .joinChannel (this .result , channelName , null , 0 );
211
252
setupLocalVideoFeed ();
212
253
}
213
254
255
+ /**
256
+ * Init the token for the channel with the corresponding channel name
257
+ *
258
+ * @param channelName of the caller (his user id)
259
+ */
214
260
private void initToken (String channelName ) {
215
261
RtcTokenBuilder token = new RtcTokenBuilder ();
216
262
int timestamp = (int ) (System .currentTimeMillis () / 1000 + expirationTimeInSeconds );
217
263
this .result = token .buildTokenWithUid (getString (R .string .agora_app_id ), getString (R .string .agora_certificate ),
218
264
channelName , 0 , RtcTokenBuilder .Role .Role_Publisher , timestamp );
219
265
}
220
266
267
+ /**
268
+ * leave the channel with the RTC engine, remove video, update the room name
269
+ * to null in the database and return to the menu
270
+ */
221
271
private void onLeaveChannelClicked () {
222
272
this .mRtcEngine .leaveChannel ();
223
273
removeVideo (R .id .floating_video_container );
@@ -229,18 +279,35 @@ private void onLeaveChannelClicked() {
229
279
finish ();
230
280
}
231
281
282
+ /**
283
+ * Remove the video
284
+ *
285
+ * @param containerID corresponding id the container
286
+ */
232
287
private void removeVideo (int containerID ) {
233
288
FrameLayout videoContainer = findViewById (containerID );
234
289
videoContainer .setVisibility (View .GONE );
235
290
videoContainer .removeAllViews ();
236
291
}
237
292
293
+ /**
294
+ * Mute the local audio stream when the local user clicks on the
295
+ * microphone button
296
+ *
297
+ * @param view id of the button element
298
+ */
238
299
private void onAudioMuteClicked (View view ) {
239
300
ImageView btn = (ImageView ) view ;
240
301
changeButtonState (btn , R .drawable .btn_mute , R .drawable .btn_unmute );
241
302
this .mRtcEngine .muteLocalAudioStream (btn .isSelected ());
242
303
}
243
304
305
+ /**
306
+ * Stop the local video stream when the local user clicks on the
307
+ * microphone button and adapt the corresponding layout
308
+ *
309
+ * @param view id of the video element
310
+ */
244
311
private void onVideoMuteClicked (View view ) {
245
312
ImageView btn = (ImageView ) view ;
246
313
changeButtonState (btn , R .drawable .video_toggle_active_btn , R .drawable .video_toggle_btn );
@@ -252,6 +319,14 @@ private void onVideoMuteClicked(View view) {
252
319
videoSurface .setVisibility (btn .isSelected () ? View .GONE : View .VISIBLE );
253
320
}
254
321
322
+ /**
323
+ * CHange the button state depending on the previous buttton
324
+ * state
325
+ *
326
+ * @param btn correspond ID of the button
327
+ * @param active drawable of the active button
328
+ * @param inactive drawable of the inactive button
329
+ */
255
330
private void changeButtonState (ImageView btn , int active , int inactive ) {
256
331
if (btn .isSelected ()) {
257
332
btn .setSelected (false );
0 commit comments