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

Optimize default camera selection #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/components/StreamBarcodeReader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,22 @@ export default {
},

methods: {
start() {
async start() {
// Modern phones often have multipe front/rear cameras.
// Sometimes special purpose cameras like the wide-angle camera are picked
// by default. Those are not optimal for scanning QR codes but standard
// media constraints don't allow us to specify which camera we want exactly.
// However, explicitly picking the first entry in the list of all videoinput
// devices for as the default front camera and the last entry as the default
// rear camera seems to be a workaround.
let selected_device_id = undefined
const devices = await this.codeReader.listVideoInputDevices()
if (devices.length > 2) {
const selectedCamera = devices[devices.length - 1]
selected_device_id = selectedCamera.deviceId
}
this.codeReader.decodeFromVideoDevice(
undefined,
selected_device_id,
this.$refs.scanner,
(result, err) => {
if (result) {
Expand Down