Stop / kill WebRTC media stream

2020-02-12 04:54发布

问题:

How to completely kill the WebRTC media stream?

MediaStream.stop() is not working anymore.

Testing in Chrome 47, Mac OS 10.11.

回答1:

Use stream.getTracks().forEach(track => track.stop());.

stream.stop() was deprecated.



回答2:

For all browsers

if (microphone_data.media_stream) {
    microphone_data.media_stream.getTracks().forEach(function (track) { track.stop(); });
}