mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
docs: update auto relay example code usage (#1163)
Co-authored-by: aomini daiki <rakesh.shrestha@hazesoft.co>
This commit is contained in:
parent
6a3e37f250
commit
3cfe4bbfac
@ -106,18 +106,15 @@ console.log(`Node started with id ${node.peerId.toB58String()}`)
|
||||
|
||||
const conn = await node.dial(relayAddr)
|
||||
|
||||
console.log(`Connected to the HOP relay ${conn.remotePeer.toString()}`)
|
||||
|
||||
// Wait for connection and relay to be bind for the example purpose
|
||||
await new Promise((resolve) => {
|
||||
node.peerStore.on('change:multiaddrs', ({ peerId }) => {
|
||||
node.peerStore.on('change:multiaddrs', ({ peerId }) => {
|
||||
// Updated self multiaddrs?
|
||||
if (peerId.equals(node.peerId)) {
|
||||
resolve()
|
||||
console.log(`Advertising with a relay address of ${node.multiaddrs[0].toString()}/p2p/${node.peerId.toB58String()}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
console.log(`Connected to the HOP relay ${conn.remotePeer.toString()}`)
|
||||
console.log(`Advertising with a relay address of ${node.multiaddrs[0].toString()}/p2p/${node.peerId.toB58String()}`)
|
||||
```
|
||||
|
||||
As you can see in the code, we need to provide the relay address, `relayAddr`, as a process argument. This node will dial the provided relay address and automatically bind to it.
|
||||
|
Loading…
x
Reference in New Issue
Block a user