I starts webcam stream in my web page using navigator.mediaDevices.getUserMedia. I want to get some callback event when user explicitly blocking camera from the tab option ('Pause' on safari & 'Always block camera' option in chrome).
I attached chrome screenshot just to clear the problem.
When user allows permission first time and then blocking camera using above option then there is no event being triggered at my code. I tried searching for such events but did not find anything. I just wanted to show some message to user on blocking the camera. Following is my full code using to start webcam stream.
function startCamera() {
if (streaming) return;
navigator.mediaDevices.getUserMedia({video: true, audio: false})
.then(function(s) {
stream = s;
video.srcObject = s;
video.play();
console.log("Start camera");
isCameraCap = true;
})
.catch(function(err) {
//executing when user disallow permission
console.log(`Stop camera at error ${err}`);
console.log("An error occured! " + err);
isCameraCap = true;
});
video.addEventListener("canplay", function(ev){
if (!streaming) {
videoWidth = video.videoWidth;
videoHeight = video.videoHeight;
video.setAttribute("width", videoWidth);
video.setAttribute("height", videoHeight);
canvasOutput.width = videoWidth;
canvasOutput.height = videoHeight;
streaming = true;
}
startVideoProcessing();
}, false);
}
