Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/html5-qrcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,7 @@ export class Html5Qrcode {
return Promise.resolve(false);
}

// Try fast decoding first for performance
return this.qrcode.decodeAsync(this.canvasElement!)
.then((result) => {
qrCodeSuccessCallback(
Expand All @@ -1151,12 +1152,25 @@ export class Html5Qrcode {
result));
this.possiblyUpdateShaders(/* qrMatch= */ true);
return true;
}).catch((error) => {
this.possiblyUpdateShaders(/* qrMatch= */ false);
let errorMessage = Html5QrcodeStrings.codeParseError(error);
qrCodeErrorCallback(
errorMessage, Html5QrcodeErrorFactory.createFrom(errorMessage));
return false;
}).catch((_error) => {
// Fast decoding failed, try robust decoding as fallback
// This helps with challenging conditions like mobile photography
return this.qrcode.decodeRobustlyAsync(this.canvasElement!)
.then((result) => {
qrCodeSuccessCallback(
result.text,
Html5QrcodeResultFactory.createFromQrcodeResult(
result));
this.possiblyUpdateShaders(/* qrMatch= */ true);
return true;
}).catch((robustError) => {
// Both fast and robust decoding failed
this.possiblyUpdateShaders(/* qrMatch= */ false);
let errorMessage = Html5QrcodeStrings.codeParseError(robustError);
qrCodeErrorCallback(
errorMessage, Html5QrcodeErrorFactory.createFrom(errorMessage));
return false;
});
});
}

Expand Down