From e67c18be0d690808df228123f7d23c5473a52bae Mon Sep 17 00:00:00 2001 From: Stef Date: Tue, 1 Jul 2025 12:11:13 +0200 Subject: [PATCH] Prefer rear camera for video device selection Updated the camera selection logic to prioritize devices labeled as 'back' or 'rear' when initializing the video input for scanning. Falls back to the first available device if no rear camera is found. --- application/templates/scan.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/application/templates/scan.html b/application/templates/scan.html index 2e24c03..92a7933 100644 --- a/application/templates/scan.html +++ b/application/templates/scan.html @@ -41,7 +41,11 @@ console.log('[DEBUG] Permission given and at least one device present'); const devices = await codeReader.listVideoInputDevices(); console.log('[DEBUG] Cameras found:', devices); - const selectedDeviceId = devices[0]?.deviceId; + const rearCamera = devices.find(device => device.label.toLowerCase().includes('back')) + || devices.find(device => device.label.toLowerCase().includes('rear')) + || devices[0]; // fallback + + const selectedDeviceId = rearCamera?.deviceId; await codeReader.decodeFromVideoDevice(selectedDeviceId, videoElement, async (result, err) => { if (result) { const codeText = result.getText();