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

Made it threadsafe #61

Merged
merged 1 commit into from
Nov 18, 2023
Merged

Conversation

KeesAlderliesten
Copy link
Contributor

Simultaneous scanning on multiple devices triggers the OnBarcodeReceived on all devices that have the scanner open. That happens because the class with the JSInvokable attribute is static. The comment 'Unfortunately JS is unable to invoke public methods of internal classes' suggests that it is not possible to call methods in a class instance, but Microsoft docs shows that is is possible: https://learn.microsoft.com/en-gb/aspnet/core/blazor/javascript-interoperability/call-dotnet-from-javascript?view=aspnetcore-6.0#class-instance-examples
So, I removed the class JsInteropClass, made all the static methods and variables non-static, added a helper class to BlazorBarcodeScanner.js and passed the reference to the instance of BarcodeReaderInterop to that helper (in BarcodeReader.razor.cs).
Now you can scan on multiple devices without triggering all the readers at the same time

…, added helperclass to be able to reference the BarcodeReaderInterop instance. This makes it thread safe
@sabitertan
Copy link
Owner

@KeesAlderliesten Thanks for PR, this library designed to work on web assembly only but then we introduced server-side support, I didn't really use it on server-side applications, PR looks good, just verifying now.

@sabitertan sabitertan merged commit 68a54ba into sabitertan:master Nov 18, 2023
@sabitertan
Copy link
Owner

Closes #59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants