this is my first post. greetings to readers.
So Im fairly new to coding, and ive got this code implemented onto my frontend, a succesful scan sends a GET request to my python API to fetch data from database.. but this script scans qr code few times a second (not only that but it submits it too).
So my question is how could I slow it down a bit, lets say a timeout for 2 seconds after a succesful scan?
function onScanSuccess(decodedText, decodedResult) {
// Handle on success condition with the decoded text or result.
console.log(`Scan result: ${decodedText}`, decodedResult);
$('#search').val(decodedText);
$('#frm').submit();
}
var html5QrcodeScanner = new Html5QrcodeScanner(
"reader", { fps: 10, qrbox: 250 });
html5QrcodeScanner.render(onScanSuccess);
});
edit: I havent said I didnt write this and I have no idea how to do timeouts in Typescript or Javascript and not even where.
Im thanking you for your time :)
This is taken directly from the html5QrcodeScanner example. On success, it will update the result, and if there's no new result scanned, it wont update the result
var resultContainer = document.getElementById('qr-reader-results');
var lastResult, countResults = 0;
function onScanSuccess(decodedText, decodedResult) {
if (decodedText !== lastResult) {
++countResults;
lastResult = decodedText;
// Handle on success condition with the decoded message.
console.log(`Scan result ${decodedText}`, decodedResult);
}
}
var html5QrcodeScanner = new Html5QrcodeScanner(
"qr-reader", { fps: 10, qrbox: 250 });
html5QrcodeScanner.render(onScanSuccess);
but this wont stop your device from scanning, it just won't update the result as from my understanding of your question that would be sufficient, but if you want to stop the camera/ scanning process altogether after successful scan, you can go into a lil bit advanced part of the library
import {Html5Qrcode} from "html5-qrcode"
const html5QrCode = new Html5Qrcode("reader");
html5QrCode.stop().then((ignore) => {
// QR Code scanning is stopped.
}).catch((err) => {
// Stop failed, handle it.
});
by doing this also means that you need to implement the whole process from Pro Mode, you can refer here for pro mode