Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions abstract-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,19 @@ export class AbstractRelay {
this.ws.onerror = ev => {
clearTimeout(this.connectionTimeoutHandle)
reject((ev as any).message || 'websocket error')
if (this._connected) {
this._connected = false
this.connectionPromise = undefined
this.onclose?.()
this.closeAllSubscriptions('relay connection errored')
}
this._connected = false
this.connectionPromise = undefined
this.onclose?.()
this.closeAllSubscriptions('relay connection errored')
}

this.ws.onclose = ev => {
clearTimeout(this.connectionTimeoutHandle)
reject((ev as any).message || 'websocket closed')
if (this._connected) {
this._connected = false
this.connectionPromise = undefined
this.onclose?.()
this.closeAllSubscriptions('relay connection closed')
}
this._connected = false
this.connectionPromise = undefined
this.onclose?.()
this.closeAllSubscriptions('relay connection closed')
}

this.ws.onmessage = this._onmessage.bind(this)
Expand Down Expand Up @@ -187,8 +183,8 @@ export class AbstractRelay {
// pingpong closing socket
this.closeAllSubscriptions('pingpong timed out')
this._connected = false
this.ws?.close()
this.onclose?.()
this.ws?.close()
}
}
}
Expand Down Expand Up @@ -378,8 +374,8 @@ export class AbstractRelay {
public close() {
this.closeAllSubscriptions('relay connection closed by us')
this._connected = false
this.ws?.close()
this.onclose?.()
this.ws?.close()
}

// this is the function assigned to this.ws.onmessage
Expand Down