16

How to completely kill the WebRTC media stream?

MediaStream.stop() is not working anymore.

Testing in Chrome 47, Mac OS 10.11.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
igorpavlov
  • 3,576
  • 6
  • 29
  • 56

2 Answers2

44

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

stream.stop() was deprecated.

Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55
jib
  • 40,579
  • 17
  • 100
  • 158
0

For all browsers

if (microphone_data.media_stream) {
    microphone_data.media_stream.getTracks().forEach(function (track) { track.stop(); });
}
Juri Noga
  • 4,363
  • 7
  • 38
  • 51
  • 3
    What is `microphone_data` and what is `media_stream`? Those are not defined in the HTML5 media API. – Dai Nov 13 '20 at 08:11