Integrate Hyperswarm in React-Native, iOS and Android

Integrate Hyperswarm in React-Native, iOS and Android
Photo by Alina Grubnyak / Unsplash

Firstly, refer to below repos if you get lost

  • Main layer for communication
GitHub - holepunchto/hyperswarm: A distributed networking stack for connecting peers.
A distributed networking stack for connecting peers. - holepunchto/hyperswarm
  • This is bare-expo example that bare runtime is integrated and we can use it
GitHub - holepunchto/bare-expo: Example of embedding Bare in an Expo application using https://github.com/holepunchto/react-native-bare-kit
Example of embedding Bare in an Expo application using https://github.com/holepunchto/react-native-bare-kit - holepunchto/bare-expo
  • This is the main part which is where we will begin from
GitHub - holepunchto/bare-link: Native addon linker for Bare
Native addon linker for Bare. Contribute to holepunchto/bare-link development by creating an account on GitHub.
  • If you would like to use any hyper modules on mobile then above repository bare-link is the one which comes very handy
  • After installing hyperswarm to the project, we need to run a simple command
    bare-pack --platform ios --linked --out app.bundle.mjs app.js
  • So you could use simple code under app.js
const Hyperswarm = require('hyperswarm');

const swarm = new Hyperswarm();

swarm.on('connection', conn => {
  conn.on('data', data => {
    console.log(data.toString());
  });

  conn.write("Hello from bare");
});

const topic = Buffer.alloc(32).fill('hello world')
swarm.join(topic)

console.log('Hello iOS!')
  • Once you run the above command you're done and go to use hyperswarm accordingly.