Browse Source

pong timeouts

master
Martin Dørum 2 years ago
parent
commit
1c1b0d045a
1 changed files with 17 additions and 1 deletions
  1. 17
    1
      web/console/conn.js

+ 17
- 1
web/console/conn.js View File

@@ -2,6 +2,8 @@ class Conn {
constructor(id) {
this.id = id;
this.conn = null;
this.pongTimeout = null;
this.pongTime = 7500;
this.q = [];

this.onstatechange = () => {}
@@ -9,7 +11,8 @@ class Conn {

this.createConn();

setInterval(() => this.send({ type: "ping" }), 30000);
setInterval(() => this.send({ type: "ping" }), this.pongTime);
this.gotPong();
}

createConn() {
@@ -64,6 +67,7 @@ class Conn {
break;

case "pong":
this.gotPong();
break;

default:
@@ -72,6 +76,18 @@ class Conn {
}
}

gotPong() {
this.ready = true;
this.onstatechange("Ready");
if (this.pongTimeout)
clearTimeout(this.pongTimeout);

this.pongTimeout = setTimeout(() => {
this.ready = false;
this.onstatechange("Pong timeout");
}, this.pongTime / 2);
}

runJavascript(js) {
this.send({ type: "run-js", js });
}

Loading…
Cancel
Save