mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 03:10:00 +00:00
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.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user