What Philip says. Also clear all links to the stream so that it can be freed. Here you have an error:
live.src = stream;
(src URL-, ). , , window.URL , WebRTC. createObjectURL . :
if (typeof live.srcObject == "object") {
live.srcObject = stream;
} else {
live.src = window.URL.createObjectURL(stream)
}
live.srcObject = stream, srcObject WebRTC (Chrome 54+). , , live.srcObject = null, , ( , track.stop() ).
createObjectURL , revokeObjectURL. , , , , , , .
. 2 , . srcObject (https Chrome):
( Cam ~ 10 Firefox, ~ 20 Chrome.)
var wait = ms => new Promise(resolve => setTimeout(resolve, ms));
navigator.mediaDevices.getUserMedia({video: true})
.then(stream => video.srcObject = stream)
.then(() => wait(2000))
.then(() => video.srcObject = null)
.catch(e => console.log(e.name + ": "+ e.message));
<video id="video" width="160" height="120" autoplay></video>
Hide resultcreateObjectURL ( revokeObjectURL) (https Chrome):
( .)
var wait = ms => new Promise(resolve => setTimeout(resolve, ms));
navigator.mediaDevices.getUserMedia({video: true})
.then(stream => video.src = URL.createObjectURL(stream))
.then(() => wait(2000))
.then(() => video.srcObject = null)
.catch(e => console.log(e.name + ": "+ e.message));
<video id="video" width="160" height="120" autoplay></video>
Hide resulttrack.stop(), , , , , , , . createObjectURL.