mirror of
https://codeberg.org/emersion/gamja
synced 2025-04-22 09:24:28 +02:00
Unregister PING timer when destroying client
This commit is contained in:
parent
24fe62f1de
commit
7b762b3e8a
@ -548,11 +548,8 @@ export default class App extends Component {
|
|||||||
this.switchToChannel = params.autojoin[0];
|
this.switchToChannel = params.autojoin[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.server && this.config.server.ping > 0) {
|
if (this.config.server && typeof this.config.server.ping === "number") {
|
||||||
// TODO: unregister setInterval on disconnect
|
client.setPingInterval(this.config.server.ping);
|
||||||
setInterval(() => {
|
|
||||||
client.send({ command: "PING", params: ["gamja"] });
|
|
||||||
}, this.config.server.ping * 1000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ export default class Client extends EventTarget {
|
|||||||
batches = new Map();
|
batches = new Map();
|
||||||
autoReconnect = true;
|
autoReconnect = true;
|
||||||
reconnectTimeoutID = null;
|
reconnectTimeoutID = null;
|
||||||
|
pingIntervalID = null;
|
||||||
pendingHistory = Promise.resolve(null);
|
pendingHistory = Promise.resolve(null);
|
||||||
cm = irc.CaseMapping.RFC1459;
|
cm = irc.CaseMapping.RFC1459;
|
||||||
whoisDB = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
|
whoisDB = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
|
||||||
@ -111,6 +112,8 @@ export default class Client extends EventTarget {
|
|||||||
clearTimeout(this.reconnectTimeoutID);
|
clearTimeout(this.reconnectTimeoutID);
|
||||||
this.reconnectTimeoutID = null;
|
this.reconnectTimeoutID = null;
|
||||||
|
|
||||||
|
this.setPingInterval(0);
|
||||||
|
|
||||||
if (this.ws) {
|
if (this.ws) {
|
||||||
this.ws.close(1000);
|
this.ws.close(1000);
|
||||||
}
|
}
|
||||||
@ -444,6 +447,21 @@ export default class Client extends EventTarget {
|
|||||||
return this.cm(nick) == this.cm(this.nick);
|
return this.cm(nick) == this.cm(this.nick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPingInterval(sec) {
|
||||||
|
clearInterval(this.pingIntervalID);
|
||||||
|
this.pingIntervalID = null;
|
||||||
|
|
||||||
|
if (sec <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pingIntervalID = setInterval(() => {
|
||||||
|
if (this.ws) {
|
||||||
|
this.send({ command: "PING", params: ["gamja"] });
|
||||||
|
}
|
||||||
|
}, sec * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
/* Execute a command that expects a response. `done` is called with message
|
/* Execute a command that expects a response. `done` is called with message
|
||||||
* events until it returns a truthy value. */
|
* events until it returns a truthy value. */
|
||||||
roundtrip(msg, done) {
|
roundtrip(msg, done) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user