Meteor WebSocket已处于CLOSING或CLOSED状态错误

时间:2016-10-26 10:36:05

标签: meteor meteor-blaze

实施Detecting idle time in JavaScript elegantly后,我在浏览器控制台中收到“WebSocket已处于CLOSING或CLOSED状态”错误。如何解决这个问题?这是我的代码:

    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 个答案:

答案 0 :(得分:0)

当t可能尚未初始化时,您正在调用clearTimeout(t) - 您应首先检查值