流星WebSocket已经处于CLOSING或CLOSED状态错误 [英] Meteor WebSocket is already in CLOSING or CLOSED state error

查看:489
本文介绍了流星WebSocket已经处于CLOSING或CLOSED状态错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实现在JavaScript中优雅地检测空闲时间之后在浏览器控制台中得到"WebSocket已经处于CLOSING或CLOSED状态"错误.如何解决这个问题?这是我的代码:

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();
});

推荐答案

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

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

这篇关于流星WebSocket已经处于CLOSING或CLOSED状态错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆