question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] facingMode constraint is essential for this library to work

See original GitHub issue

Very nice and clean module but… is useless without facingMode constraint, device label can be in any language making the camera choice impossible

Example:

{id: "AFB981283186FBA62F2947AA63940A4482BF80C3", label: "Πίσω κάμερα"}

Alternative, selecting between 4 options (devices), where only one option is essential its not the best user experience

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:19 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
mebjascommented, Jun 27, 2020

I can possibly exposure arguments to getCameras so you can request camera of choice and build your user interface on top of it.

You can call it like

Html5Qrcode.getCameras({ facingMode: "user" })
  .then(devices => {
    // handle the returned devices
});

or

Html5Qrcode.getCameras({ facingMode: { exact: "environment" } })
  .then(devices => {
    // handle the returned devices
});

Similar to video part of web api syntax - https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia

@dennmtr WDYT?

1reaction
max2ticommented, Sep 7, 2020

@mebjas

I’ve done some more tests and found that the problem appears only if the div used by html5qrcode is managed by Vue.js. I’ve swapped the call to Html5Qrcode#getCameras() with a call to a generic awaitable (an async/await wrapper of setTimeout) and it worked, so it’s not what Html5Qrcode#getCameras() does, any “time waster” works.

There’s probably nothing wrong with html5-qrcode, I must be doing something wrong with Vue (I’m integrating html5-qrcode in a big pre-existing vue app).

EDIT: I was calling Html5Qrcode#getCameras() before the component was fully mounted, moved it to the mounted event, now it works as expected. Sorry for having wasted some of your time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MediaTrackConstraints.facingMode - Web APIs | MDN
The MediaTrackConstraints dictionary's facingMode property is a ConstrainDOMString describing the requested or mandatory constraints placed ...
Read more >
Media Capture and Streams - W3C
This document defines a set of JavaScript APIs that allow local media, including audio and video, to be requested from a platform.
Read more >
html5-qrcode - npm Package Health Analysis - Snyk
Use this lightweight library to easily / quickly integrate QR code, bar code, ... type of code would be helpful to have, please...
Read more >
javascript - GetUserMedia - facingmode - Stack Overflow
facingMode is not yet implemented in Chrome for Android, but works natively in Firefox for Android. You must use standard constraints however: ( ......
Read more >
How To Access Front and Rear Cameras with JavaScript's ...
The getUserMedia API makes use of the media input devices to produce a ... To enable this functionality, update the constraints object to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found