mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 03:04:59 -05:00
client: reconnect immediately if network comes online during backoff
This commit is contained in:
parent
32012bbea5
commit
414d93ebab
1 changed files with 11 additions and 5 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue