Skip to content

Add a Mute/Unmute Button? #23

@Ruok2bu

Description

@Ruok2bu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions