const startCall = async (client) => {
if (!client) return;
try {
await client.join(sessionName, token, fname);
const stream = client.getMediaStream();
// await stream.startAudio();
await stream.startVideo();
setMediaStream(stream);
setIsJoined(true);
// Automatically mute participants
const currentUser = client.getCurrentUserInfo();
// console.log('currentUser',!currentUser.isHost,currentUser.isHost)
// if (!currentUser.isHost) {
// //await stream.startAudio();
// // await stream.stopAudio(); // Automatically mute participants
// await stream.stopVideo(); // Prevent participant from starting video
// }
// if (currentUser.isHost) {
// await stream.startAudio();
// }
if (currentUser.isHost) {
await stream.startAudio(); // ✅ Only host can speak
await stream.startVideo();
} else {
// await stream.stopAudio();
await stream.startAudio(); // ✅ Only host can speak
await stream.stopVideo();
await stream.muteAudio();
}
const chat = client.getChatClient();
setChatClient(chat);
client.on("chat-on-message", (payload) => {
setChatHistory((prevHistory) => [
...prevHistory,
{ message: payload.message, sender: payload.sender.name },
]);
});
// Event listeners for video and audio changes
client.on("peer-video-state-change", renderVideo);
client.on("peer-audio-state-change", handleAudioChange);
client.on("user-added", updateParticipants);
client.on("user-removed", updateParticipants);
client.on("connection-change",handleConnectionChange)
// dddddd();
// Update participants list
updateParticipants();
// Attach only the host's video if available
const participantsList = client.getAllUser();
// console.log('participantsList',participantsList)
const host = participantsList.find((user) => user.isHost);
// console.log('host',host)
setHostId(host?.userId);
if (host && host.bVideoOn) {
// console.log(
// "Host is detected and has video on. Attaching host video..."
// );
const hostVideo = await stream.attachVideo(
host.userId,
VideoQuality.Video_360P
);
if (hostVideo) {
videoContainerRef.current.appendChild(hostVideo);
} else {
console.error("Failed to attach host video immediately.");
}
}
} catch (error) {
console.error("Error joining Zoom session:", error);
}
};
This is my start meeting code on the participant’s side and I am using @zoom/videosdk library.