From 2180c7a1fe7943bbf6870c6e037b227768179c6b Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 31 Jan 2026 14:19:26 -0300 Subject: [PATCH] add onRelayConnectionSuccess to pair with onRelayConnectionFailure. --- abstract-pool.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/abstract-pool.ts b/abstract-pool.ts index 0e7f2a2..bfd9d4f 100644 --- a/abstract-pool.ts +++ b/abstract-pool.ts @@ -22,6 +22,8 @@ export type AbstractPoolConstructorOptions = AbstractRelayConstructorOptions & { automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise) // onRelayConnectionFailure is called with the URL of a relay that failed the initial connection onRelayConnectionFailure?: (url: string) => void + // onRelayConnectionSuccess is called with the URL of a relay that succeeds the initial connection + onRelayConnectionSuccess?: (url: string) => void // allowConnectingToRelay takes a relay URL and the operation being performed // return false to skip connecting to that relay allowConnectingToRelay?: (url: string, operation: ['read', Filter[]] | ['write', Event]) => boolean @@ -50,6 +52,7 @@ export class AbstractSimplePool { public automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise) public trustedRelayURLs: Set = new Set() public onRelayConnectionFailure?: (url: string) => void + public onRelayConnectionSuccess?: (url: string) => void public allowConnectingToRelay?: (url: string, operation: ['read', Filter[]] | ['write', Event]) => boolean public maxWaitForConnection: number @@ -62,6 +65,7 @@ export class AbstractSimplePool { this.enableReconnect = opts.enableReconnect || false this.automaticallyAuth = opts.automaticallyAuth this.onRelayConnectionFailure = opts.onRelayConnectionFailure + this.onRelayConnectionSuccess = opts.onRelayConnectionSuccess this.allowConnectingToRelay = opts.allowConnectingToRelay this.maxWaitForConnection = opts.maxWaitForConnection || 3000 } @@ -216,6 +220,8 @@ export class AbstractSimplePool { return } + this.onRelayConnectionSuccess?.(url) + let subscription = relay.subscribe(filters, { ...params, oneose: () => handleEose(i),