@@ -197,14 +197,6 @@ const publishVideo = async (
197
197
198
198
await rtmInit ( appId , userId , channel ) ;
199
199
200
- const mediaStreamTrack = videoTrack . getMediaStreamTrack ( ) ;
201
- if ( mediaStreamTrack ) {
202
- const videoSettings = mediaStreamTrack . getSettings ( ) ;
203
- const videoWidth = videoSettings . width ;
204
- const videoHeight = videoSettings . height ;
205
- // height.videoWidth.change(videoWidth);
206
- // height.videoHeight.change(videoHeight);
207
- }
208
200
} ;
209
201
210
202
const sendMessageRtm = ( message : any ) => {
@@ -278,12 +270,69 @@ let MTComp = (function () {
278
270
} ) ;
279
271
const [ rtmMessages , setRtmMessages ] = useState < any > ( [ ] ) ;
280
272
const [ localUserSpeaking , setLocalUserSpeaking ] = useState < any > ( false ) ;
273
+ const [ userJoined , setUserJoined ] = useState < IAgoraRTCRemoteUser > ( ) ;
274
+ const [ userLeft , setUserLeft ] = useState < IAgoraRTCRemoteUser > ( ) ;
281
275
282
276
useEffect ( ( ) => {
283
- dispatch (
284
- changeChildAction ( "participants" , getData ( userIds ) . data , false )
285
- ) ;
286
- } , [ userIds ] ) ;
277
+ if ( userJoined ) {
278
+ let userData = {
279
+ user : userJoined . uid ,
280
+ host : false ,
281
+ audiostatus : userJoined . hasVideo ,
282
+ } ;
283
+ setUserIds ( ( userIds : any ) => [ ...userIds , userData ] ) ;
284
+ if ( userIds . length == 0 ) {
285
+ userData . host = true ;
286
+ } else {
287
+ userData . host = false ;
288
+ }
289
+ dispatch (
290
+ changeChildAction (
291
+ "participants" ,
292
+ removeDuplicates ( getData ( [ ...userIds , userData ] ) . data , "user" ) ,
293
+ false
294
+ )
295
+ ) ;
296
+ }
297
+ } , [ userJoined ] ) ;
298
+ function removeDuplicates ( arr : any , prop : any ) {
299
+ const uniqueObjects = [ ] ;
300
+ const seenValues = new Set ( ) ;
301
+
302
+ for ( const obj of arr ) {
303
+ const objValue = obj [ prop ] ;
304
+
305
+ if ( ! seenValues . has ( objValue ) ) {
306
+ seenValues . add ( objValue ) ;
307
+ uniqueObjects . push ( obj ) ;
308
+ }
309
+ }
310
+
311
+ return uniqueObjects ;
312
+ }
313
+ useEffect ( ( ) => {
314
+ if ( userLeft ) {
315
+ console . log ( "user left" , userLeft . uid ) ;
316
+ console . log ( "all users " , userIds ) ;
317
+ let newUsers = userIds . filter (
318
+ ( item : any ) => item . user !== userLeft . uid
319
+ ) ;
320
+ console . log ( "after user left " , newUsers ) ;
321
+ let hostExists = newUsers . filter ( ( f : any ) => f . host === true ) ;
322
+ if ( hostExists . length == 0 && newUsers . length > 0 ) {
323
+ newUsers [ 0 ] . host = true ;
324
+ hostChanged ( newUsers ) ;
325
+ }
326
+ setUserIds ( newUsers ) ;
327
+ dispatch (
328
+ changeChildAction (
329
+ "participants" ,
330
+ removeDuplicates ( getData ( newUsers ) . data , "user" ) ,
331
+ false
332
+ )
333
+ ) ;
334
+ }
335
+ } , [ userLeft ] ) ;
287
336
288
337
useEffect ( ( ) => {
289
338
if ( updateVolume . userid ) {
@@ -304,14 +353,12 @@ let MTComp = (function () {
304
353
}
305
354
} , [ updateVolume ] ) ;
306
355
307
- useEffect ( ( ) => {
308
- if ( props . endCall . value ) {
309
- let newUsers = userIds . filter ( ( item : any ) => item . user !== userId ) ;
310
- dispatch (
311
- changeChildAction ( "participants" , getData ( newUsers ) . data , false )
312
- ) ;
313
- }
314
- } , [ props . endCall . value ] ) ;
356
+ // useEffect(() => {
357
+ // if (props.endCall.value) {
358
+ // let newUsers = userIds.filter((item: any) => item.user !== userId);
359
+ // changeChildAction("participants", getData([]).data, false);
360
+ // }
361
+ // }, [props.endCall.value]);
315
362
316
363
useEffect ( ( ) => {
317
364
if ( rtmMessages ) {
@@ -333,17 +380,17 @@ let MTComp = (function () {
333
380
}
334
381
} , [ localUserSpeaking ] ) ;
335
382
336
- useEffect ( ( ) => {
337
- if ( props . localUser . value ) {
338
- let newUsers = userIds . filter ( ( item : any ) => item . user !== userId ) ;
339
- if ( newUsers . length == 0 ) return ;
340
- newUsers = props . localUser . value ;
341
- let updatedUsers = [ ...userIds , newUsers ] ;
342
- dispatch (
343
- changeChildAction ( "participants" , getData ( updatedUsers ) . data , false )
344
- ) ;
345
- }
346
- } , [ props . localUser . value ] ) ;
383
+ // useEffect(() => {
384
+ // if (props.localUser.value) {
385
+ // let newUsers = userIds.filter((item: any) => item.user !== userId);
386
+ // if (newUsers.length == 0) return;
387
+ // newUsers = props.localUser.value;
388
+ // let updatedUsers = [...userIds, newUsers];
389
+ // dispatch(
390
+ // changeChildAction("participants", getData(updatedUsers).data, false)
391
+ // );
392
+ // }
393
+ // }, [props.localUser.value]);
347
394
348
395
useEffect ( ( ) => {
349
396
if ( rtmChannelResponse ) {
@@ -363,29 +410,10 @@ let MTComp = (function () {
363
410
if ( client ) {
364
411
client . enableAudioVolumeIndicator ( ) ;
365
412
client . on ( "user-joined" , ( user : IAgoraRTCRemoteUser ) => {
366
- let userData = {
367
- user : user . uid ,
368
- host : false ,
369
- audiostatus : user . hasVideo ,
370
- } ;
371
-
372
- if ( userIds . length == 0 ) {
373
- userData . host = true ;
374
- } else {
375
- userData . host = false ;
376
- }
377
- setUserIds ( ( userIds : any ) => [ ...userIds , userData ] ) ;
413
+ setUserJoined ( user ) ;
378
414
} ) ;
379
415
client . on ( "user-left" , ( user : IAgoraRTCRemoteUser , reason : any ) => {
380
- let newUsers = userIds . filter (
381
- ( item : any ) => item . user !== user . uid
382
- ) ;
383
- let hostExists = newUsers . filter ( ( f : any ) => f . host === true ) ;
384
- if ( hostExists . length == 0 && newUsers . length > 0 ) {
385
- newUsers [ 0 ] . host = true ;
386
- hostChanged ( newUsers ) ;
387
- }
388
- setUserIds ( newUsers ) ;
416
+ setUserLeft ( user ) ;
389
417
} ) ;
390
418
client . on ( "volume-indicator" , ( volumeInfos : any ) => {
391
419
if ( volumeInfos . length == 0 ) return ;
@@ -689,6 +717,21 @@ MTComp = withMethodExposing(MTComp, [
689
717
} ,
690
718
execute : async ( comp , values ) => {
691
719
if ( ! comp . children . meetingActive . getView ( ) . value ) return ;
720
+ let participants = comp . children . participants . getView ( ) as [ ] ;
721
+ console . log ( "participants" , participants ) ;
722
+
723
+ let newUsers = participants . filter ( ( item : any ) => item . user !== userId ) ;
724
+ console . log ( "after user left " , newUsers ) ;
725
+ let hostExists = newUsers . filter ( ( f : any ) => f . host === true ) ;
726
+ // if (hostExists.length == 0 && newUsers.length > 0) {
727
+ // newUsers[0].host = true;
728
+ // hostChanged(newUsers);
729
+ // }
730
+ // setUserIds(newUsers);
731
+ // dispatch(
732
+ // changeChildAction("participants", getData(newUsers).data, false)
733
+ // );
734
+
692
735
let value = ! comp . children . endCall . getView ( ) . value ;
693
736
comp . children . endCall . change ( value ) ;
694
737
comp . children . meetingActive . change ( false ) ;
0 commit comments