reprompt for permissions with getUserMedia() after initial denial

后端 未结 5 1026
我在风中等你
我在风中等你 2020-12-02 09:56

How do we go about requesting camera/microphone access with getUserMedia() after being denied once?

I\'m working with getUserMedia to access the user\'s camera and p

5条回答
  •  一个人的身影
    2020-12-02 10:07

    jeffreyveon's answer will help reduce the chance that your user will choose deny, since she will only have to choose once.

    In case she does click deny, you can provide a message that explains why you need the permission and how to update her choice. For example:

    navigator.getUserMedia (
       // constraints
       {
          video: true,
          audio: true
       },
    
       // successCallback
       function(localMediaStream) {
          var video = document.querySelector('video');
          video.src = window.URL.createObjectURL(localMediaStream);
          video.onloadedmetadata = function(e) {
             // Do something with the video here.
          };
       },
    
       // errorCallback
       function(err) {
        if(err === PERMISSION_DENIED) {
          // Explain why you need permission and how to update the permission setting
        }
       }
    );
    

提交回复
热议问题