AgoraIO-Extensions / agora-rtc-react

Agora RTC React SDK
https://agoraio-extensions.github.io/agora-rtc-react/
MIT License
26 stars 10 forks source link

How to identify track is normal video track or shared screen ? #187

Closed nileshzala005 closed 5 months ago

nileshzala005 commented 5 months ago

What kind of problem do you need help?

This hooks useRemoteUsers return remote users list with remote video track and shared screen track const remoteUsers = useRemoteUsers();

How to identify track is normal video track or shared screen ?

guoxianzhe commented 5 months ago

@nileshzala005

check the sample code you can identify by UID.

ttebify commented 1 month ago

Like @guoxianzhe mentioned, you can identify by UID.

Here is another creative approach. On your server, embed some information into the token to identify a screen share client and retrieve the token via UID. Decode and use it normally. Here is an example:

client.on("user-published", async (participant, mediaType) => {
    const remoteId = participant.uid as string;
    const clientData = decodeData(remoteId);

    if (clientData?.id !== user?.id) {
        await client.subscribe(participant, mediaType);

        if (mediaType === "audio") {
            participant.audioTrack?.play();
        }
    }

    if (clientData?.screen_share) { // Here I know it is a screen share client
        setHighlightedParticipant(remoteId);
    }
});

Here is a reference to see how this token can be created on the server: https://github.com/AgoraIO-Extensions/agora-rtc-react/issues/199#issuecomment-2260876956