feross / simple-peer

📡 Simple WebRTC video, voice, and data channels
MIT License
7.44k stars 975 forks source link

Mute own microphone #889

Closed pjebs closed 2 years ago

pjebs commented 2 years ago

There seems to be no way way to mute my own microphone.

I can mute other person's mic so that I can't hear them. But I can't stop other person from hearing me.

pjebs commented 2 years ago

The answer is:

if (window.SimplePeerInstance) {
        let streams = window.SimplePeerInstance.streams;
        if (streams.length === 0) {
            return;
        }

        let stream = streams[0];

        let tracks = stream.getAudioTracks();
        if (tracks.length === 0) {
            return;
        }

        for (let track of tracks) {
            track.enabled = !track.enabled;
        }
    }

, where window.SimplePeerInstance is the simple-peer object from new Peer()