Skip to main content
Version: 1.x.x

Camera Controls - Javascript

Whenever any participant wants to start/stop broadcasting their video to other participant in a meeting, they can simply do it with VideoSDK Meeting.

note

This page uses the following asynchronous methods. Refer to their API reference for the errors each Promise may reject with, and handle these rejections appropriately based on your use case.

This guide will provide an overview of how to implement enable, disable and switch webcam features in a meeting.

  1. Enable Camera - By using enableWebcam() function, a participant can publish camera stream to other participants.
  2. Disable Camera - By using disableWebcam() function, a participant can stop publishing camera stream to other participants.
  3. Switch Camera - By using changeWebcam() function, a participant can stream from front / rear camera during the meeting.This function is only applicable for Mobile devices.

Enable, Disable And Switch Webcam

const onPress = async () => {
// Enable Webcam in Meeting
try {
await meeting?.enableWebcam();
} catch (err) {
console.error("enableWebcam failed:", err);
}

// Disable Webcam in Meeting
try {
await meeting?.disableWebcam();
} catch (err) {
console.error("disableWebcam failed:", err);
}

// Change Webcam in Meeting
let webcams;
try {
webcams = await meeting?.getWebcams(); // returns all webcams
} catch (err) {
console.error("getWebcams failed:", err);
}

const { deviceId, label } = webcams[0];

try {
await meeting?.changeWebcam(deviceId);
} catch (err) {
console.error("changeWebcam failed:", err);
}
};

Events

Events associated with enableWebcam():

Events associated with disableWebcam():

participant.on("stream-enabled", (stream) => {
if (stream.kind === "video") {
//particiapnt turned on video
//Render Participant video logic here
}
});

participant.on("stream-disabled", (stream) => {
if (stream.kind === "video") {
//particiapnt turned off video
//remove Participant video logic here
}
});

Got a Question? Ask us on discord