I don't know ar.js
events, and can't answer whether it has some direct way to observe this.
If you're asking for a way to hack around it, then there's no such global event in browsers. NotAllowedError
is from calling await navigator.mediaDevices.getUserMedia()
.
But if you know approximately when it's prompting the user, then you can do a parallel request, like this:
// library
(async () => {
video.srcObject = await navigator.mediaDevices.getUserMedia({video: true});
})();
// us
(async () => {
try {
await navigator.mediaDevices.getUserMedia({video: true});
console.log("GOT CAM");
} catch (e) {
console.log("GOT ERROR : " + e);
}
})();
This should give you the notification you want without causing a second user prompt.
It works because the spec mandates that getUserMedia must succeed without prompting the user again if the page already has a camera stream.
If you don't know when it'll prompt, then you'd need to override the getUserMedia
method on the navigator.mediaDevices
object. Various libraries like adapter.js do this successfully, if you need an example.