webrtc icon indicating copy to clipboard operation
webrtc copied to clipboard

Add a Mute/Unmute Button?

Open Ruok2bu opened this issue 2 years ago • 0 comments

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;
};

Ruok2bu avatar Jul 29 '22 06:07 Ruok2bu