Meteor WebSocket is already in CLOSING or CLOSED state error
Asked Answered
A

1

0

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();
});
Absquatulate answered 26/10, 2016 at 10:36 Comment(0)
T
0

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

Thence answered 26/10, 2016 at 13:20 Comment(6)
I checked it with if(), but it doesn't help: if(t) clearTimeout(t);Absquatulate
OK, I fixed this issue. Just changed set/clearTimeout to Meteor.set/clearTimeout. However, I will accept your answer because it was helpful too.Absquatulate
Hmm, someone cheered too soon :( Error is still there.Absquatulate
One minute it works, then it fails again? What does your code look like nowThence
My Code is the same. I get no error if the alert message appears (first timeOut) and I click OK (alert message). However, if the alert message appears and I wait for the second timeout without clicking OK, I get this error. If I could disable second Timeout so long as I didn't click OK, it will maybe fix this issue. But, I don't know how to do it.Absquatulate
Right, that makes sense. Using alert isn't a great practice, especially for something like this, as it is interrupting the flow. Just change it to a console.log(...) and everything should be sweetThence

© 2022 - 2024 — McMap. All rights reserved.