I am currently working with two desktop PCs, each running a browser tab that is using js-ipfs to instantiate an IPFS node.
//file index.html, served through HTTPS
const node = IpfsCore.create(); //ipfs browser node
Both nodes have peers (approximately 50 peers are returned when calling node.swarm.addrs()
), but they do not list each other as peers.
My goal is to establish a connection between these two nodes so that if I use node.add( ... )
on the first browser tab, I can then use node.cat( ... )
on the second browser tab to retrieve a file from the first one. Alternatively, I would like browser tab 1's pubsub
broadcast to always reach browser tab 2, and for browser tab 1 to be able to read browser tab 2's wantlist
, and vice versa.
How can I connect these two browser tabs as peers?
In a similar example found at https://github.com/ipfs/js-ipfs/blob/master/packages/interface-ipfs-core/src/swarm/connect.js, the following command is used:
ipfsA.swarm.connect( ipfsBId.addresses[0] )
However, in my scenario, both browser tabs have empty arrays for addresses.
console.log( ( await node.id() ).addresses ); //[] empty arrays
I am unsure of how the browser tabs are able to connect to other peers without their own addresses, and I am unsure of how to make them connect to each other.
There is an older question regarding browser peers at IPFS - pubsub connect to peers from browser, but it seems to rely on the deprecated / outdated webrtc-star https://github.com/libp2p/js-libp2p-webrtc-star
When setting up a WebRTC connection, I would typically use fetch()
, XHR
, or a websocket
to communicate with a public-facing server (with a DNS record or IP address) to exchange negotiation information while querying a list of iceServers (also with DNS records/IP addresses).
I do not want to rely on a list of servers that I own or have configured, nor do I want to burden any public example TURN servers. Perhaps js-libp2p uses multicastDNS, but I am unsure if browser tabs can broadcast signals. Is it possible for fetch()
to achieve this with clever URL manipulation?
What steps should I take? How can these two browser-tab IPFS peers discover each other specifically?
I have a feeling that there is a simple solution to this problem, but after days of research and reviewing countless pages of documentation, I have yet to come across a relevant answer. Despite the vast resources available on the internet, I have been unable to find the solution I am seeking.