From be1b336a17cbe09829b4dbc8f068d770fd748302 Mon Sep 17 00:00:00 2001 From: LordGhostX Date: Tue, 14 May 2024 00:15:07 +0100 Subject: [PATCH] update js-waku docs --- docs/guides/js-waku/light-send-receive.md | 37 ++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/guides/js-waku/light-send-receive.md b/docs/guides/js-waku/light-send-receive.md index d81f963..9f25f1b 100644 --- a/docs/guides/js-waku/light-send-receive.md +++ b/docs/guides/js-waku/light-send-receive.md @@ -24,7 +24,18 @@ await node.start(); When the `defaultBootstrap` parameter is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes. ::: -Your node will route messages to the default pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different shared pubsub topic, you can change this using the `ShardInfo` parameter: +By default, your node will route messages to the standard pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different shared pubsub topic, you can configure this using the `ShardInfo` parameter: + +```js +// Create the shard info +const shardInfo = { clusterId: 3, shards: [1, 2] }; + +// Create node with custom shard info +const node = await createLightNode({ + defaultBootstrap: true, + shardInfo: shardInfo, +}); +``` ## Connect to remote peers @@ -70,6 +81,20 @@ const encoder = createEncoder({ }); ``` +The `pubsubTopicShardInfo` parameter allows you to configure a different shared pubsub topic for your `encoder` and `decoder`: + +```js +// Create the shard info +const shardInfo = { clusterId: 3, shard: 1 }; + +// Create encoder and decoder with custom shard info +const encoder = createEncoder({ + contentTopic: contentTopic, + pubsubTopicShardInfo: shardInfo, +}); +const decoder = createDecoder(contentTopic, shardInfo); +``` + :::info In this example, users send and receive messages on a shared content topic. However, real applications may have users broadcasting messages while others listen or only have 1:1 exchanges. Waku supports all these use cases. ::: @@ -134,6 +159,16 @@ const subscription = await node.filter.createSubscription(); await subscription.subscribe([decoder], callback); ``` +The `pubsubTopicShardInfo` parameter allows you to configure a different shared pubsub topic for your `Filter` subscription: + +```js +// Create the shard info +const shardInfo = { clusterId: 3, shard: 1 }; + +// Create Filter subscription with custom shard info +const subscription = await node.filter.createSubscription(shardInfo); +``` + You can use the `subscription.unsubscribe()` function to stop receiving messages from a content topic: ```js