webrtc
webrtc copied to clipboard
Add a Mute/Unmute Button?
I added the following code (i found online) to add a mute/unmute button and it doesnt work. Any idea why?
In index.html i added:
<button id="mute_btn" onclick="muteBtnClick()">Mute Mic</button>
In script.js i added at the very bottom:
function muteBtnClick() {
var btn = document.getElementById("mute_btn");
if (isMicMuted()) {
muteMic(false);
btn.innerHTML = "Mute Mic";
} else {
muteMic(true);
btn.innerHTML = "Unmute Mic";
}
}
function isMicMuted() {
return !(localStream.getAudioTracks()[0].enabled); }
function muteMic (mute) {
localStream.getAudioTracks()[0].enabled = !mute;
};