diff --git a/static/index.html b/static/index.html index d5903e7..cdfecda 100644 --- a/static/index.html +++ b/static/index.html @@ -2613,20 +2613,25 @@ // Create reader with 1D-only hints for fast, accurate scanning codeReader = new ZXing.BrowserMultiFormatReader(_barcodeHints(), _barcodeOptions()); + // Pick the rear-facing camera (environment-facing on phones) + let deviceId = null; + try { + const devices = await codeReader.listVideoInputDevices(); + if (devices && devices.length > 0) { + const rear = devices.find(d => + d.label && /back|rear|environment/i.test(d.label) + ); + deviceId = rear ? rear.deviceId : devices[0].deviceId; + } + } catch (e) { + // Fallback: pass null to let decodeFromVideoDevice pick default + console.warn('listVideoInputDevices failed, using default camera:', e); + } + document.getElementById('cameraPlaceholder').style.display = 'none'; video.style.display = 'block'; scanningActive = true; - // Pick the rear-facing camera (environment-facing on phones) - const devices = await ZXing.BrowserMultiFormatReader.listVideoInputDevices(); - let deviceId = null; - if (devices && devices.length > 0) { - const rear = devices.find(d => - d.label && /back|rear|environment/i.test(d.label) - ); - deviceId = rear ? rear.deviceId : devices[0].deviceId; - } - setScanStatus('Point camera at a barcode', 'success'); // decodeFromVideoDevice handles camera + scanning in one call