Class NDKRelay

The NDKRelay class represents a connection to a relay.

NDKRelay#connect

NDKRelay#ready

NDKRelay#disconnect

NDKRelay#notice

NDKRelay#event

NDKRelay#published when an event is published to the relay

NDKRelay#publish:failed when an event fails to publish to the relay

NDKRelay#eose when the relay has reached the end of stored events

NDKRelay#auth when the relay requires authentication

NDKRelay#authed when the relay has authenticated

NDKRelay#delayed-connect when the relay will wait before reconnecting

Hierarchy

  • EventEmitter<{
        auth: ((challenge: string) => void);
        auth:failed: ((error: Error) => void);
        authed: (() => void);
        connect: (() => void);
        delayed-connect: ((delayInMs: number) => void);
        disconnect: (() => void);
        flapping: ((stats: NDKRelayConnectionStats) => void);
        notice: ((notice: string) => void);
        publish:failed: ((event: NDKEvent, error: Error) => void);
        published: ((event: NDKEvent) => void);
        ready: (() => void);
    }>
    • NDKRelay

Constructors

  • Parameters

    Returns NDKRelay

Properties

authPolicy?: NDKAuthPolicy
close: ((subId: string) => void)
complaining: boolean = false
connectivity: NDKRelayConnectivity
debug: Debugger
lowestValidationRatio?: number

The lowest validation ratio this relay can reach.

req: ((relaySub: NDKRelaySubscription) => void)
scores: Map<NDKUser, number>
targetValidationRatio?: number

Current validation ratio this relay is targeting.

trusted: boolean = false

Whether this relay is trusted.

Trusted relay's events do not get their signature verified.

url: string
validationRatioFn?: ((relay: NDKRelay, validatedCount: number, nonValidatedCount: number) => number)

Accessors

  • get validationRatio(): number
  • The current validation ratio this relay has achieved.

    Returns number

Methods

  • Connects to the relay.

    Parameters

    • OptionaltimeoutMs: number
    • reconnect: boolean = true

    Returns Promise<void>

  • Publishes an event to the relay with an optional timeout.

    If the relay is not connected, the event will be published when the relay connects, unless the timeout is reached before the relay connects.

    Parameters

    • event: NDKEvent

      The event to publish

    • timeoutMs: number = 2500

      The timeout for the publish operation in milliseconds

    Returns Promise<boolean>

    A promise that resolves when the event has been published or rejects if the operation times out

  • Parameters

    • relay: NDKRelay
    • validatedCount: number
    • nonValidatedCount: number

    Returns number