Fix quote, retry errored sockets

This commit is contained in:
Jon Staab
2024-11-18 17:11:24 -08:00
parent 02617d9c24
commit 2de2d24e0b
2 changed files with 13 additions and 1 deletions
+9
View File
@@ -26,6 +26,7 @@ const {
} = SocketStatus
export class Socket {
lastError = 0
status = SocketStatus.New
worker = new Worker<Message>()
ws?: WebSocket
@@ -53,6 +54,13 @@ export class Socket {
this.cxn.emit(ConnectionEvent.Reset)
}
// If we're closed due to an error retry after a delay
if (Date.now() - this.lastError > 15_000) {
this.status = New
this.lastError = 0
this.cxn.emit(ConnectionEvent.Reset)
}
// If the socket is new, connect
if (this.status === New) {
this.#init()
@@ -94,6 +102,7 @@ export class Socket {
this.ws.onerror = () => {
this.status = Error
this.lastError = Date.now()
this.cxn.emit(ConnectionEvent.Error)
}