Skip to content

Commit 2180c7a

Browse files
committed
add onRelayConnectionSuccess to pair with onRelayConnectionFailure.
1 parent b4bec20 commit 2180c7a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

abstract-pool.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export type AbstractPoolConstructorOptions = AbstractRelayConstructorOptions & {
2222
automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise<VerifiedEvent>)
2323
// onRelayConnectionFailure is called with the URL of a relay that failed the initial connection
2424
onRelayConnectionFailure?: (url: string) => void
25+
// onRelayConnectionSuccess is called with the URL of a relay that succeeds the initial connection
26+
onRelayConnectionSuccess?: (url: string) => void
2527
// allowConnectingToRelay takes a relay URL and the operation being performed
2628
// return false to skip connecting to that relay
2729
allowConnectingToRelay?: (url: string, operation: ['read', Filter[]] | ['write', Event]) => boolean
@@ -50,6 +52,7 @@ export class AbstractSimplePool {
5052
public automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise<VerifiedEvent>)
5153
public trustedRelayURLs: Set<string> = new Set()
5254
public onRelayConnectionFailure?: (url: string) => void
55+
public onRelayConnectionSuccess?: (url: string) => void
5356
public allowConnectingToRelay?: (url: string, operation: ['read', Filter[]] | ['write', Event]) => boolean
5457
public maxWaitForConnection: number
5558

@@ -62,6 +65,7 @@ export class AbstractSimplePool {
6265
this.enableReconnect = opts.enableReconnect || false
6366
this.automaticallyAuth = opts.automaticallyAuth
6467
this.onRelayConnectionFailure = opts.onRelayConnectionFailure
68+
this.onRelayConnectionSuccess = opts.onRelayConnectionSuccess
6569
this.allowConnectingToRelay = opts.allowConnectingToRelay
6670
this.maxWaitForConnection = opts.maxWaitForConnection || 3000
6771
}
@@ -216,6 +220,8 @@ export class AbstractSimplePool {
216220
return
217221
}
218222

223+
this.onRelayConnectionSuccess?.(url)
224+
219225
let subscription = relay.subscribe(filters, {
220226
...params,
221227
oneose: () => handleEose(i),

0 commit comments

Comments
 (0)