Skip to content

ipfs-shipyard/js-libp2p-react-native

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Running js-libp2p under React Native

There is some setup that needs to be done to modernise the react-native runtime.

  1. Shimming globals

Some standard JS APIs aren't available in React Native, these need to be polyfilled, hopefully not forever.

See ./globals.js for the changes you need to make.

  1. Enable modern JS features
$ npm i -D @babel/plugin-transform-private-methods
// babel.config.js
module.exports = {
  //... other config
  plugins: [
    ['@babel/plugin-transform-private-methods', { loose: true }]
  ]
}
  1. Add support for missing Node.js APIs

Some dependencies use Node.js APIs so these need to be added to the module resolver.

See ./babel-config.js for the changes you need to make.

Running

Prerequisites

Make sure you have completed the React Native - Environment Setup instructions till "Creating a new application" step, before proceeding.

Run in the simulator

Start Expo:

$ npm i
$ npm start

Follow the instructions - press i to start iOS or a for Android.

Run on a device

See the expo docs

$ npx expo run:android --device

For iOS you will need to provision a device certificate as normal.

$ npx expo run:ios --device

Notes

  • @libp2p/webrtc can only run on a device since it needs native code

Debugging

Put this at the top of your app file:

import debug from 'weald'

debug.enable('libp2p:*')

About

A demo app running js-libp2p in a React Native app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •