Mic Controls - Javascript
Whenever any participant wants to start / stop broadcasting their audio to other participant in 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 use enable and disable Mic in a meeting.
- Enable Mic - By using
unmuteMic()function, a participant can publish audio to other participants. - Disable Mic - By using
muteMic()function, a participant can stop publishing audio to other participants. - Change Mic - By using
changeMic()function, a participant can change mic.
Enable, Disable, Change Mic
note
For Javascript, we will use unmuteMic() function for publish audio to other participants and muteMic() function for stop publishing audio to other participants.
Enable, Disable Mic
const onPress = async () => {
// Enable Mic in Meeting
try {
await meeting?.unmuteMic();
} catch (err) {
console.error("unmuteMic failed:", err);
}
// Disable Mic in Meeting
try {
await meeting?.muteMic();
} catch (err) {
console.error("muteMic failed:", err);
}
// Change Mic in Meeting
let mics;
try {
mics = await meeting?.getMics(); // returns all mics
} catch (err) {
console.error("getMics failed:", err);
}
const { deviceId, label } = mics[0];
try {
await meeting?.changeMic(deviceId);
} catch (err) {
console.error("changeMic failed:", err);
}
};
Events
Event associated with unmuteMic():
stream-enabledevent will be emitted withstreamobject from the event callback, inside that participant object.
Event associated with muteMic():
stream-disabledevent will be emitted withstreamobject from the event callback, inside that participant object.
participant.on("stream-enabled", (stream) => {
if (stream.kind === "audio") {
//particiapnt turned on audio
//Render Participant audio logic here
}
});
participant.on("stream-disabled", (stream) => {
if (stream.kind === "audio") {
//particiapnt turned off audio
//remove Participant audio logic here
}
});
Got a Question? Ask us on discord

