Class NDKRelaySet

A relay set is a group of relays. This grouping can be short-living, for a single REQ or can be long-lasting, for example for the explicit relay list the user has specified.

Requests to relays should be sent through this interface.

Constructors

Properties

Accessors

Methods

Constructors

Properties

relays: Set<NDKRelay>

Accessors

Methods

  • Publish an event to all relays in this set. Returns the number of relays that have received the event.

    Parameters

    • event: NDKEvent
    • OptionaltimeoutMs: number

      timeout in milliseconds for each publish operation and connection operation

    • requiredRelayCount: number = 1

    Returns Promise<Set<NDKRelay>>

    A set where the event was successfully published to

    NDKPublishError if no relay was able to receive the event

    const event = new NDKEvent(ndk, {kinds: [NDKKind.Message], "#d": ["123"]});
    try {
    const publishedToRelays = await relaySet.publish(event);
    console.log(`published to ${publishedToRelays.size} relays`)
    } catch (error) {
    console.error("error publishing to relays", error);

    if (error instanceof NDKPublishError) {
    for (const [relay, err] of error.errors) {
    console.error(`error publishing to relay ${relay.url}`, err);
    }
    }
    }
  • Creates a relay set from a list of relay URLs.

    If no connection to the relay is found in the pool it will temporarily connect to it.

    Parameters

    • relayUrls: string[]

      list of relay URLs to include in this set

    • ndk: default
    • connect: boolean = true

      whether to connect to the relay immediately if it was already in the pool but not connected

    Returns NDKRelaySet

    NDKRelaySet