mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-30 11:07:14 -05:00
client: reconnect immediately if network comes online during backoff
This commit is contained in:
parent
ad165389f0
commit
24e6767cab
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);
|
this.monitored = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
|
||||||
|
|
||||||
if (this.autoReconnect) {
|
if (this.autoReconnect) {
|
||||||
|
window.addEventListener("online", this.handleOnline);
|
||||||
|
|
||||||
if (!navigator.onLine) {
|
if (!navigator.onLine) {
|
||||||
console.info("Waiting for network to go back online");
|
console.info("Waiting for network to go back online");
|
||||||
const handleOnline = () => {
|
|
||||||
window.removeEventListener("online", handleOnline);
|
|
||||||
this.reconnect();
|
|
||||||
};
|
|
||||||
window.addEventListener("online", handleOnline);
|
|
||||||
} else {
|
} else {
|
||||||
let delay = this.reconnectBackoff.next();
|
let delay = this.reconnectBackoff.next();
|
||||||
console.info("Reconnecting to server in " + (delay / 1000) + " seconds");
|
console.info("Reconnecting to server in " + (delay / 1000) + " seconds");
|
||||||
|
@ -226,6 +223,8 @@ export default class Client extends EventTarget {
|
||||||
clearTimeout(this.reconnectTimeoutID);
|
clearTimeout(this.reconnectTimeoutID);
|
||||||
this.reconnectTimeoutID = null;
|
this.reconnectTimeoutID = null;
|
||||||
|
|
||||||
|
window.removeEventListener("online", this.handleOnline);
|
||||||
|
|
||||||
this.setPingInterval(0);
|
this.setPingInterval(0);
|
||||||
|
|
||||||
if (this.ws) {
|
if (this.ws) {
|
||||||
|
@ -245,6 +244,13 @@ export default class Client extends EventTarget {
|
||||||
this.dispatchEvent(new CustomEvent("error", { detail: err }));
|
this.dispatchEvent(new CustomEvent("error", { detail: err }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleOnline() {
|
||||||
|
window.removeEventListener("online", this.handleOnline);
|
||||||
|
if (this.autoReconnect && this.status === Client.Status.DISCONNECTED) {
|
||||||
|
this.reconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleOpen() {
|
handleOpen() {
|
||||||
console.log("Connection opened");
|
console.log("Connection opened");
|
||||||
this.setStatus(Client.Status.REGISTERING);
|
this.setStatus(Client.Status.REGISTERING);
|
||||||
|
|
Loading…
Reference in a new issue