Mute / Unmute Mic - Javascript
Muting and Unmuting your microphone refers to turning your microphone off and on, respectively.
Muting your microphone prevents the transmission of any sound from your microphone to other meeting participants, while unmuting allows them to hear you.
unmuteMic()
-
By using the
unmuteMic()
function of themeeting
object, the local participant can publish their audio to other participants.- You can only call this method when the local participant is not broadcasting audio to others.
-
You can also pass a customised audio track in
unmuteMic()
by using Custom Audio Track. -
Audio stream of the participant can be accessed from the
streams
property of theParticipant
object.
muteMic()
-
By using the
muteMic()
function of themeeting
object, the local participant can stop publishing their audio to other participants. -
You can only call this method when the local participant is broadcasting audio to others.
Example
let meeting;
// Initialize Meeting
meeting = VideoSDK.initMeeting({
// ...
});
const unmuteMicBtn = document.getElementById("unmuteMicBtn");
unmuteMicBtn.addEventListener("click", () => {
// unmuteMic Meeting
meeting?.unmuteMic();
});
const muteMicBtn = document.getElementById("muteMicBtn");
muteMicBtn.addEventListener("click", () => {
// unmuteMic Meeting
meeting?.muteMic();
});
To learn, how to render a audio in the meeting, follow this detailed guide.
Events associated with unmuteMic
-
Every Participant will receive a callback on
stream-enabled
event of theparticipant
object with theStream
object. -
Every Participant will receive a callback on
media-status-changed
event of theparticipant
object with the type of media and its status.
Events associated with muteMic
-
Every Participant will receive a callback on
stream-disabled
event of theparticipant
object with theStream
object. -
Every Participant will receive a callback on
media-status-changed
event of theparticipant
object with the type of media and its status.
const participants = meeting.participants;
const participant = participants.get("<participant-id>");
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
}
});
participant.on("media-status-changed", (data) => {
const { kind, newStatus } = data;
if (kind === "audio") {
//particiapnt media status changed
}
});
Audio Permissions
- By default, VideoSDK will request audio permission when a participant attempts to turn on the mic. Once the permission is granted, the mic is activated. If the permission is denied, VideoSDK will send an error message in the
onError
event callback of themeeting
object.
Troubleshoot Audio Permissions
- If a participant denies the microphone permission, they can manually grant it by following the below shown steps.
To use the audio and video communications in the web browser, your site must be SSL enabled
i.e. it must be secured and running on https
.
API Reference
The API references for all the methods and events utilized in this guide are provided below.
Got a Question? Ask us on discord