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

Camera does not stop scanning #35

Closed
OneDivZero opened this issue May 3, 2020 · 4 comments
Closed

Camera does not stop scanning #35

OneDivZero opened this issue May 3, 2020 · 4 comments

Comments

@OneDivZero
Copy link

OneDivZero commented May 3, 2020

Describe the bug
A call to stopScanning() does not stop scanning im some cases.
Maybe it's a problem, that I'll do this in a timeout-callback.

Reason: I'am doing a pattern-matching on scanned result ... this happens very fast in success-case. For providing a better UX, I add a small timeout for giving interaction-feedback to current user ... before I'll do other stuff in my final implementation.

To Reproduce
Modify Success-Callback this way:

    if(qrCodeMessage == matchingPattern) {
      resultBox.innerHTML = qrCodeMessage; // my test-div
      setTimeout(function() {
        stopScanning();
      }, timeoutAfterScan);
    }

Expected behavior
Should close the stream in any case when invoking stopScanning()

Screenshots
n.a.

Smartphone:

  • Device: [e.g. iPhone*]
  • OS: [iOS*]
  • Browser [safari*]
  • Version [*]

Additional context
n.a.

@mebjas
Copy link
Owner

mebjas commented May 5, 2020

stopScanning() is a promised based API and may not be instantaneous as it needs to cleanup - on going video stream and scanning.

Would this way help

if(qrCodeMessage == matchingPattern) {
      resultBox.innerHTML = qrCodeMessage; // my test-div
      setTimeout(function() {
        // Some UI transitions indicating stopping
        stopScanning()
           .then(_ => {
                 // UI changes for fully stopped
            })
            .catch(error => {
                // Error UI or fallbacks
            })
      }, timeoutAfterScan);
}

@mebjas
Copy link
Owner

mebjas commented May 23, 2020

@OneDivZero is this still happening?

@mebjas
Copy link
Owner

mebjas commented Jun 13, 2020

Marking closed, @OneDivZero - Please feel free to reopen if this is still happening.

@mebjas mebjas closed this as completed Jun 13, 2020
@sargearmstrong
Copy link

Dears, sorry for reopening. I have similar/related problem that I kindly desire some guidance on, pretty please!

Using html5QrCode 2.0.3, in my qrCodeSuccessCallback.. I am immediately calling html5QrCode.stop() using await and then reactivating it once done with parsing logic.. this works great (visible in code below).

However, I'd like to keep camera off for X seconds (so user can verify parse data before next scan) so I wrapped my call to startScanning() inside setTimeout, but when I do.. I randomly receive this error:

Uncaught (in promise) Cannot clear while scan is ongoing, close it first.

I'm confident the scanner is stopped before calling startScanning (in both working/non-working scenarios).. I just don't understand how SetTimeout introduces the error.

Thank you kindly for the library, and your insight.

function startScanning() {
	html5QrCode.start({facingMode: "environment"}, { fps: 10}, 
	async qrCodeMessage => {
		await stopScanning();
		//parse & display logic here
		//startScanning();  //this works, camera re-activates really fast
		setTimeout(function () {  //but if I use this instead, it randomly errors on next scan.. regardless of interval
			startScanning();
		}, 100); //errors occur at 100ms, 3000ms, 10000ms
	}, errorMessage => {}).catch(err => { console.log(err); });
}

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

No branches or pull requests

3 participants