fix: tweak re-connect
This commit is contained in:
parent
d8e0c935b9
commit
1a405f7796
@ -36,7 +36,10 @@ export async function initRelayWorker() {
|
||||
if (!conn) {
|
||||
conn = await tryUseCacheRelay("ws://umbrel:4848");
|
||||
}
|
||||
if (conn) return;
|
||||
if (conn) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
} else if (Relay instanceof ConnectionCacheRelay) {
|
||||
await Relay.connection.connect(true);
|
||||
return;
|
||||
@ -44,6 +47,9 @@ export async function initRelayWorker() {
|
||||
} catch (e) {
|
||||
localStorage.removeItem("cache-relay");
|
||||
console.error(e);
|
||||
if (cacheRelay) {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -45,6 +45,7 @@ export class Connection extends EventEmitter<ConnectionTypeEvents> implements Co
|
||||
#activeRequests = new Set<string>();
|
||||
#connectStarted = false;
|
||||
#syncModule?: ConnectionSyncModule;
|
||||
#wasUp = false;
|
||||
|
||||
id: string;
|
||||
readonly address: string;
|
||||
@ -169,6 +170,7 @@ export class Connection extends EventEmitter<ConnectionTypeEvents> implements Co
|
||||
#onOpen(wasReconnect: boolean) {
|
||||
this.#downCount = 0;
|
||||
this.#connectStarted = false;
|
||||
this.#wasUp = true;
|
||||
this.#log(`Open!`);
|
||||
this.#setupEphemeral();
|
||||
this.emit("connected", wasReconnect);
|
||||
@ -176,12 +178,12 @@ export class Connection extends EventEmitter<ConnectionTypeEvents> implements Co
|
||||
}
|
||||
|
||||
#onClose(e: WebSocket.CloseEvent) {
|
||||
// remote server closed the connection, dont re-connect
|
||||
if (!this.#closing) {
|
||||
// if not explicity closed or closed after, start re-connect timer
|
||||
if (this.#wasUp && !this.#closing) {
|
||||
this.#downCount++;
|
||||
this.#reconnectTimer(e);
|
||||
} else {
|
||||
this.#log(`Closed!`);
|
||||
this.#log(`Closed: connecting=${this.#connectStarted}, closing=${this.#closing}`);
|
||||
this.#downCount = 0;
|
||||
if (this.ReconnectTimer) {
|
||||
clearTimeout(this.ReconnectTimer);
|
||||
@ -206,9 +208,7 @@ export class Connection extends EventEmitter<ConnectionTypeEvents> implements Co
|
||||
this.ReconnectTimer = undefined;
|
||||
try {
|
||||
this.connect();
|
||||
} catch {
|
||||
this.emit("disconnect", -1);
|
||||
}
|
||||
} catch {}
|
||||
}, this.ConnectTimeout);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user