@@ 51,6 51,7 @@ const WHOX_FIELDS = {
let lastLabel = 0;
let lastWhoxToken = 0;
+let lastPingSerial = 0;
class IRCError extends Error {
constructor(msg) {
@@ 746,7 747,7 @@ export default class Client extends EventTarget {
this.pingIntervalID = setInterval(() => {
if (this.ws) {
- this.send({ command: "PING", params: ["gamja"] });
+ this.ping();
}
}, sec * 1000);
}
@@ 954,6 955,16 @@ export default class Client extends EventTarget {
return networks;
}
+ async ping() {
+ lastPingSerial++;
+ let token = "gamja-" + lastPingSerial;
+
+ let msg = { command: "PING", params: [token] };
+ await this.roundtrip(msg, (reply) => {
+ return reply.command === "PONG" && reply.params[1] === token;
+ });
+ }
+
monitor(target) {
if (this.monitored.has(target)) {
return;