user73636
user73636

Reputation: 79

Content Settings in Chromium Browser

Is there a way to get/set the USB Hardware ID's for Mic/Camera in Chromium browser from the command line.

I could not able to find out. The requirement is to set a particular Camera/Mic during runtime without manually updating in chrome://settings/content in the chromium browser.

It will be great if I can get some link or some sample code. Thanks !!!

Upvotes: 0

Views: 1132

Answers (1)

Gideon Pyzer
Gideon Pyzer

Reputation: 23958

You can use the --use-fake-ui-for-media-stream CLI flag to suppress the permissions dialog from showing up when you have a media stream. It will allow by default.

In terms of selecting a particular microphone or camera with a CLI flag, I don't believe it's possible. However, you can access and select the device to be used in JavaScript.

The navigator.mediaDevices.enumerateDevices object returns the following information:

  1. The device kind - audioinput or videoinput
  2. The device label - e.g. Built-in Microphone, Logitech bla, FaceTime HD Camera, etc.
  3. The device Id - e.g. bd9759740e6c29df7703d0bfg62vbbc726fcb9422fdb948a35550835a840b328
  4. The device group Id - If 2+ devices share the same physical device, they can have group Id

The Id is generated per session, so it's not something we can hardcode, but the label is unlikely to change. This means you could traverse the list and get the device Id that matches the string. I did this with async/await but you can use Promises or transpile to ES5 if need be:

(async() => {
    const getFaceTimeCamId = async() => {
        try {
            const devices = await navigator.mediaDevices.enumerateDevices();
            const faceTimeCam = devices.find(device => 
                device.kind === 'videoinput' && device.label === 'FaceTime HD Camera');
            return (faceTimeCam && faceTimeCam.deviceId) || undefined;
        } catch(err) {
            console.log(`${err.name}: ${err.message}`);
        }
    }
    console.log(await getFaceTimeCamId());
})();

You can then set the constraints object for your stream to include the deviceId you want, for example, when using MediaDevices.getUserMedia.

const constraints = {
    video: { deviceId: { exact: faceTimeCamId } }
};

I've not fully tested this as I don't have another camera or mic at hand, but hopefully this is of some help. I don't know your exact use case so probably made some assumptions.

Upvotes: 1

Related Questions