diff --git a/rlgterm.js b/rlgterm.js index 8630672..a726364 100644 --- a/rlgterm.js +++ b/rlgterm.js @@ -85,6 +85,11 @@ var session = { playing: false }; +/* The interval ID for checking the status of current games. */ +var statInterval = null; +/* How frequently to check. */ +var statDelta = 8000; + function writeData(hexstr) { var codenum; var codes = []; @@ -420,9 +425,17 @@ function formlogin(ev) { return; } -function getcurrent() { - if (session.id) +function getcurrent(clear) { + if (session.id || clear) { + if (statInterval) { + window.clearInterval(statInterval); + statInterval = null; + } return; + } + if (!statInterval) { + statInterval = window.setInterval(getcurrent, statDelta); + } var req = new XMLHttpRequest(); req.onreadystatechange = function () { if (req.readyState != 4 || req.status != 200) @@ -477,6 +490,8 @@ function getcurrent() { }; req.open('GET', '/status', true); req.send(); + if (session.lcred) + getchoices(); return; } @@ -711,7 +726,6 @@ function setmode(mode, ev) { document.getElementById("login").style.display = "none"; document.getElementById("register").style.display = "none"; document.getElementById("current").style.display = "block"; - getchoices(); getcurrent(); } else if (mode == "login") {