instascan
instascan copied to clipboard
accessing cameras.length
FIRST I am sure this is due to my programming ability not a bug in Instascan.
I want to use javascript to get cameras.length. I see in the demo that this is done but I do not want to use that template system.
I just can't get the cameras.length out of this section of code. I CAN see it in an "alert" placed inside this code but if I try to assign it to a "window" variable it is always undefined. Nothing I can find researching global variables can get the data out of this function.
This is one of the ways I've tried but I still get 999 in the 2nd alert. The "3rd alert" doesn't even come up.
`window.camq = {qty: 999);
Instascan.Camera.getCameras().then(function (cameras) {
alert('1st alert = ' + cameras.length);
window.camq.qty = cameras.length; // <----- MY NEW CODE
if (cameras.length > 0) {
scanner.start(cameras[0]);
} else {
console.error('No cameras found.');
}
}).catch(function (e) {
console.error(e);
});
alert('2nd alert' + window.camq.qty); alert('3rd alert' + cameras.length);
Thanks!