I am building a react app and need to access the webcam which get with the following code:
navigator.mediaDevices.getUserMedia({ video: true, audio: false })
.then(function(stream) {
video.srcObject = stream;
window.localstream = stream;
video.play();
})
However, when I unmount the current component, my webcam stays on. In my componentWillUnmount block, I have tried the following code.
video.pause();
video.srcObject=null;
window.localstream.getTracks()[0].stop();
window.localstream.getVideoTracks()[0].stop();
My webcam light still stays on however. When I console.log the mediaStreamTrack afterwards, I get:
How do I stop my webcam?