Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron disable specific camera device access or set default webcam

We are using atom electron to run an app in a "kiosk" type setting, we have 4 webcam devices connected to the physical computer, we want specifically 1 of those to be used for webrtc inside of the electron browser, then other 3 we use some C code to capture still frames. We know the USB path or the /dev/video{#} for the device we want.

Is there a way to either disable access by the view layer to the 3 webcams in node before we launch the electron window? Or another option is to set the default camera before we launch the view layer so that it will default to the webcam we want.

In the view layer we can get a list of devices and see if they are audio or video, but we can't get their /dev/video# or their USB path to figure out which one is the target webrtc cam, so this has not been very helpful yet.

Any help is great, I feel weird for having to post a question since for the last 12 years I have been able to find what I needed by searching, but its been about 3 hours so its time to ask for help.

like image 565
DrFrow Avatar asked Sep 13 '25 10:09

DrFrow


1 Answers

I don't think Chromium provides a way to retrieve the USB path for a media source. You'll probably need to display a configuration screen to allow the user to select the correct camera (similar to this demo) the first time around and then use the source/device id as a mandatory constraint from that point on.

Another option is to find the correct camera based on the device label, though obviously this will only work if each camera has a distinct label. You can get all the device labels and ids by running this snippet in the DevTools console:

navigator.mediaDevices.enumerateDevices()
.then(devices => devices.forEach(
  device => console.log(`kind: ${device.kind}: ${device.label} id=${device.deviceId}`)
))
.catch(err => console.log(err));

Either way, once you have the source/device id you can specify it as a mandatory constraint to ensure that only that one particular camera is used:

navigator.webkitGetUserMedia(
  {
    audio: false,
    video: {
      mandatory: {
        chromeMediaSourceId: 'the camera source id obtained earlier',
      }
    }
  },
  stream => console.dir(stream),
  error => console.log(error)
);
like image 166
Vadim Macagon Avatar answered Sep 15 '25 01:09

Vadim Macagon