Meteor WebSocket is already in CLOSING or CLOSED state error

不打扰是莪最后的温柔 提交于 2020-01-07 05:32:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!