zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.
https://zxing-js.github.io/library/
Apache License 2.0
2.43k stars 541 forks source link

How to restart the scanner after successful read #352

Open fydelio opened 3 years ago

fydelio commented 3 years ago

How do I restart the Zxing-js 1/2D barcode scanner after a successful scan (best without dropping the video stream)?

I start my ZXing Multiformat Reader like this:

codeReader.decodeFromInputVideoDevice(undefined, 'video').then((result) => { ... I submit the value via AJAX to the backend, check the database and return the record if found } If no record is found, I show a message to the user and would like to restart the scanner. How to restart the scanner for a new scan?

odahcam commented 3 years ago

You can continuously scan with the decodeFromInputVideoDeviceContinuously, so no need to restart. Also, I would higly recommend switching to the new browser layer for better support and reliability: https://github.com/zxing-js/browser/releases/tag/v0.0.1-beta.1

fydelio commented 3 years ago

Ok. I'll be looking forward to trying out the new scanner. Sorry, NooB question, by doing this yarn add @zxing/library would I then be getting the latest beta scanner?

Further: I checked the code of the beta release, the DecodeOnce no longer exists. So how could I temporarily stop the scanning after a positiv barcode read, to do an ajax request, and depending the result, tear down the scanner or do another scan using the latest build beta.1?

odahcam commented 3 years ago

would I then be getting the latest beta scanner?

Yes, but only for this package. For the browser package please use yarn add @zxing/library @zxing/browser.

Further: I checked the code of the beta...?

I think you're looking for decodeOnceFromVideoDevice, the source is a bit changed indeed, hehe.

fydelio commented 3 years ago

Hey Odahcam

Could you give some more background on how the library and the browser repository play together. Until now I only needed the library repository for the scanner to work, which included the browser files too.

So what exactly is the browser repo? An add on? Extension? That is not clear from the readme. Some context would be great.

Thx fydelio

odahcam commented 3 years ago

Sure, the browser layer on the library is hard to maintain and develop and will be deleted. The browser package will then be the only browser layer available. The browser package already uses this library, is tested (while the layer here is not), is partialy documented (which currently is very poor here for the browser) and has a much better API and interaction with interface items.

minusdavid commented 3 years ago

I've been wanting to use the browser package instead of the library package, but I can't get the browser package to work while I can get the library package to work :/.

minusdavid commented 3 years ago

Ok I got decodeFromVideoDevice to work but couldn't get decodeOnceFromVideoDevice to work. I imagine I am just doing something wrong, but it would be great if the documentation could be improved.