mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
relay: ensure onclose callback is triggered
This commit is contained in:
@@ -121,23 +121,19 @@ export class AbstractRelay {
|
|||||||
this.ws.onerror = ev => {
|
this.ws.onerror = ev => {
|
||||||
clearTimeout(this.connectionTimeoutHandle)
|
clearTimeout(this.connectionTimeoutHandle)
|
||||||
reject((ev as any).message || 'websocket error')
|
reject((ev as any).message || 'websocket error')
|
||||||
if (this._connected) {
|
this._connected = false
|
||||||
this._connected = false
|
this.connectionPromise = undefined
|
||||||
this.connectionPromise = undefined
|
this.onclose?.()
|
||||||
this.onclose?.()
|
this.closeAllSubscriptions('relay connection errored')
|
||||||
this.closeAllSubscriptions('relay connection errored')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ws.onclose = ev => {
|
this.ws.onclose = ev => {
|
||||||
clearTimeout(this.connectionTimeoutHandle)
|
clearTimeout(this.connectionTimeoutHandle)
|
||||||
reject((ev as any).message || 'websocket closed')
|
reject((ev as any).message || 'websocket closed')
|
||||||
if (this._connected) {
|
this._connected = false
|
||||||
this._connected = false
|
this.connectionPromise = undefined
|
||||||
this.connectionPromise = undefined
|
this.onclose?.()
|
||||||
this.onclose?.()
|
this.closeAllSubscriptions('relay connection closed')
|
||||||
this.closeAllSubscriptions('relay connection closed')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ws.onmessage = this._onmessage.bind(this)
|
this.ws.onmessage = this._onmessage.bind(this)
|
||||||
@@ -187,8 +183,8 @@ export class AbstractRelay {
|
|||||||
// pingpong closing socket
|
// pingpong closing socket
|
||||||
this.closeAllSubscriptions('pingpong timed out')
|
this.closeAllSubscriptions('pingpong timed out')
|
||||||
this._connected = false
|
this._connected = false
|
||||||
this.ws?.close()
|
|
||||||
this.onclose?.()
|
this.onclose?.()
|
||||||
|
this.ws?.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -378,8 +374,8 @@ export class AbstractRelay {
|
|||||||
public close() {
|
public close() {
|
||||||
this.closeAllSubscriptions('relay connection closed by us')
|
this.closeAllSubscriptions('relay connection closed by us')
|
||||||
this._connected = false
|
this._connected = false
|
||||||
this.ws?.close()
|
|
||||||
this.onclose?.()
|
this.onclose?.()
|
||||||
|
this.ws?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is the function assigned to this.ws.onmessage
|
// this is the function assigned to this.ws.onmessage
|
||||||
|
|||||||
Reference in New Issue
Block a user