BlinkID / blinkid-react-native

ID scanning for cross-platform apps built with ReactNative.
176 stars 59 forks source link

Timeout after scanning for x amount of seconds #127

Open cjinghong opened 5 years ago

cjinghong commented 5 years ago

Is it possible to implement a timeout? It should be able to dismiss the activity after failing to scan the document within a certain period of time.

dCubelic commented 4 years ago

Hi @cjinghong, sorry for the late answer.

Are you still trying to solve this?

You can set the property milisecondsBeforeTimeout to recognizer collection which will return even the partially read results.

But probably a more general solution for you would be to use some kind of timers inside of react native, which on trigger dismisses the activity. (https://reactnative.dev/docs/timers)

Best regards, Dominik

dragorwyin commented 2 years ago

Hi, I have the same question. MilisecondsBeforeTimeout is not working, by default it's set to 10 seconds, but it isn't timeouted anyway. Moreover, scanWithCamera is not possible to stop because Promise object is unstoppable. Could you give any hint how to stop the scanner from React level? I tried solution given by @dCubelic

I'm using BlinkIDReactNative.MrtdRecognizer

mparadina commented 2 years ago

Hi @dragorwyin

Allow me to jump in.

When you've added MilisecondsBeforeTimeout, is the scanning still 'stuck' in a loop, or is there some other behaviour? Which version of the SDK are you using?

Keep in mind that the time couting starts from the moment when at least one piece of information get extracted from the document (the recognizer changes its state to uncertain or valid), not from the beginning of the scanning session.

I certainly reccomend using the BlinkIdRecognizer instead of the MrtdRecognizer, as the MrtdRecognizer has been depracted and the BlinkIdRecognizer contains all of its functionalities. More information about the recognizer can be found here.

dragorwyin commented 2 years ago

Hi @mparadina. Not sure which SDK you are asking for so I'm sending all of them: minSdkVersion = 23 compileSdkVersion = 31 targetSdkVersion = 31 "@microblink/blinkid-in-browser-sdk": "~5.17.0",

The scanner is showing up "scan the front of your document" and after timeout the scanner doesn't close it's still trying to scan document.

Oh I didn't know that counter is starting when there will be at least one piece of information recognized.

I dropped BlinkIdRecognizer, we used that before but it's reading all things we don't want to read for example barcodes, scanning document, etc. But we just want to use MRZ scanner only. But I will try to replace it with BlinkId and drop additional functionalities somehow.

AngTim commented 2 years ago

Hello @dragorwyin.

Thank you for the information regarding the version of the In-browser SDK. The first thing I would recommend is that you use the latest version of the SDK; 5.19.1.

To add to the previous conversation, the timer for recognition timeout will start only after the first results have been retrieved from the document. We don't have a timeout that will begin immediately with the scanning process, giving users enough time to place the document and providing enough time for low-end machines to detect a document and start the extraction process.

You can check two timers we have implemented since version 5.17.0 for the In-browser SDK here: recognitionTimeout and recognitionPauseTimeout.

You can also configure the BlinkIdRecognizer with the recognition mode filter to enable/disable recognition of specific document groups:

An example can look similar to the snippet:

const BlinkIdRecognizer = await BlinkIDSDK.createBlinkIdRecognizer( sdk );

const settings = await BlinkIdRecognizer.currentSettings();
settings.captureModeFilter = {
    enableMrzId: true,
    enableMrzPassport: true,
    enableMrzVisa: true,
    enablePhotoId: false,
    enableBarcodeId: false,
    enableFullDocumentRecognition: true
}

await BlinkIdRecognizer.updateSettings( settings );

Let me know if this helps and if you have any additional questions.

dragorwyin commented 2 years ago

Hello @AngTim , sorry I didn't answer, had a lot of other things. I can see your answer is about In-browser SDK, but the problem is about Android part.

Sorry, maybe the "in-browser" library I gave mislead you. I'm writing the app in React Native technology and I'm using also: "blinkid-react-native": "~5.17.0" library.

For me, waiting for "extracting any information" in this library until counter starts seems like a bug and the problem is not solved yet so ticket should be reopened.

mparadina commented 2 years ago

Hi @dragorwyin

Allow me to jump in.

Just to double-check, how did you implement the timeout on your end? Is the issue only present on Android, or on iOS as well?

Also to confirm, the timer starts at the point where the SDK starts with the information extraction process. If during the scanning session, you do not present the SDK with a document, then the timer will not trigger and the SDK will not give you any response.

dragorwyin commented 2 years ago

Hi @mparadina I cannot answer about iOS because I'm not using this platform. I'm implementing the timeout and whole Scanner this way:

 try {
      const recognizer = new BlinkIDReactNative.MrtdRecognizer();

      const recognizerCollection = new BlinkIDReactNative.RecognizerCollection([
        recognizer,
      ]);

      recognizerCollection.milisecondsBeforeTimeout = ANDROID_SCANNER_TIMEOUT;

      BlinkIDReactNative.BlinkID.scanWithCamera(
        new BlinkIDReactNative.BlinkIdOverlaySettings(),
        recognizerCollection,
        config.SCANNER_LICENSE_KEY,
      )
        .then((scanningResults) => {
         ...
        });

The problem is that when I'm attaching document which is not recognized or I just use something different than ID or Passport, it's scanning without timeout still until first proper document as you said. But my project requirement is I need to implement timeout when scanner is starting scanning and have no idea how to achieve that.

mparadina commented 2 years ago

Hi @dragorwyin

Thank you for the explanation.

From what I understood from your response above, the milisecondsBeforeTimeout property is working as expected (the timer starts when the SDK picks up at least one piece of information from the document)?

Regarding your requirement, I'm afraid we do not have an out-of-the timeout that starts immediately after the end user enters the SDK. However, I can recommend implementing your own timeout when the SDK is initialized and when it ends to add an action to dismiss the activity.

dragorwyin commented 1 year ago

Hi @mparadina , how I could do the implementation of custom timeout from JS code? Or is Java knowledge needed here? ScanWithCamera is a Promise which is uncancellable actually and I cannot stop the scanning process. Thank you for any hints :)

Regarding to the "milisecondsBeforeTimeout", currently I didn't had an case where one information piece was read and others not. It's always reading all or nothing.

dragorwyin commented 1 year ago

Pinging my question.

mparadina commented 1 year ago

Hi @dragorwyin,

Apologies for the delay. Would you mind sharing the code snippet of how you added the custom timeout with the SDK so that we can check internally which modifications are needed to achieve the mentioned flow?

dragorwyin commented 1 year ago

Hello @mparadina, I didn't add custom timeout for Android part, that's what is my question about from 19 days ago. How I could achieve that if scanWithCamera function is a promise which we aren't able to cancel. I don't have Java knowledge but with JS I cannot find out any solutions to achieve custom closing scanning timeout.

mparadina commented 1 year ago

Hi @dragorwyin

Apologies for keeping you waiting.

As you've mentioned, there are not any 'out-of-the-box' solutions with JS and React-Native, but you can customize our Java wrapper since it is open-source.

I suggest that you fork the repository and make the change in the following file: BlinkID/src/android/src/main/java/com/microblink/reactnative/MicroblinkModule.java

In line 76, you can add a handler which, after 10 seconds, closes the scanning activity:

(new Handler(Looper.getMainLooper())).postDelayed(new Runnable() {
            @Override
            public void run() {
                getCurrentActivity().finishActivity(REQUEST_CODE);
            }
        }, 10000);

Let me know if this helps.

dragorwyin commented 1 year ago

Hello @mparadina , Thank you for the response.

I'm unable to use forked repository in current project (client requirement) so only adding possibility (even configurable in Java) in new release will be satisfying our project needs. If there is any possibility to do it, I would kindly ask about it :)

Thank you and have a nice day!

mparadina commented 1 year ago

Hi @dragorwyin

Before adding the feature to the SDK, the team asked if you could explain in more detail why the feature is required on your end so that we can review it internally?

As mentioned previously, you can still directly modify the React-Native wrapper on your end (as it is open-source) with the following code to achieve the mentioned functionality:

Android:
Path: BlinkID/src/android/src/main/java/com/microblink/reactnative/MicroblinkModule.java

On line 76:

(new Handler(Looper.getMainLooper())).postDelayed(new Runnable() {
            @Override
            public void run() {
                getCurrentActivity().finishActivity(REQUEST_CODE);
            }
        }, 10000);

iOS: Path: _.../nodemodules/blinkid-react-native/src/ios/MicroblinkModule/MicroblinkModule/MBBlinkIDModule.m

Below line 99:

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10 repeats:NO block:^(NSTimer * _Nonnull timer) {
        [rootViewController dismissViewControllerAnimated:YES completion:nil];
}];

This will achieve the functionality that, after 10 seconds of the moment the scanning screen is opened, it will close.

dragorwyin commented 1 year ago

It's working, thank you! Can't wait to release it as feature ;) let me update here :)