client: reconnect immediately if network comes online during backoff

This commit is contained in:
Simon Ser 2024-11-05 13:54:49 +01:00
parent ad165389f0
commit 24e6767cab

View file

@ -201,13 +201,10 @@ export default class Client extends EventTarget {
this.monitored = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
if (this.autoReconnect) {
window.addEventListener("online", this.handleOnline);
if (!navigator.onLine) {
console.info("Waiting for network to go back online");
const handleOnline = () => {
window.removeEventListener("online", handleOnline);
this.reconnect();
};
window.addEventListener("online", handleOnline);
} else {
let delay = this.reconnectBackoff.next();
console.info("Reconnecting to server in " + (delay / 1000) + " seconds");
@ -226,6 +223,8 @@ export default class Client extends EventTarget {
clearTimeout(this.reconnectTimeoutID);
this.reconnectTimeoutID = null;
window.removeEventListener("online", this.handleOnline);
this.setPingInterval(0);
if (this.ws) {
@ -245,6 +244,13 @@ export default class Client extends EventTarget {
this.dispatchEvent(new CustomEvent("error", { detail: err }));
}
handleOnline() {
window.removeEventListener("online", this.handleOnline);
if (this.autoReconnect && this.status === Client.Status.DISCONNECTED) {
this.reconnect();
}
}
handleOpen() {
console.log("Connection opened");
this.setStatus(Client.Status.REGISTERING);