Meteor WebSocket is already in CLOSING or CLOSED s

2019-09-15 01:50发布

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条回答
仙女界的扛把子
2楼-- · 2019-09-15 02:42

You are calling clearTimeout(t) when t may not have been initialised - you should check for a value first

查看更多
登录 后发表回答