我正在使用此代码在浏览器中使用 IPFS。我想知道如何访问 webRTC 对等方的 IP 地址?甚至知道对等点实际上是 webRTC 还是 http 对等点?
<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
<script>
(async () => {
window.node = await Ipfs.create({
config: {
Addresses: {
Swarm: []
},
Bootstrap: []
}
})
window.node.libp2p.on('peer:discovery', (peer) => console.log('peer:discovery', peer))
window.node.libp2p.on('peer:connect', peerInfo => console.log('peer:connect', peerInfo))
window.node.libp2p.on('peer:disconnect', peerInfo => console.log('peer:disconnect', peerInfo))
window.node.libp2p.peerStore.on('peer', (peerId) => console.log('peer', peerId))
window.node.libp2p.peerStore.on('change:multiaddrs', ({ peerId, multiaddrs}) => console.log('change:multiaddrs', {peerId, multiaddrs}))
window.node.libp2p.peerStore.on('change:protocols', ({ peerId, protocols}) => console.log('change:protocols', {peerId, protocols}))
window.node.libp2p.on('error', (err) => console.log('error', err))
window.node.libp2p.connectionManager.on('peer:connect', (connection) => console.log('peer:connect', connection))
window.node.libp2p.connectionManager.on('peer:disconnect', (connection) => console.log('peer:disconnect', connection))
const data = 'Hello'
const results = await window.node.add(data)
console.log({results})
})()
</script>
node.swarm.peers()
给了我一个同行列表,但它似乎不包括 IP 地址。