0
votes

Does .getusermedia() always require mic permissions even if my use case doesn't require any audio input?

Is there a way to make it work by asking and using ONLY camera?

I'm using the sample below - https://webrtc.github.io/samples/src/content/getusermedia/gum/ - it looks like audio constraint is false - but is that audio input?

2

2 Answers

0
votes

Does .getusermedia() always require mic permissions even if my use case doesn't require any audio input?

No (but will typically keep asking for camera permissions depending on browser).

Is there a way to make it work by asking and using ONLY camera?

Yes, your link provides the code for this. By setting audio: false means it will not seek Mic permissions, not take in audio and not output audio. It would use the default camera and provide the video only.

If you flip video to false and audio to true chrome asks you for Mic permissions only. However depending on browser you will be asked for camera permissions either for the first session or for each session.

I'm using the sample below - https://webrtc.github.io/samples/src/content/getusermedia/gum/ - it looks like audio constraint is false - but is that audio input?

audio:true would use the default audio input and output on your device, you can specify other sources (video, audio input and audio output) via deviceId. By using the example code you posted with audio set to false you are only seeking camera permissions. If you set it to true it will use the default audio input (typically the same device as the camera) and output (speakers).

What is confusing is the permissions pop up. If you seek audio only it asks "website_name wants to use your microphone". If you seek camera only it asks "website_name wants to use your camera", and the same message is asked if you seek video and audio.

You can test this by blocking mic permissions in chrome here: chrome://settings/content/siteDetails?site=https%3A%2F%2Fwebrtc.github.io%3A443 for https://webrtc.github.io/samples/src/content/getusermedia/gum/

Or on android going to settings -> site settings -> microphone -> block

Using the link you provided (with audio:false) it still works when I manually have blocked mic access on Chrome macOS, Windows 10, and Android. Typically on first run it only asks for camera permissions once on chrome.

0
votes

Pass the video and audio argument in getUserMedia. Allow or not allow by making them true or false respectively.

navigator.mediaDevices.getUserMedia({
  audio: false,
  video: true
})