reconnect
This commit is contained in:
parent
87b75c2ea1
commit
8bd36f29b2
1 changed files with 16 additions and 2 deletions
|
@ -10,6 +10,12 @@ type UserRecord = {
|
|||
|
||||
let turnInt: number = -1;
|
||||
|
||||
async function sleep(ms: number) : Promise<void> {
|
||||
return new Promise((res) => {
|
||||
setTimeout(() => res(), ms);
|
||||
});
|
||||
}
|
||||
|
||||
function waitingTimer(text, ms, dot: boolean = true) {
|
||||
let dots = '';
|
||||
let timer = document.querySelector('.turn-timer') as HTMLDivElement;
|
||||
|
@ -212,17 +218,25 @@ class SocketClient {
|
|||
}
|
||||
}
|
||||
|
||||
private onWsClose() {
|
||||
// backoff + reconnect?
|
||||
private async onWsClose() {
|
||||
this.websocket.removeEventListener("open", this.onWsOpen);
|
||||
this.websocket.removeEventListener("message", this.onWsMessage);
|
||||
this.websocket.removeEventListener("close", this.onWsClose);
|
||||
this.websocket = null;
|
||||
|
||||
// reset state
|
||||
this.resetState();
|
||||
|
||||
// reconnect
|
||||
await sleep(1000);
|
||||
this.connect();
|
||||
}
|
||||
|
||||
private resetState() {
|
||||
this.selfNamed = false;
|
||||
this.name = "";
|
||||
this.userList = [];
|
||||
this.updateUserCount();
|
||||
}
|
||||
|
||||
async SendMessage(messageGenerator: (encoder: Shared.MessageEncoder) => ArrayBuffer) {
|
||||
|
|
Loading…
Reference in a new issue