Ver código fonte

pong timeouts

master
Martin Dørum 4 anos atrás
pai
commit
1c1b0d045a
1 arquivos alterados com 17 adições e 1 exclusões
  1. 17
    1
      web/console/conn.js

+ 17
- 1
web/console/conn.js Ver arquivo

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

Carregando…
Cancelar
Salvar