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

View File

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

View File

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