Detecting UserMedia permission before requesting it

I would like to explain to users why a camera / microphone is needed before asking them so that they can make the best choice if they want to provide it or not.

To implement this , I need a way to determine if permission has been granted previously so that I can explain the request to the user before asking him. I also do not want to ask every time (although I already have permissions!).

+4
source share
2 answers
navigator.mediaDevices.enumerateDevices().then(devices => 
  devices.forEach(device => console.log(device.label)))

device.label == ""
device.label!= ""

+5

cookie localStorage, , .

, , - , , , .

navigator.mediaDevices.enumerateDevices, , /, , .

, , , / , . , / .

, , query, , , "camera" "microphone" ( ):

navigator.permissions.query({name: "camera"})
.then(({status}) => console.log(status),
      e => console.log(e.name +": "+ e.message));
Hide result
+3

Source: https://habr.com/ru/post/1664073/


All Articles