mirror of
https://codeberg.org/emersion/gamja
synced 2025-03-12 23:43:42 +01:00
Don't try to reconnect if the network is down
This commit is contained in:
parent
56c18e3810
commit
02ba4be438
@ -69,6 +69,7 @@ export default class Client extends EventTarget {
|
||||
this.disconnect();
|
||||
this.autoReconnect = autoReconnect;
|
||||
|
||||
console.log("Connecting to " + this.params.url);
|
||||
this.setStatus(Client.Status.CONNECTING);
|
||||
|
||||
try {
|
||||
@ -98,11 +99,20 @@ export default class Client extends EventTarget {
|
||||
this.isupport = new Map();
|
||||
|
||||
if (this.autoReconnect) {
|
||||
console.info("Reconnecting to server in " + RECONNECT_DELAY_SEC + " seconds");
|
||||
clearTimeout(this.reconnectTimeoutID);
|
||||
this.reconnectTimeoutID = setTimeout(() => {
|
||||
this.reconnect();
|
||||
}, RECONNECT_DELAY_SEC * 1000);
|
||||
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 {
|
||||
console.info("Reconnecting to server in " + RECONNECT_DELAY_SEC + " seconds");
|
||||
clearTimeout(this.reconnectTimeoutID);
|
||||
this.reconnectTimeoutID = setTimeout(() => {
|
||||
this.reconnect();
|
||||
}, RECONNECT_DELAY_SEC * 1000);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user