docs: update auto relay example code usage (#1163)

Co-authored-by: aomini daiki <rakesh.shrestha@hazesoft.co>
This commit is contained in:
Rakesh Shrestha 2022-02-28 22:31:56 +05:45 committed by GitHub
parent 6a3e37f250
commit 3cfe4bbfac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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