Skip to content
Advertisement

Disable a function for a specific time

I currently have a function that scans a barcode or QR code and returns the result:

    function onScanSuccess(decodedText, decodedResult) {
        console.log(`Code scanned = ${decodedText}`, decodedResult);
    }
    var html5QrcodeScanner = new Html5QrcodeScanner(
        "qr-reader", { fps: 10, qrbox: 250 });
    html5QrcodeScanner.render(onScanSuccess);

It works great but the problem i have is that it scans the code very fast and multiple times.

enter image description here

Is there a way to timeout the function so it only return the scans every second?

Advertisement

Answer

First of all, thanks for all the answers and comments.

In the end it worked with the tweaking of the fps. I changed the fps: 10 to fps: 1. Thanks @nicael for that answer.

var html5QrcodeScanner = new Html5QrcodeScanner(
    "qr-reader", { fps: 1, qrbox: 250 });
html5QrcodeScanner.render(onScanSuccess);

If you searched for an answer to disable a function for a specific time, look at @Alireza Jahandoost answer that one’s perfect for that case.

Advertisement