mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-10 17:18:51 +00:00
don't try to send a ["CLOSE"] after the websocket is closed.
addresses https://github.com/nbd-wtf/nostr-tools/pull/387
This commit is contained in:
@@ -99,17 +99,20 @@ export class AbstractRelay {
|
|||||||
this.ws.onerror = ev => {
|
this.ws.onerror = ev => {
|
||||||
reject((ev as any).message)
|
reject((ev as any).message)
|
||||||
if (this._connected) {
|
if (this._connected) {
|
||||||
|
this._connected = false
|
||||||
|
this.connectionPromise = undefined
|
||||||
this.onclose?.()
|
this.onclose?.()
|
||||||
this.closeAllSubscriptions('relay connection errored')
|
this.closeAllSubscriptions('relay connection errored')
|
||||||
this._connected = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ws.onclose = async () => {
|
this.ws.onclose = async () => {
|
||||||
|
if (this._connected) {
|
||||||
|
this._connected = false
|
||||||
this.connectionPromise = undefined
|
this.connectionPromise = undefined
|
||||||
this.onclose?.()
|
this.onclose?.()
|
||||||
this.closeAllSubscriptions('relay connection closed')
|
this.closeAllSubscriptions('relay connection closed')
|
||||||
this._connected = false
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ws.onmessage = this._onmessage.bind(this)
|
this.ws.onmessage = this._onmessage.bind(this)
|
||||||
@@ -338,7 +341,7 @@ export class Subscription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public close(reason: string = 'closed by caller') {
|
public close(reason: string = 'closed by caller') {
|
||||||
if (!this.closed) {
|
if (!this.closed && this.relay.connected) {
|
||||||
// if the connection was closed by the user calling .close() we will send a CLOSE message
|
// if the connection was closed by the user calling .close() we will send a CLOSE message
|
||||||
// otherwise this._open will be already set to false so we will skip this
|
// otherwise this._open will be already set to false so we will skip this
|
||||||
this.relay.send('["CLOSE",' + JSON.stringify(this.id) + ']')
|
this.relay.send('["CLOSE",' + JSON.stringify(this.id) + ']')
|
||||||
|
|||||||
Reference in New Issue
Block a user