@@ -196,7 +196,6 @@ const publishVideo = async (
196
196
await client . publish ( videoTrack ) ;
197
197
198
198
await rtmInit ( appId , userId , channel ) ;
199
-
200
199
} ;
201
200
202
201
const sendMessageRtm = ( message : any ) => {
@@ -270,6 +269,8 @@ let MTComp = (function () {
270
269
} ) ;
271
270
const [ rtmMessages , setRtmMessages ] = useState < any > ( [ ] ) ;
272
271
const [ localUserSpeaking , setLocalUserSpeaking ] = useState < any > ( false ) ;
272
+ const [ localUserVideo , setLocalUserVideo ] =
273
+ useState < IAgoraRTCRemoteUser > ( ) ;
273
274
const [ userJoined , setUserJoined ] = useState < IAgoraRTCRemoteUser > ( ) ;
274
275
const [ userLeft , setUserLeft ] = useState < IAgoraRTCRemoteUser > ( ) ;
275
276
@@ -278,7 +279,8 @@ let MTComp = (function () {
278
279
let userData = {
279
280
user : userJoined . uid ,
280
281
host : false ,
281
- audiostatus : userJoined . hasVideo ,
282
+ audiostatus : userJoined . hasAudio ,
283
+ streamingVideo : true ,
282
284
} ;
283
285
setUserIds ( ( userIds : any ) => [ ...userIds , userData ] ) ;
284
286
if ( userIds . length == 0 ) {
@@ -312,12 +314,9 @@ let MTComp = (function () {
312
314
}
313
315
useEffect ( ( ) => {
314
316
if ( userLeft ) {
315
- console . log ( "user left" , userLeft . uid ) ;
316
- console . log ( "all users " , userIds ) ;
317
317
let newUsers = userIds . filter (
318
318
( item : any ) => item . user !== userLeft . uid
319
319
) ;
320
- console . log ( "after user left " , newUsers ) ;
321
320
let hostExists = newUsers . filter ( ( f : any ) => f . host === true ) ;
322
321
if ( hostExists . length == 0 && newUsers . length > 0 ) {
323
322
newUsers [ 0 ] . host = true ;
@@ -353,12 +352,18 @@ let MTComp = (function () {
353
352
}
354
353
} , [ updateVolume ] ) ;
355
354
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]);
355
+ useEffect ( ( ) => {
356
+ let prevUsers : [ ] = props . participants as [ ] ;
357
+ const updatedItems = prevUsers . map ( ( userInfo : any ) => {
358
+ if ( userInfo . user === localUserVideo ?. uid ) {
359
+ return { ...userInfo , streamingVideo : localUserVideo ?. hasVideo } ;
360
+ }
361
+ return userInfo ;
362
+ } ) ;
363
+ dispatch (
364
+ changeChildAction ( "participants" , getData ( updatedItems ) . data , false )
365
+ ) ;
366
+ } , [ localUserVideo ?. hasVideo ] ) ;
362
367
363
368
useEffect ( ( ) => {
364
369
if ( rtmMessages ) {
@@ -369,7 +374,7 @@ let MTComp = (function () {
369
374
} , [ rtmMessages ] ) ;
370
375
371
376
useEffect ( ( ) => {
372
- if ( localUserSpeaking === true ) {
377
+ if ( localUserSpeaking === true || localUserVideo ) {
373
378
let localObject = {
374
379
user : userId + "" ,
375
380
audiostatus : props . audioControl . value ,
@@ -380,18 +385,6 @@ let MTComp = (function () {
380
385
}
381
386
} , [ localUserSpeaking ] ) ;
382
387
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]);
394
-
395
388
useEffect ( ( ) => {
396
389
if ( rtmChannelResponse ) {
397
390
rtmClient . on ( "MessageFromPeer" , function ( message , peerId ) {
@@ -429,6 +422,21 @@ let MTComp = (function () {
429
422
}
430
423
} ) ;
431
424
} ) ;
425
+
426
+ client . on (
427
+ "user-published" ,
428
+ async ( user : IAgoraRTCRemoteUser , mediaType : "video" | "audio" ) => {
429
+ setLocalUserVideo ( user ) ;
430
+ }
431
+ ) ;
432
+ client . on (
433
+ "user-unpublished" ,
434
+ ( user : IAgoraRTCRemoteUser , mediaType : "video" | "audio" ) => {
435
+ console . log ( "user-unpublished" ) ;
436
+
437
+ setLocalUserVideo ( user ) ;
438
+ }
439
+ ) ;
432
440
}
433
441
} , [ client ] ) ;
434
442
@@ -600,13 +608,16 @@ MTComp = withMethodExposing(MTComp, [
600
608
params : [ ] ,
601
609
} ,
602
610
execute : async ( comp , values ) => {
611
+ //check if meeting is active
603
612
if ( ! comp . children . meetingActive . getView ( ) . value ) return ;
613
+ //toggle videoControl
604
614
let value = ! comp . children . videoControl . getView ( ) . value ;
605
615
if ( videoTrack ) {
606
616
videoTrack . setEnabled ( value ) ;
607
617
} else {
608
618
await turnOnCamera ( value ) ;
609
619
}
620
+ //change my local user data
610
621
let localData = {
611
622
user : userId + "" ,
612
623
streamingVideo : value ,
@@ -717,20 +728,6 @@ MTComp = withMethodExposing(MTComp, [
717
728
} ,
718
729
execute : async ( comp , values ) => {
719
730
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
731
735
732
let value = ! comp . children . endCall . getView ( ) . value ;
736
733
comp . children . endCall . change ( value ) ;
0 commit comments