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.

Hierarchy

  • NDKRelaySet

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

      timeout in milliseconds for each publish operation and connection operation

    Returns Promise<Set<NDKRelay>>

    A set where the event was successfully published to

    Throws

    PublishError if no relay was able to receive the event

    Example

    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 PublishError) {
    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

    Returns NDKRelaySet

    NDKRelaySet

Generated using TypeDoc