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

feat: pauseScanning and resumeScanning #180

Closed
3 of 7 tasks
anusha-kaparapu opened this issue Aug 26, 2024 · 8 comments
Closed
3 of 7 tasks

feat: pauseScanning and resumeScanning #180

anusha-kaparapu opened this issue Aug 26, 2024 · 8 comments

Comments

@anusha-kaparapu
Copy link

Plugin(s)

  • Barcode Scanning
  • Face Detection
  • Face Mesh Detection
  • Selfie Segmentation
  • Translation

Current problem

In our project, we have to validate barcode scans in the background while the user is still scanning them. If the validation is invalid, we have to force the user to restart the scanning process rather than aborting it.

We must halt and continue scanning events in order to achieve this.

Preferred solution

pauseScanning and resumeScanning events is required.

Alternative options

No response

Additional context

ionic - 8
Capacitor - 6
@capacitor-mlkit/barcode-scanning - 6.1.0
FYI @robingenz, @JanMisker, @trancee, @jcesarmobile is there any plan to do for feature requests. let me know if any additional details.

Before submitting

@JanMisker
Copy link
Contributor

In my projects I remove() the listener I get from BarcodeScanner.addListener to force a pause. Basically the scanSingleBarcode from the Usage example.

@anusha-kaparapu
Copy link
Author

Thank you for your response, @JanMisker . However, in our project, we incorporated validations such as "Serial number is not valid" while scanning the barcode. After throwing the error, we immediately restarted the scan. Previously, we utilised the Capacitor/Community barcode scanner plugin, which has resume and pause scanning capabilities.

@robingenz
Copy link
Member

@anusha-kaparapu What exactly are these methods supposed to do? I agree with @JanMisker. You can simply remove the listener and then you will no longer be informed about new barcodes. If you want to continue scanning, then add the listener again. You may have to adapt your code, but the plugin should already provide the functionality you need.

@anusha-kaparapu
Copy link
Author

anusha-kaparapu commented Aug 29, 2024

Thanks for your response @robingenz , As per your suggestion, I did the same implementation once the barcode was scanned. We removed the lister after getting validation, and we initiated listener again for continued scanning. But we are facing some issues while continuing to scan. Please find the attached videos. Some white background is displayed after the lister is removed in between interacting with the listener, again and while continuing to scan, some times the screen gets stuck and stoped the scanning as well.

Please find the below code what we have written.

the below two videos is @capacitor-mlkit/barcode-scanning plugin

issue1.mp4
Issue2.mp4

The below video is @capacitor-community/barcode-scanner (this is our current existing behaviour for using resume and pause scanning methods).

capacitor.community-plugin.mp4

Example:

async startScanner() {
 		document.querySelector('body')?.classList.add(‘barcode-scanner-active');
                const listener = await BarcodeScanner.addListener(
                    'barcodeScanned',
                    async result => {
                    if (result.barcode.displayValue) {
                        if (result.barcode.displayValue) {
                            await listener.remove();
                            document.querySelector('body')?.classList.remove('barcode -scanner-active');
                            BarcodeScanner.stopScan();
                            // this method is API call, sending the barcode display value to API based on response 
								we display the error message and do the continue scan.
                            this.getSerialNumberFromSearch().catch(() => {});
                        }
                    } else {
                        this.errorInfo = String(
                            this.translateService.instant('scanner.Serial-number-is-not-valid')
                        );
                        this.continuosScan();
                    }
                    },
                );
                await BarcodeScanner.startScan();
      };

	continuosScan() {
            setTimeout(() => {
                this.ngZone.run(() => {
                    this.startScanner();
                    this.hideErrorMessage();
                });
            }, 1000);
        }

@robingenz
Copy link
Member

@anusha-kaparapu You should only call BarcodeScanner.stopScan() when you are completely finished. Otherwise, just remove the listener and let the scan run in the background during validation.

@JanMisker
Copy link
Contributor

You are calling BarcodeScanner.startScan() multiple times, which will cause problems like you show in the videos. The continue scanning method should only register the listener and nothing else.

@anusha-kaparapu
Copy link
Author

Thanks a lot @robingenz and @JanMisker i followed your instructions and applied, it is working as expected. :)

@robingenz
Copy link
Member

@anusha-kaparapu Great, thank you for getting back. @JanMisker Thank you for your help. Feel free to continue contributing to this project in the future. I really appreciated your contributions to the Capacitor Community.

In this case i will close this issue.

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

No branches or pull requests

3 participants