feat: introduce new waitForPeers API (#226)

This commit is contained in:
Sasha 2024-10-11 12:05:07 +02:00 committed by GitHub
parent 1b2affe15e
commit 2b0258ade2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 11 deletions

View File

@ -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());

View File

@ -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

View File

@ -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