Skip to content

Commit

Permalink
feat: introduce new waitForPeers API (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
weboko authored Oct 11, 2024
1 parent 1b2affe commit 2b0258a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/guides/js-waku/configure-discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ const node = await createLightNode({
You can retrieve the array of peers connected to a node using the `libp2p.getPeers()` function within the `@waku/sdk` package:

```js
import { createLightNode, waitForRemotePeer } from "@waku/sdk";
import { createLightNode } from "@waku/sdk";

const node = await createLightNode({ defaultBootstrap: true });
await waitForRemotePeer(node);
await node.waitForPeers();

// Retrieve array of peers connected to the node
console.log(node.libp2p.getPeers());
Expand Down
10 changes: 4 additions & 6 deletions docs/guides/js-waku/light-send-receive.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,20 @@ const node = await createLightNode({

## Connect to remote peers

Use the `waitForRemotePeer()` function to wait for the node to connect with peers on the Waku Network:
Use the `node.waitForPeers()` function to wait for the node to connect with peers on the Waku Network:

```js
import { waitForRemotePeer } from "@waku/sdk";

// Wait for a successful peer connection
await waitForRemotePeer(node);
await node.waitForPeers();
```

The `protocols` parameter allows you to specify the [protocols](/learn/concepts/protocols) that the remote peers should have enabled:

```js
import { waitForRemotePeer, Protocols } from "@waku/sdk";
import { Protocols } from "@waku/sdk";

// Wait for peer connections with specific protocols
await waitForRemotePeer(node, [Protocols.LightPush, Protocols.Filter]);
await node.waitForPeers([Protocols.LightPush, Protocols.Filter]);
```

## Choose a content topic
Expand Down
6 changes: 3 additions & 3 deletions docs/guides/js-waku/store-retrieve-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ await node.start();

## Connect to store peers

Use the `waitForRemotePeer()` function to wait for the node to connect with Store peers:
Use the `node.waitForPeers()` method to wait for the node to connect with Store peers:

```js
import { waitForRemotePeer, Protocols } from "@waku/sdk";
import { Protocols } from "@waku/sdk";

// Wait for a successful peer connection
await waitForRemotePeer(node, [Protocols.Store]);
await node.waitForPeers([Protocols.Store]);
```

## Choose a content topic
Expand Down

0 comments on commit 2b0258a

Please sign in to comment.