js-ipfs connect two browser peers

148 Views Asked by At

I have 2 devices (desktop PCs), each running a browser tab that instantiates an IPFS node using js-ipfs.

//file index.html, served over HTTPS
const node = IpfsCore.create(); //ipfs browser node 

Both nodes have peers (calling node.swarm.addrs() returns about 50 peers). They do not list each other as peers.

I want to connect those two nodes to each other, so if I call node.add( ... ) on the first, I can then call node.cat( ... ) on the second, and acquire a file from the first. (Or so that browser 1's pubsub broadcasts always reach browser 2; browser 1 can read browser 2's wantlist etc.)

How do I connect these 2 browser tabs as peers?

The example at https://github.com/ipfs/js-ipfs/blob/master/packages/interface-ipfs-core/src/swarm/connect.js uses this command:

ipfsA.swarm.connect( ipfsBId.addresses[0] )

But in my case, both my browser-tabs have no addresses.

console.log( ( await node.id() ).addresses ); //[] empty array

I don't know how the browser tabs manage connecting to other peers without their own addresses, and I don't know how to make them connect to each other.

There is a 4-year-old question about browser peers here IPFS - pubsub connect to peers from browser, but its fairly unrelated and seems to rely on the the deprecated / out-of-date webrtc-star https://github.com/libp2p/js-libp2p-webrtc-star

I know if I were setting up a WebRTC connection I would use fetch() or XHR or a websocket to a public-facing server (with a DNS record or IP address) to exchange negotiation info while querying a list of iceServers (also with DNS records / IP addresses).

I don't want to rely on a list of servers I own or configure, and I don't want to burden any public example TURN servers or anything. js-libp2p might use multicastDNS? I don't think browser tabs can broadcast signals though (I could be wrong? Maybe fetch() can do that somehow with some sneaky url stuff?)

What do I do? How can these two browser-tab IPFS peers discover each other, specifically?

I suspect this has a very straight-forward answer, but I have been researching for days now and read hundreds of pages, and none of the documentation I have read anywhere is relevant. Wherever the answer is on this vast Internet, I have not been able to find it.

0

There are 0 best solutions below