0

one of the users reported me a weird issue :

in the remote debugging I've done, first the apps runs this function:

navigator.permissions.query({name: 'microphone'})
  .then(async (permission) => {

    alert(permission.state); // it returns prompt
    const success = await check(permission.state);

  }).catch(e => {

    resolve();

  });

The permission.state in the above code returns prompt Not denied, ok?

then the check function checks the mic permissions:

function check() {
  return new Promise((resolve, reject) => {
    navigator.mediaDevices.getUserMedia({
      audio: true
    }).then(stream => {
     
      resolve();
    }).catch(err => {
      console.log(err.name) //NotAllowedError
      resolve();
    });
  });
}

Here the console.log(err.name) returns the NotAllowedError

if the navigator.permissions.query({name: 'microphone'}) returns prompt how the navigator.mediaDevices.getUserMedia returns the NotAllowedError it doesn't make sense to me ?

What is your suggestion ? How to fix this issue?

Sara Ree
  • 3,417
  • 12
  • 48
  • Avoid the [`Promise` constructor antipattern](https://stackoverflow.com/q/23803743/1048572?What-is-the-promise-construction-antipattern-and-how-to-avoid-it)! – Bergi Nov 28 '22 at 17:49
  • "*query returns `prompt`, how getUserMedia returns `NotAllowedError` - it doesn't make sense to me?*" - sounds very much like the user was prompted and denied access. – Bergi Nov 28 '22 at 17:54
  • no, if he/she denied access then query returns denied at the first point not prompt – Sara Ree Nov 28 '22 at 17:57
  • Why would it have returned denied *before* the user was prompted? – Bergi Nov 28 '22 at 17:58
  • query returns prompt because user not denied the permission yet, then without denying anything we get the `NotAllowedError` . that's the issue... – Sara Ree Nov 28 '22 at 18:01
  • How do you know that it happened "*without denying anything*"? Calling `navigator.mediaDevices.getUserMedia()` opens the prompt, and that can be denied. – Bergi Nov 28 '22 at 20:54

0 Answers0