Browse Source

pong timeouts

master
Martin Dørum 4 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

constructor(id) { constructor(id) {
this.id = id; this.id = id;
this.conn = null; this.conn = null;
this.pongTimeout = null;
this.pongTime = 7500;
this.q = []; this.q = [];


this.onstatechange = () => {} this.onstatechange = () => {}


this.createConn(); this.createConn();


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


createConn() { createConn() {
break; break;


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


default: default:
} }
} }


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) { runJavascript(js) {
this.send({ type: "run-js", js }); this.send({ type: "run-js", js });
} }

Loading…
Cancel
Save