@@ -196,7 +196,6 @@ const publishVideo = async (
196196 await client . publish ( videoTrack ) ;
197197
198198 await rtmInit ( appId , userId , channel ) ;
199-
200199} ;
201200
202201const sendMessageRtm = ( message : any ) => {
@@ -270,6 +269,8 @@ let MTComp = (function () {
270269 } ) ;
271270 const [ rtmMessages , setRtmMessages ] = useState < any > ( [ ] ) ;
272271 const [ localUserSpeaking , setLocalUserSpeaking ] = useState < any > ( false ) ;
272+ const [ localUserVideo , setLocalUserVideo ] =
273+ useState < IAgoraRTCRemoteUser > ( ) ;
273274 const [ userJoined , setUserJoined ] = useState < IAgoraRTCRemoteUser > ( ) ;
274275 const [ userLeft , setUserLeft ] = useState < IAgoraRTCRemoteUser > ( ) ;
275276
@@ -278,7 +279,8 @@ let MTComp = (function () {
278279 let userData = {
279280 user : userJoined . uid ,
280281 host : false ,
281- audiostatus : userJoined . hasVideo ,
282+ audiostatus : userJoined . hasAudio ,
283+ streamingVideo : true ,
282284 } ;
283285 setUserIds ( ( userIds : any ) => [ ...userIds , userData ] ) ;
284286 if ( userIds . length == 0 ) {
@@ -312,12 +314,9 @@ let MTComp = (function () {
312314 }
313315 useEffect ( ( ) => {
314316 if ( userLeft ) {
315- console . log ( "user left" , userLeft . uid ) ;
316- console . log ( "all users " , userIds ) ;
317317 let newUsers = userIds . filter (
318318 ( item : any ) => item . user !== userLeft . uid
319319 ) ;
320- console . log ( "after user left " , newUsers ) ;
321320 let hostExists = newUsers . filter ( ( f : any ) => f . host === true ) ;
322321 if ( hostExists . length == 0 && newUsers . length > 0 ) {
323322 newUsers [ 0 ] . host = true ;
@@ -353,12 +352,18 @@ let MTComp = (function () {
353352 }
354353 } , [ updateVolume ] ) ;
355354
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 ] ) ;
362367
363368 useEffect ( ( ) => {
364369 if ( rtmMessages ) {
@@ -369,7 +374,7 @@ let MTComp = (function () {
369374 } , [ rtmMessages ] ) ;
370375
371376 useEffect ( ( ) => {
372- if ( localUserSpeaking === true ) {
377+ if ( localUserSpeaking === true || localUserVideo ) {
373378 let localObject = {
374379 user : userId + "" ,
375380 audiostatus : props . audioControl . value ,
@@ -380,18 +385,6 @@ let MTComp = (function () {
380385 }
381386 } , [ localUserSpeaking ] ) ;
382387
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-
395388 useEffect ( ( ) => {
396389 if ( rtmChannelResponse ) {
397390 rtmClient . on ( "MessageFromPeer" , function ( message , peerId ) {
@@ -429,6 +422,21 @@ let MTComp = (function () {
429422 }
430423 } ) ;
431424 } ) ;
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+ ) ;
432440 }
433441 } , [ client ] ) ;
434442
@@ -600,13 +608,16 @@ MTComp = withMethodExposing(MTComp, [
600608 params : [ ] ,
601609 } ,
602610 execute : async ( comp , values ) => {
611+ //check if meeting is active
603612 if ( ! comp . children . meetingActive . getView ( ) . value ) return ;
613+ //toggle videoControl
604614 let value = ! comp . children . videoControl . getView ( ) . value ;
605615 if ( videoTrack ) {
606616 videoTrack . setEnabled ( value ) ;
607617 } else {
608618 await turnOnCamera ( value ) ;
609619 }
620+ //change my local user data
610621 let localData = {
611622 user : userId + "" ,
612623 streamingVideo : value ,
@@ -717,20 +728,6 @@ MTComp = withMethodExposing(MTComp, [
717728 } ,
718729 execute : async ( comp , values ) => {
719730 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- // );
734731
735732 let value = ! comp . children . endCall . getView ( ) . value ;
736733 comp . children . endCall . change ( value ) ;
0 commit comments