Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toggle remote camera is not update #2004

Open
Mrezagolbaba opened this issue May 18, 2023 · 3 comments
Open

toggle remote camera is not update #2004

Mrezagolbaba opened this issue May 18, 2023 · 3 comments
Assignees
Labels
help wanted Issues, feature requests, or enhancement we'd like help on or would receive PRs for

Comments

@Mrezagolbaba
Copy link

we want to toggle remote participants for show their avatar id disable in first attempt but when we want to enable again it doesn’t work I think this useEffect doesn’t trigger for next time
do we have any other properties when the remote participant change the camera or mic?

useEffect(() => {   
      if (room) {
        setParticipants([]);
    
        const participantConnected = (participant: any) => {
          setParticipants((prevParticipants): any => [...prevParticipants, participant]);
        };
    
        const participantDisconnected = (participant: any) => {
          setParticipants((prevParticipants) => prevParticipants.filter((p) => p !== participant));
        };
    
        let trackDisabledEnabled = false; // Flag to control event registration
    
        const trackDisabled = (track: any, participant: any) => {
          if (track.kind === 'video') {
            // Handle the remote user disabling their video
            setRemoteCamStatus(true);
          }
        };
    
        const trackEnabled = (track: any, participant: any) => {
          if (track.kind === 'video') {
            // Handle the remote user enabling their video
            setRemoteCamStatus(false);
          }
        };
    
        room.on('participantConnected', participantConnected);
        room.on('participantDisconnected', participantDisconnected);
    
        // Register trackDisabled and trackEnabled event listeners conditionally
        if (!trackDisabledEnabled) {
          room.on('trackDisabled', trackDisabled);
          room.on('trackEnabled', trackEnabled);
          trackDisabledEnabled = true;
        }
    
        room?.participants.forEach(participantConnected);
    
        return () => {
          room.off('participantConnected', participantConnected);
          room.off('participantDisconnected', participantDisconnected);
          room.off('trackDisabled', trackDisabled);
          room.off('trackEnabled', trackEnabled);
        };
      }
    }, [room])

we used Next js and Typescript in this code

@manjeshbhargav
Copy link
Collaborator

Hi @Mrezagolbaba ,

Sorry for the delayed response. Can you try listening to the enabled and disabled events on the RemoteVideoTrack instead of the events on the Room? Please let me know if that works.

@manjeshbhargav manjeshbhargav self-assigned this Jun 2, 2023
@manjeshbhargav manjeshbhargav added the help wanted Issues, feature requests, or enhancement we'd like help on or would receive PRs for label Jun 2, 2023
@Mrezagolbaba
Copy link
Author

Hi @manjeshbhargav thanks
I check this method but it doesn’t work

      const trackDisabled = (track, participant) => {
            if (track.kind === 'video') {
                // Handle the remote user disabling their video
                setRemoteCamStatus(true);
            }
        };
        const trackEnabled = (track, participant) => {
            if (track.kind === 'video') {
                // Handle the remote user enabling their video
                setRemoteCamStatus(false);
            }
        };
        RemoteVideoTrack.on( 'enabled' , trackEnabled );
        RemoteVideoTrack.on( 'disabled' , trackDisabled );

@Mrezagolbaba
Copy link
Author

based on documentation, I found this solution
it works on my code

   const handleTrackDisabled=(track:any)=> {
           track.on('disabled', () => {
             
             setRemoteCamStatus(true);
           });
           track.on('enabled', () => {
               setRemoteCamStatus(false);
             });
         }
         
         room.participants.forEach((participant: { tracks: any[]; }) => {
           participant.tracks.forEach(publication => {
             if (publication.isSubscribed) {
               handleTrackDisabled(publication.track);
             }

             publication.on('subscribed', handleTrackDisabled);
           });
         });
         ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues, feature requests, or enhancement we'd like help on or would receive PRs for
Projects
None yet
Development

No branches or pull requests

2 participants