Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct return channel to .NET for errors #18

Merged
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions BlazorBarcodeScanner.ZXing.JS/JsInteropClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public static void ReceiveBarcode(string barcodeText)
BarcodeReaderInterop.OnBarcodeReceived(barcodeText);
}

[JSInvokable]
public static void ReceiveError(object error)
{
// What to do with the knowledge that an error happened?
// Looking at current examples this might indicate issues with one of the decoders
// (namely BrowserQRCodeReader appears to throw errors occasionally...)
}

[JSInvokable]
public static void ReceiveNotFound()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ window.BlazorBarcodeScanner = {
console.log("Starting decoding with " + videoConstraints);
await this.codeReader.decodeFromConstraints({ video: videoConstraints }, video, (result, err) => {
if (result) {
console.log(result);
if (this.lastPictureDecodedFormat) {
this.lastPictureDecoded = this.codeReader.captureCanvas.toDataURL(this.lastPictureDecodedFormat);
}
Expand All @@ -106,8 +105,7 @@ window.BlazorBarcodeScanner = {
});
}
if (err && !(err instanceof ZXing.NotFoundException)) {
console.error(err);
DotNet.invokeMethodAsync('BlazorBarcodeScanner.ZXing.JS', 'ReceiveBarcode', err)
DotNet.invokeMethodAsync('BlazorBarcodeScanner.ZXing.JS', 'ReceiveError', err)
.then(message => {
console.log(message);
});
Expand Down