Implements

Constructors

Properties

activeSubscriptions: Map<string, Subscription> = ...
connectionManager: waku.ConnectionManager
libp2p: Libp2p
lightPush?: ILightPush
peerManager: PeerManager

Methods

  • Parameters

    • pubsubTopic: string
    • subscription: Subscription

    Returns Subscription

  • Opens a subscription with the Filter protocol using the provided decoders and callback. This method combines the functionality of creating a subscription and subscribing to it.

    Type Parameters

    Parameters

    • decoders: IDecoder<T> | IDecoder<T>[]

      A single decoder or an array of decoders to use for decoding messages.

    • callback: Callback<T>

      The callback function to be invoked with decoded messages.

    Returns Promise<SubscribeResult>

    A promise that resolves to an object containing:

    • subscription: The created subscription object if successful, or null if failed.
    • error: A ProtocolError if the subscription creation failed, or null if successful.
    • results: An object containing arrays of failures and successes from the subscription process. Only present if the subscription was created successfully.

    Throws

    If there's an unexpected error during the subscription process.

    Remarks

    This method attempts to create a subscription using the pubsub topic derived from the provided decoders, then tries to subscribe using the created subscription. The return value should be interpreted as follows:

    • If subscription is null and error is non-null, a critical error occurred and the subscription failed completely.
    • If subscription is non-null and error is null, the subscription was created successfully. In this case, check the results field for detailed information about successes and failures during the subscription process.
    • Even if the subscription was created successfully, there might be some failures in the results.

    Example

    const {subscription, error, results} = await waku.filter.subscribe(decoders, callback);
    if (!subscription || error) {
    console.error("Failed to create subscription:", error);
    }
    console.log("Subscription created successfully");
    if (results.failures.length > 0) {
    console.warn("Some errors occurred during subscription:", results.failures);
    }
    console.log("Successful subscriptions:", results.successes);