You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having trouble to receive any errors or results in the callback of "decodeFromVideoDevice".
This is a simplification of my code: const reader = new BrowserMultiFormatReader(); const deviceId = '[valid device id here]' reader.decodeFromVideoDevice(deviceId, 'video', (result, err) => { console.log('test', err); if (!result) return; })
The whole code works, when the camera does not emit any errors and i can successfully scan items.
My issue is with the error-handling, as the console log with "test" does never trigger, when there is an error.
To test this, I triggered errors for "NotAllowedError: Permission denied", "NotAllowedError: Permission dismissed" and "NotReadableError: Device in use", which are all correctly recognized and logged in the console by the library code itself, but are not returned in the error callback.
My understanding is that the errors happen before the actual initialization and are this not returned.
It would be great if someone could assist me in this matter.
Thanks a lot! :)
The text was updated successfully, but these errors were encountered:
Hi Laurenz, the catch and callback actually serve different purposes:
The callback is called for each scan attempt and handles scan-related errors. The catch handles errors during the initial camera setup (e.g., when the camera is already in use)
Here's an example of how to implement both correctly:
const callback = (result, err) => {
if (result) {
console.log('Scan successful:', result.getText());
}
if (err && !(err instanceof NotFoundException)) {
console.error('Scanning error:', err);
}
};
codeReader
.decodeFromVideoDevice(selectedDeviceId, 'video', callback)
.catch((error) => {
console.error('Camera initialization error:', error);
if (error.name === 'NotReadableError') {
// Handle camera being in use
}
});
I'm having trouble to receive any errors or results in the callback of "decodeFromVideoDevice".
This is a simplification of my code:
const reader = new BrowserMultiFormatReader(); const deviceId = '[valid device id here]' reader.decodeFromVideoDevice(deviceId, 'video', (result, err) => { console.log('test', err); if (!result) return; })
The whole code works, when the camera does not emit any errors and i can successfully scan items.
My issue is with the error-handling, as the console log with "test" does never trigger, when there is an error.
To test this, I triggered errors for "NotAllowedError: Permission denied", "NotAllowedError: Permission dismissed" and "NotReadableError: Device in use", which are all correctly recognized and logged in the console by the library code itself, but are not returned in the error callback.
My understanding is that the errors happen before the actual initialization and are this not returned.
It would be great if someone could assist me in this matter.
![Screenshot 2024-10-28 120909](https://private-user-images.githubusercontent.com/88063622/380689322-aa0a372a-965b-4f19-9471-2e7591e32add.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4NDU2NjYsIm5iZiI6MTczODg0NTM2NiwicGF0aCI6Ii84ODA2MzYyMi8zODA2ODkzMjItYWEwYTM3MmEtOTY1Yi00ZjE5LTk0NzEtMmU3NTkxZTMyYWRkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA2VDEyMzYwNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUwMTRmY2YzZTI5MjM1YzQwM2I2MDM0MDQ0MGI0ODBjODY4NWFhNDFjYmRjYzBmNzBkNGQwZWM5NWI3OGFiNzQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.CCC8cBCh1J4WuH4PP9f6H_h-rjElLfUbgbb8hln6kAw)
Thanks a lot! :)
The text was updated successfully, but these errors were encountered: