0

Is there a way in javascript to check if Browser(Any Browser) is waiting for user to Allow permission for Microphone or Camera?

enter image description here

Note:- Based on this, I want to determine if media permission was already saved. i.e. if permission is saved then the popup will not appear.

EDIT

MEDIA = ( navigator.webkitGetUserMedia     ||
          navigator.mozGetUserMedia        ||
          navigator.msGetUserMedia         ||
          navigator.getUserMedia           );

get_user_media: function() {
  jQuery("instruction_image_id").show();

  (MEDIA.bind(navigator))(
    {audio: true, video: false},
    media_success(),
    media_error()
  );
}

media_success: function() {
  jQuery("instruction_image_id").hide();
}

EDIT

Note:- I need a Cross Browser solution. THIS(Marked as duplicate) thread's solution works well only with Chrome.

Community
  • 1
  • 1
Abhi
  • 4,123
  • 6
  • 45
  • 77
  • `Based on this, I want to determine if media permission was already saved` Why do you need that? – A. Wolff Dec 15 '15 at 10:56
  • 1
    @A.Wolff Because I want to show an image that has visual instructions that asks user to click on **Allow** and this image gets hidden in the success block of **getUserMedia**. If permissions are saved then this image fluctuates. – Abhi Dec 15 '15 at 11:04
  • So you can use any kind of persistent data client side which you set the first time your user allow it (localStorage). Then check for it. But what you ask could be a XY problem in fact, not sure about it – A. Wolff Dec 15 '15 at 11:12
  • 2
    I tried using `localStorage`, but user always has option to revoke the permissions from browser settings, then I don't know how to reset `localStorage` – Abhi Dec 15 '15 at 11:36

1 Answers1

0

The time between waiting can be checked here, see start and end of permission:

// Start the permission.
navigator.getUserMedia (
  // constraints
  {
    video: true,
    audio: true
  },

  // successCallback
  function(localMediaStream) {
    // End the permission
    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
    }
  }
);
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252