How to mute microphone after recording using javascript

I have using an application to record audio which uses the javaScript code but after recording its mic will never disable.

So please suggest me that how to mute/disable microphone using javaScript?


You can stop stream created on MediaRecorder:

navigator.mediaDevices.getUserMedia({audio:true,video:false}).then(function(stream)
{
    recorder = new MediaRecorder(stream);
});
recorder.stream.getAudioTracks().forEach(function(track){track.stop();});

The previous answer is not ideal because the tracks are actually ended and cannot recover after you called track.stop();, so you cannot unmute for example. Better:

Mute

stream.getAudioTracks().forEach(function(track) {
    track.enabled = false;
});

Unmute

stream.getAudioTracks().forEach(function(track) {
    track.enabled = true;
});