Skip to content

Multiple remote users gets unpublished on unpublishing one remote user #359

Description

@ahmedbashir-veraio

This is my useEffect code. I have subscribed to the user-joined, user-unpublished events. When multiple remote users join the channel, their video gets published successfully. When any of the remote user leaves the channel, all remote users get unpublished somehow.
useEffect(() => {
let initClientCallbacks = () => {
videoCallContext.client.on("user-published", async (remoteUser, mediaType) => {
await videoCallContext.client.subscribe(remoteUser, mediaType);
if (mediaType == "video") {
console.log("subscribe video success");
// remoteUser.videoTrack.play(document.getElementById("subscriber"));
setUsers((prevUsers) => {
return [...prevUsers, remoteUser];
});
}
if (mediaType == "audio") {
console.log("subscribe audio success");
remoteUser.audioTrack.play();
}
const p = document.getElementById('publisher');
p.style.width = '30%';
p.style.height = '30%';
p.style.left = '10px';
p.style.bottom = '10px';
})

        videoCallContext.client.on("user-unpublished", async (user, type) => {
            if (user.uid === leavingUserUidRef.current) {
                return;
            }

            console.log("unpublished", user, type);

            if (type === "audio") {
                user.audioTrack?.stop();
            }

            if (type === "video") {
                setUsers((prevUsers) => {
                    return prevUsers.filter((User) => User.uid !== user.uid);
                });
            }

            setInitiatePolling(true);
        });

        videoCallContext.client.on("user-left", (user) => {
            console.log("leaving", user);
            console.log("leaving id", user.uid);
            leavingUserUidRef.current = user.uid;
            setUsers((prevUsers) => {
                return prevUsers.filter((User) => User.uid !== user.uid);
            });
            setInitiatePolling(true);
        });


    }

    initClientCallbacks();


}, [appointmentInformation?.id]);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions