问题
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();
});
回答1:
You are calling clearTimeout(t) when t may not have been initialised - you should check for a value first
来源:https://stackoverflow.com/questions/40259972/meteor-websocket-is-already-in-closing-or-closed-state-error