Documentation
    Preparing search index...

    Interface RelayNode

    interface RelayNode {
        events: IWakuEventEmitter;
        filter: undefined;
        health: HealthStatus;
        libp2p: Libp2p;
        lightPush: undefined;
        peerId: PeerId;
        protocols: string[];
        relay: IRelay;
        store: undefined;
        createDecoder(params: CreateDecoderParams): IDecoder<IDecodedMessage>;
        createEncoder(params: CreateEncoderParams): IEncoder;
        dial(
            peer: PeerId | MultiaddrInput,
            protocols?: Protocols[],
        ): Promise<Stream>;
        getConnectedPeers(): Promise<Peer[]>;
        hangUp(peer: PeerId | MultiaddrInput): Promise<boolean>;
        isConnected(): boolean;
        isStarted(): boolean;
        start(): Promise<void>;
        stop(): Promise<void>;
        waitForPeers(protocols?: Protocols[], timeoutMs?: number): Promise<void>;
    }

    Hierarchy (View Summary)

    Index

    Properties

    Emits events related to the Waku node. Those are:

    • WakuEvent.Connection
    • WakuEvent.Health
    waku.events.addEventListener(WakuEvent.Connection, (event) => {
    console.log(event.detail); // true if connected, false if disconnected
    });
    filter: undefined
    health: HealthStatus

    The health status can be one of three states:

    • Unhealthy: No peer connections
    • MinimallyHealthy: At least 1 peer supporting both Filter and LightPush protocols
    • SufficientlyHealthy: At least 2 peers supporting both Filter and LightPush protocols
    console.log(waku.health); // 'Unhealthy'
    
    libp2p: Libp2p
    lightPush: undefined
    peerId: PeerId

    Returns a unique identifier for a node on the network.

    console.log(waku.peerId); // 12D3KooWNmk9yXHfHJ4rUduRqD1TCTHkNFMPF9WP2dqWpZDL4aUb
    
    protocols: string[]

    Returns a list of supported protocols.

    console.log(waku.protocols); // ['/ipfs/id/1.0.0', '/ipfs/ping/1.0.0', '/vac/waku/filter-push/2.0.0-beta1', '/vac/waku/metadata/1.0.0']
    
    relay: IRelay
    store: undefined

    Methods

    • Creates a decoder for Waku messages on a specific content topic.

      A decoder is used to decode messages from the Waku network format. The decoder automatically handles shard configuration based on the Waku node's network settings.

      Parameters

      Returns IDecoder<IDecodedMessage>

      A decoder instance configured for the specified content topic

      If the shard configuration is incompatible with the node's network settings

      // Create a decoder with default network shard settings
      const decoder = waku.createDecoder({
      contentTopic: "/my-app/1/chat/proto"
      });

      // Create a decoder with custom shard settings
      const customDecoder = waku.createDecoder({
      contentTopic: "/my-app/1/chat/proto",
      shardInfo: {
      clusterId: 1,
      shard: 5
      }
      });
    • Creates an encoder for Waku messages on a specific content topic.

      An encoder is used to encode messages into the Waku network format. The encoder automatically handles shard configuration based on the Waku node's network settings.

      Parameters

      • params: CreateEncoderParams

        Configuration for the encoder including content topic and optionally shard information and ephemeral flag

      Returns IEncoder

      An encoder instance configured for the specified content topic

      If the shard configuration is incompatible with the node's network settings

      // Create a basic encoder with default network shard settings
      const encoder = waku.createEncoder({
      contentTopic: "/my-app/1/chat/proto"
      });

      // Create an ephemeral encoder (messages won't be stored by store nodes)
      const ephemeralEncoder = waku.createEncoder({
      contentTopic: "/my-app/1/notifications/proto",
      ephemeral: true,
      shardInfo: {
      clusterId: 2,
      shardsUnderCluster: 16
      }
      });
    • Dials to the provided peer

      Parameters

      • peer: PeerId | MultiaddrInput

        information to use for dialing

      • Optionalprotocols: Protocols[]

        array of Waku protocols to be used for dialing. If no provided - will be derived from mounted protocols.

      Returns Promise<Stream>

      Promise that will resolve to a Stream to a dialed peer and will reject if the connection fails

      await waku.dial(remotePeerId, [Protocols.LightPush]);

      waku.isConnected() === true;
    • Hang up a connection to a peer

      Parameters

      • peer: PeerId | MultiaddrInput

        information to use for hanging up

      Returns Promise<boolean>

      Promise that will resolve to true if the connection is hung up, false otherwise

    • Starts all services and components related to functionality of Waku node.

      Returns Promise<void>

      Promise that will resolve when started.

      await waku.start();

      waku.isStarted() === true;
    • Stops all recurring processes and services that are needed for functionality of Waku node.

      Returns Promise<void>

      Promise that resolves when stopped.

      await waku.stop();

      waku.isStarted === false;
    • Resolves when Waku successfully gains connection to a remote peers that fits provided requirements. Must be used after attempting to connect to nodes, using IWaku.dial or if was bootstrapped by using IPeerExchange or DnsDiscoveryComponents.

      Parameters

      • Optionalprotocols: Protocols[]

        Protocols that need to be enabled by remote peers

      • OptionaltimeoutMs: number

        Timeout value in milliseconds after which promise rejects

      Returns Promise<void>

      Promise that resolves if all desired protocols are fulfilled by at least one remote peer, rejects if the timeoutMs is reached

      If passing a protocol that is not mounted or Waku node is not started

      try {
      // let's wait for at least one LightPush node and timeout in 1 second
      await waku.waitForPeers([Protocols.LightPush], 1000);
      } catch(e) {
      waku.isConnected() === false;
      console.error("Failed to connect due to", e);
      }

      waku.isConnected() === true;