mirror of
https://codeberg.org/emersion/gamja
synced 2025-03-13 07:48:37 +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.disconnect();
|
||||||
this.autoReconnect = autoReconnect;
|
this.autoReconnect = autoReconnect;
|
||||||
|
|
||||||
|
console.log("Connecting to " + this.params.url);
|
||||||
this.setStatus(Client.Status.CONNECTING);
|
this.setStatus(Client.Status.CONNECTING);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -98,12 +99,21 @@ export default class Client extends EventTarget {
|
|||||||
this.isupport = new Map();
|
this.isupport = new Map();
|
||||||
|
|
||||||
if (this.autoReconnect) {
|
if (this.autoReconnect) {
|
||||||
|
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");
|
console.info("Reconnecting to server in " + RECONNECT_DELAY_SEC + " seconds");
|
||||||
clearTimeout(this.reconnectTimeoutID);
|
clearTimeout(this.reconnectTimeoutID);
|
||||||
this.reconnectTimeoutID = setTimeout(() => {
|
this.reconnectTimeoutID = setTimeout(() => {
|
||||||
this.reconnect();
|
this.reconnect();
|
||||||
}, RECONNECT_DELAY_SEC * 1000);
|
}, RECONNECT_DELAY_SEC * 1000);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.ws.addEventListener("error", () => {
|
this.ws.addEventListener("error", () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user