Stop/Close webcam stream which is opened by navigator.mediaDevices.getUserMedia [closed] Stop/Close webcam stream which is opened by navigator.mediaDevices.getUserMedia [closed] javascript javascript

Stop/Close webcam stream which is opened by navigator.mediaDevices.getUserMedia [closed]


EDIT

Since this answer has been originally posted the browser API has changed..stop() is no longer available on the stream that gets passed to the callback.The developer will have to access the tracks that make up the stream (audio or video) and stop each of them individually.

More info here: https://developers.google.com/web/updates/2015/07/mediastream-deprecations?hl=en#stop-ended-and-active

Example (from the link above):

stream.getTracks().forEach(function(track) {  track.stop();});