4

Whenever I accept the permission to use the camera on the browser, my desktop camera will light up. I would assume this is because navigator.mediaDevices.getUserMedia() returns a stream on success, and that stream is straight from the camera.

I do not want the stream from the camera instantly on acceptance of the permission.

Is there a way I could ask for permission without having to use the camera "instantly". I would use the camera later.

Artish1
  • 61
  • 9
  • 1
    You could ask for it, then immediately stop using it. When you ask for it a subsequent time it doesn't ask you again if you already said yes the first time. – Wyck Feb 13 '20 at 21:08

1 Answers1

1

I would try to immediatly stop the tracks after receiving the stream:

stream.getVideoTracks().forEach(function(track) {
    track.stop();
});

The next time you call getUserMedia it shouldn't call for permissions again. But that depends on the browser.

bitWorking
  • 11,824
  • 1
  • 30
  • 37