Class NDKRelay

The NDKRelay class represents a connection to a relay.

Emits

NDKRelay#connect

Emits

NDKRelay#ready

Emits

NDKRelay#disconnect

Emits

NDKRelay#notice

Emits

NDKRelay#event

Emits

NDKRelay#published when an event is published to the relay

Emits

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

Emits

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

Emits

NDKRelay#auth when the relay requires authentication

Emits

NDKRelay#authed when the relay has authenticated

Emits

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

Hierarchy

  • EventEmitter<{
        auth: ((challenge: string) => 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
complaining: boolean = false
connectivity: NDKRelayConnectivity
debug: Debugger
scores: Map<NDKUser, number>
trusted: boolean = false

Whether this relay is trusted.

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

url: string
validationRatio?: number

Accessors

Methods

  • Connects to the relay.

    Parameters

    • Optional timeoutMs: 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

  • Called when this relay has responded with an event but wasn't the fastest one.

    Parameters

    • timeDiffInMs: number

      The time difference in ms between the fastest and this relay in milliseconds

    Returns void

Generated using TypeDoc