-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
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]);