BlinkID / blinkid-in-browser

BlinkID In-browser SDK for WebAssembly-enabled browsers.
https://microblink.com/blinkid
58 stars 30 forks source link

Question / Feature Request: Is there a way to detect when the processImage() (background task) method has finished executing? #106

Open jamesbarrett95 opened 1 year ago

jamesbarrett95 commented 1 year ago

Problem Statement:

After successfully capturing the the user's documents in our application, we dispose of all the video resources, destroy the component from the DOM, and redirect to a 'confirmation' screen which displays a preview of what Blink ID has captured. We display a retry button at the bottom of that confirmation screen which, once clicked, will navigate back and re-initialize the component which is responsible for creating a new VideoRecognizer.

Our problem is that if the retry button is clicked whilst the processImage() background task is executing, then we receive an error when attempting to initialize a new VideoRecognizer, which causes our application to break.

Question / Feature Request

Is there a way to 'wait' until the async processImage() task has finished executing such that we can control when the user is allowed to hit retry?

Additional Information

Version "@microblink/blinkid-in-browser-sdk": "^5.18.0"

Error when trying to recreate a new VideoRecognizer, immediately after capturing a document: image

ivancuric commented 1 year ago

There is currently no way to see if a frame is still being processed, but it can be added in a future release.

This error triggers if the video is still playing, as it checks for its .paused property, so that's one way you can check.

Another one is to wait for the VideoRecognizer.startRecognition() to resolve as it uses processImage() under the hood.

jamesbarrett95 commented 1 year ago

Thanks for the reply @ivancuric.

Another one is to wait for the VideoRecognizer.startRecognition() to resolve as it uses processImage() under the hood.

Does it? Because once it's resolved, it seems as if there are still some background tasks executed by Blink ID, hence why the question was asked in the first place. See screenshot 1 which illustrates a browser log containing the output of BlinkIdCombinedRecognizer.getResult() followed by some network calls, initiated by Blink ID. See screenshot 2, which illustrates the corresponding Blink ID network call, initiated by processImage.

Screenshot 1: image

Screenshot 2: image

ivancuric commented 1 year ago

It should: https://github.com/BlinkID/blinkid-in-browser/blob/master/src/MicroblinkSDK/VideoRecognizer.ts#L712-L728.

Thanks for the feedback, I'll try to see what's going on.

Is there any chance you could provide a minimal reproduction sample on a repository?