From bfc76199bc7389aed27dcc16147e1723167b43d4 Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Sat, 1 Sep 2018 17:44:08 -0700 Subject: [PATCH] prevent second requests when the relay is still active --- public/client.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/public/client.js b/public/client.js index 7a20fe6..658c5f8 100644 --- a/public/client.js +++ b/public/client.js @@ -1,8 +1,9 @@ $(function(){ - // refocus and clear the input box every 20sec + // refocus and clear the input box and relay every 20sec for failsafe setInterval(function(){ $("#rfid").focus(); $("#rfid").val(null); + window.relayActivated = false; }, 20000); $("#rfid").keydown(function(event){ @@ -22,7 +23,7 @@ $(function(){ $("#rfid").val(null); // post value to server loading(true); - if (!window.checkinLoading) { + if (!window.checkinLoading && !window.relayActivated) { // use global var to prevent simultaneous posts window.checkinLoading = true; console.log("Checking in..."); @@ -31,6 +32,7 @@ $(function(){ if (data.hasOwnProperty("success")) { if (data.success) { success(data.name); + window.relayActivated = true; } else { failure(); } @@ -66,6 +68,7 @@ function reset(){ $("#success").addClass("dn"); $("#error").addClass("dn"); $("#errormessage").text("Something went wrong with the card reader."); + loading(false); } function success(name){ @@ -73,7 +76,11 @@ function success(name){ setTimeout(function(){ $("#name").text(name); $("#success").removeClass("dn"); - setTimeout(function(){ reset(); }, 6000); // 6000 to match door.js(const DELAY) + setTimeout(function(){ + reset(); + // this is the only time when the relay is reset, besides the 20-sec reset + window.relayActivated = false; + }, 6000); // 6000 to match door.js(const DELAY) }, 250); }