attempt reconnect if no messages received for 5 seconds.

This commit is contained in:
Evan
2025-04-02 16:50:58 -07:00
parent 118a826025
commit 77a60d5a00
2 changed files with 40 additions and 8 deletions
+8 -5
View File
@@ -158,8 +158,7 @@ export class Transport {
private onmessage: (msg: ServerMessage) => void;
private pingInterval: number | null = null;
private isLocal: boolean;
public readonly isLocal: boolean;
constructor(
private lobbyConfig: LobbyConfig,
private eventBus: EventBus,
@@ -267,7 +266,7 @@ export class Transport {
onmessage: (message: ServerMessage) => void,
) {
this.startPing();
this.maybeKillSocket();
this.killExistingSocket();
const wsHost = window.location.host;
const wsProtocol = window.location.protocol === "https:" ? "wss:" : "ws:";
const workerPath = this.lobbyConfig.serverConfig.workerPath(
@@ -304,11 +303,15 @@ export class Transport {
);
if (event.code != 1000) {
console.log(`reconnecting`);
this.connect(onconnect, onmessage);
this.reconnect();
}
};
}
public reconnect() {
this.connect(this.onconnect, this.onmessage);
}
private onSendLogEvent(event: SendLogEvent) {
this.sendMsg(
JSON.stringify(
@@ -586,7 +589,7 @@ export class Transport {
}
}
private maybeKillSocket(): void {
private killExistingSocket(): void {
if (this.socket == null) {
return;
}