Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better listVideoInputDevices check in BrowserCodeReader.ts #141

Open
nicoesiea opened this issue Jan 6, 2025 · 0 comments
Open

Add better listVideoInputDevices check in BrowserCodeReader.ts #141

nicoesiea opened this issue Jan 6, 2025 · 0 comments

Comments

@nicoesiea
Copy link

nicoesiea commented Jan 6, 2025

The function listVideoInputDevices (in the BrowserCodeReader.ts file) lists all the available video input devices. It could be nice to force the label with a known value to have a way to make a distinction with environemental and selfie camera.
I'm thinking on an example of code, like:

navigator.mediaDevices .enumerateDevices() .then(function (devices) {
  const videoDevices = devices.filter(
    (device) => device.kind === "videoinput"
  );
  videoDevices.forEach((device) => {

  navigator.mediaDevices
    .getUserMedia({ video: { deviceId: device.deviceId } })
    .then((stream) => {
      const track = stream.getVideoTracks()[0];
      const settings = track.getSettings();
      
      alert("Camera:" + device.label);
      alert("Settings:" + JSON.stringify(settings));

      // Hypothèse : the selfie camera are mirror option set
      if (settings.facingMode === "user") {
        alert("It seems this is selfie camera");
      } else if (settings.facingMode === "environment") {
        alert("It seems this is environmental camera.");
      } else {
        alert("Here we do not know.");
      }

      // Stop
      track.stop();
    })
    .catch((err) => {
      console.error("Error", device.deviceId, err);
    });
});
})
.catch(function (err) {
  console.error("Error to get the camera:" + err);
});

Maybe there is a better solution to do this check. I will be very happy to discover it.
Thank you in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant