Connecting two browser peers through js-ipfs

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.

Answer №1

It appears that js-libp2p may not currently support establishing peer-to-peer connections in browsers. Instead, it seems to enhance existing connections with features like PKI or connect to non-browser libp2p nodes, referred to as "peers".

The main objective of the libp2p project is to achieve universal connectivity, even though connecting nodes in browsers has historically been a challenge.

The website discusses various transport options to address this issue, including connecting to a Websocket server, a QUIC server, or using WebRTC, which relies on a pre-existing "signaling" channel.

However, it seems that the effort to enable in-browser nodes to connect without external software aiding in signaling was ultimately abandoned.


On the other hand, https://github.com/webtorrent/bittorrent-dht is working towards allowing pure-webapp peers to establish connections using a generic DHT bootstrap server, but this functionality is not yet operational in browsers.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to ensure that the table header is printed on every page when printing?

My table has a large number of dynamic rows, and when I try to print or preview it using the window.print() function, only the table header (thead) appears on the first page. How can I make sure that the table header appears on each printed page? <div ...

"Encountering issues while upgrading Polymer project version from 0.5 to 1.0

I am in the process of upgrading my project from polymer .5 to polymer 1.0. After installing the new version of the polymer library, iron element, and paper element, I encountered the following error: polymer-micro.html:63 Uncaught TypeError: prototype ...

What's the process for setting a value in selectize.js using Angular programmatically?

Currently, I am implementing the AngularJS directive to utilize selectize.js from this source: https://github.com/kbanman/selectize-ng In my scenario, I have two dropdowns and my goal is to dynamically populate one of them called selectizeVat based on the ...

Incorrect JavaScript switch case usage

Once again, I find myself with a question regarding JavaScript. This one seems to be an easy fix, but for some reason, I just can't seem to figure out what went wrong: I have a textbox and a button. When the button is clicked, the value should be pas ...

Creating a search-enabled multi-select feature in a Tabulator.js column

Currently, I am working on a project involving Tabulator.js and attempting to incorporate a column with a multi-select feature that includes a search option. My approach has been to utilize the Select2 library, but I have run into some challenges. Here is ...

Retrieving and storing selected checkbox values using both JavaScript and PHP

I have location names and location IDs stored in a database table. I am using a foreach loop to print these values as checkboxes in PHP. When the user clicks on the submit button, it triggers a JavaScript function. I would like to store all the selected ...

Looking to compare values within an ng-repeat loop?

I am trying to compare values within the context of an ng-repeat directive. Specifically, I need to compare the current value with the previous value in the array being iterated over by ng-repeat. For example, if my array contains the values [2,3], how can ...

Troubleshooting React hooks: Child component dispatches not triggering updates in parent component

I've been trying to implement a method of passing down a reducer to child components using useContext. However, I encountered an issue where dispatching from a child component did not trigger a re-render in the parent component. Although the state ap ...

Can a complete form be encapsulated within a single AngularJS directive?

While I have come across several instances of individuals utilizing a blend of HTML and directives to craft an AngularJS form (as seen here), my goal is to develop a self-contained widget. This widget would encompass all the necessary HTML for the form w ...

AngularJS directive and customized markup/function

Here is the code snippet I am currently working with: <body ng-controller="testController"> <div test-directive transform="transform()"> </div> <script type="text/ng-template" id="testDirective.html"> <div& ...

The process of inserting data using NextJS Mysql works seamlessly when executed through phpMyAdmin, however, it encounters issues when

My SQL query works perfectly in phpmyadmin, but I'm encountering an issue when making a request from the API. The API uses the MySQL package which was installed using: npm i mysql This is the SQL code that is causing the problem: BEGIN; INSERT INTO A ...

Having trouble sending data from the controller to the view in Laravel 8

I am struggling to display data retrieved from the database in my view through the controller. Despite trying various solutions found on similar questions, none of them seem to be effective. My main goal is to showcase a list of employees on my admin page. ...

Unexpected behavior observed with Async/Await

I am currently learning how to use Async/Await, which is supposed to wait until the Await function finishes executing before moving on with the code. However, I have encountered an issue where my code stops completely after using Await. Here is the method ...

Modify the `value` of the `<input type=color>` element

Hello there! I have been working on a feature where I need users to select a color and have that choice reflected in the value field. Initially, I assumed this could be achieved easily through Bootstrap's features since my project is based on Bootstr ...

changing pictures with jquery

Struggling with this code snippet: $('#clicked_package').css({"background-image" : "url(img/head_2.png)"}).fadeOut("slow"); $('#clicked_package').css({"background-image" : "url(img/head_2_normal.png)"}).fadeIn("slow"); No matter which ...

What is the best way to pre-fetch data using axios in Vue?

My app requires offline functionality for drivers operating in remote areas with limited internet access. To address this, I aim to pre-download all necessary data using Axios requests when an internet connection is available. This way, the app can retriev ...

How can I show the number of items in my filtered data using AngularJS?

My data array holds objects in JSON format. var users = { 'New':{ {Name:'One'}, {Name:'Two'} }, 'Old':{ {Name:'Three'}, {Name:'Four'} } This piece of code is used to disp ...

"Sending a POST request from the smartphone application client developed using the Meteor

I'm currently working on a simple mobile app with Meteor that aims to send user location data to a geospatial database or server. However, I'm facing some challenges and uncertainties about the feasibility of this task using Meteor. The issue ari ...

Utilizing Inquiries within Arrays

I've been working on a quiz application and I have successfully built the array with questions and answers. However, I'm facing some challenges in getting the next question to display after clicking the submit button. Here is a snippet of the cod ...

unable to establish connection due to port error in node.js

While executing node app.js I encountered the following error message info - socket.io started warn - error raised: Error: listen EACCES This snippet shows all the JavaScript code within the application. After running sudo supervisor app.js T ...