Remove listeners from sockets on disconnect

This commit is contained in:
Jonathan Staab
2023-08-02 11:45:15 -07:00
parent ef18009d33
commit 9dad35ce20
3 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "paravel", "name": "paravel",
"version": "0.2.0", "version": "0.2.1",
"description": "Yet another toolkit for nostr", "description": "Yet another toolkit for nostr",
"repository": { "repository": {
"type": "git", "type": "git",
+1 -1
View File
@@ -30,7 +30,7 @@ export class Executor {
}, },
} }
} }
publish(event, {verb = 'EVENT', onOk, onError}) { publish(event, {verb = 'EVENT', onOk, onError} = {}) {
const okListener = (url, id, ...payload) => id === event.id && onOk(url, id, ...payload) const okListener = (url, id, ...payload) => id === event.id && onOk(url, id, ...payload)
const errorListener = (url, id, ...payload) => id === event.id && onError(url, id, ...payload) const errorListener = (url, id, ...payload) => id === event.id && onError(url, id, ...payload)
+1
View File
@@ -75,6 +75,7 @@ export class Socket extends EventEmitter {
// Avoid "WebSocket was closed before the connection was established" // Avoid "WebSocket was closed before the connection was established"
this.ready.then(() => ws.close(), () => null) this.ready.then(() => ws.close(), () => null)
this.ws.removeAllListeners()
this.ws = undefined this.ws = undefined
} }
} }