only transform filters with enableReconnect() when we're actually reconnecting.

This commit is contained in:
fiatjaf
2025-12-05 09:20:36 -03:00
parent 21ec5bb2dc
commit de7d459f6f
3 changed files with 15 additions and 10 deletions

View File

@@ -159,12 +159,14 @@ export class AbstractRelay {
} }
clearTimeout(this.connectionTimeoutHandle) clearTimeout(this.connectionTimeoutHandle)
this._connected = true this._connected = true
const isReconnection = this.reconnectAttempts > 0
this.reconnectAttempts = 0 this.reconnectAttempts = 0
// resubscribe to all open subscriptions // resubscribe to all open subscriptions
for (const sub of this.openSubs.values()) { for (const sub of this.openSubs.values()) {
sub.eosed = false sub.eosed = false
if (typeof this.enableReconnect === 'function') { if (isReconnection && typeof this.enableReconnect === 'function') {
sub.filters = this.enableReconnect(sub.filters) sub.filters = this.enableReconnect(sub.filters)
} }
sub.fire() sub.fire()
@@ -206,14 +208,17 @@ export class AbstractRelay {
private async waitForDummyReq() { private async waitForDummyReq() {
return new Promise((resolve, _) => { return new Promise((resolve, _) => {
// make a dummy request with expected empty eose reply // make a dummy request with expected empty eose reply
// ["REQ", "_", {"ids":["aaaa...aaaa"]}] // ["REQ", "_", {"ids":["aaaa...aaaa"], "limit": 0}]
const sub = this.subscribe([{ ids: ['a'.repeat(64)] }], { const sub = this.subscribe(
oneose: () => { [{ ids: ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'], limit: 0 }],
sub.close() {
resolve(true) oneose: () => {
sub.close()
resolve(true)
},
eoseTimeout: this.pingTimeout + 1000,
}, },
eoseTimeout: this.pingTimeout + 1000, )
})
}) })
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nostr/tools", "name": "@nostr/tools",
"version": "2.18.2", "version": "2.19.0",
"exports": { "exports": {
".": "./index.ts", ".": "./index.ts",
"./core": "./core.ts", "./core": "./core.ts",

View File

@@ -1,7 +1,7 @@
{ {
"type": "module", "type": "module",
"name": "nostr-tools", "name": "nostr-tools",
"version": "2.18.2", "version": "2.19.0",
"description": "Tools for making a Nostr client.", "description": "Tools for making a Nostr client.",
"repository": { "repository": {
"type": "git", "type": "git",