mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
web: stop polling when the page has had no input for ten minutes
The firmware counts every authenticated request as session activity, and the page polls the status every 2.5 s, so an open tab never let the session expire. Track the last mouse, key, touch or wheel event and treat the page as hidden once ten minutes have passed without one: the pollers keep ticking but send nothing, the session times out in the firmware as it did before, and the next input resumes polling, which meets the 401 and returns to the login page.
This commit is contained in:
1 parent
9f107b6e60
commit
ffde4eaf60
1 file changed
+6
-1
+6
-1
@@ -533,13 +533,18 @@ TABS.forEach(function(tb){
|
||||
});
|
||||
$("burger").addEventListener("click",function(){$("nav").classList.toggle("open")});
|
||||
|
||||
var IDLE_STOP_MS=600000,lastInput=Date.now();
|
||||
["mousemove","mousedown","keydown","touchstart","wheel"].forEach(function(ev){
|
||||
addEventListener(ev,function(){lastInput=Date.now()},{passive:true});
|
||||
});
|
||||
function Poller(fn,ms){this.fn=fn;this.ms=ms;this.on=false;this.t=null}
|
||||
Poller.prototype.start=function(){if(this.on)return;this.on=true;this.tick()};
|
||||
Poller.prototype.stop=function(){this.on=false;clearTimeout(this.t)};
|
||||
Poller.prototype.tick=function(){
|
||||
var self=this;
|
||||
if(!self.on)return;
|
||||
var run=document.hidden?Promise.resolve():Promise.resolve().then(self.fn).catch(function(){});
|
||||
var quiet=document.hidden||Date.now()-lastInput>IDLE_STOP_MS;
|
||||
var run=quiet?Promise.resolve():Promise.resolve().then(self.fn).catch(function(){});
|
||||
run.then(function(){ if(self.on)self.t=setTimeout(function(){self.tick()},self.ms); });
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user