schmich/instascan

Select camera to scan

arnaubosch opened this issue · 1 comments

I have a website where I scan QR CODES using instascan.

I access to the website using my mobiIe phone thas has 4 back cameras (HUAWEI P30 PRO).

I have implmented a for each that selects the first 'back' camera:

if (cameras.length > 0) {
var selectedCam = cameras[0];
$.each(cameras, (i, c) => {
if (c.name.indexOf('back') != -1) {
selectedCam = c;
return false;
}
});
scanner.start(selectedCam);
}

But with that selectedCamera the vision is so fuzzy and I can't scan the QR. If I select by default the 2nd camera of the array by doing scanner.start(cameras[2]); the vision is perfect and I can scan all the QR.

Anyone knows a generic way to pick the correct back camera? I mean my webapp is going to be used by so many users that will have differents mobile phones so different numbers of cameras.