mirror of
https://github.com/logos-messaging/docs.waku.org.git
synced 2026-01-02 12:53:12 +00:00
feat: introduce new waitForPeers API (#226)
This commit is contained in:
parent
1b2affe15e
commit
2b0258ade2
@ -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());
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user