-
Notifications
You must be signed in to change notification settings - Fork 501
Open
Labels
help wantedSeeking public contribution on this issueSeeking public contribution on this issueneed/analysisNeeds further analysis before proceedingNeeds further analysis before proceeding
Description
Problem
The browser WebRTC guide uses @libp2p/pubsub-peer-discovery
to discover peers. While the module correctly emits the peer
event with maddrs of discovered webrtc peers (source), js-libp2p emits a peer:discovery
event, however it's missing the /p2p/PEER_ID
component that is present in the original peer
event.
I've worked around this as follows:
libp2p.addEventListener('peer:discovery', async (evt) => {
console.log(
`Discovered new peer (${evt.detail.id.toString()}). Dialling...`,
evt.detail.multiaddrs.map((ma) => ma.toString()),
)
try {
const maddrs = evt.detail.multiaddrs.map((ma) => ma.encapsulate(`/p2p/${evt.detail.id.toString()}`))
await libp2p.dial(maddrs) // dial the new peer
console.log(`Successfully dialed peer (${evt.detail.id.toString()})`)
} catch (err) {
console.error(`Failed to dial peer (${evt.detail.id.toString()}):`, err)
}
})
The problem is that if you just dial the maddrs in the event the dial will fail for webrtc maddrs.
Metadata
Metadata
Assignees
Labels
help wantedSeeking public contribution on this issueSeeking public contribution on this issueneed/analysisNeeds further analysis before proceedingNeeds further analysis before proceeding