GithubHelp home page GithubHelp logo

Comments (4)

mebjas avatar mebjas commented on May 15, 2024

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);
}

from html5-qrcode.

mebjas avatar mebjas commented on May 15, 2024

@OneDivZero is this still happening?

from html5-qrcode.

mebjas avatar mebjas commented on May 15, 2024

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

from html5-qrcode.

sargearmstrong avatar sargearmstrong commented on May 15, 2024

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); });
}

from html5-qrcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.