After implementing Detecting idle time in JavaScript elegantly I get "WebSocket is already in CLOSING or CLOSED state" error in the browser console. How to fix this issue? Here is my code:
var inactivityTime = function () {
var t;
window.onload = resetTimer;
document.onmousemove = resetTimer;
document.onkeypress = resetTimer;
function detector() {
alert("You are idle!");
}
function resetTimer() {
console.log("RESET!");
clearTimeout(t);
t = setTimeout(detector, 10000)
// 1000 milisec = 1 sec
}
};
Template.myTemplate.onRendered(function(){
inactivityTime();
});
You are calling clearTimeout(t) when t may not have been initialised - you should check for a value first