hyper-sdk icon indicating copy to clipboard operation
hyper-sdk copied to clipboard

React-Native support

Open RangerMauve opened this issue 6 years ago • 8 comments

Make a wrapper over the SDK using nodejs-mobile-react-native and provide it to React-Native apps.

RangerMauve avatar Jan 20 '20 16:01 RangerMauve

Won't that push the entire node_modules into the app build? I've tried a similar alternative to run a full IPFS node on a React-Native app and in the end the app had about to 500MB. This is not something I'd call ideal...

Would it be possible to just pull a compiled version of the code or something like that into nodejs-mobile-react-native directory somehow?

Edit: typo

fmsouza avatar Apr 30 '20 02:04 fmsouza

I'm not sure actually. It might be possible to browserify the bundle and just include the binaries in the folder. I wonder if there are tools that do this already?

There's also an effort to make it work with regular react-native: https://github.com/cliqz/dat-react-native/ If they can get decent performance out of it then nodejs-mobile wouldn't be needed.

RangerMauve avatar Apr 30 '20 16:04 RangerMauve

Yes, react-native out of the box would be ideal. However, we have a working app that runs hypercore, networking, crypto, leveldb in nodejs-mobile, it's pretty small actually given it's bundling node, the APK is 89MB. https://github.com/digidem/mapeo-mobile

It takes a bit of effort to make sure it works well in the background, but this is mostly app logic not too different from programming in electron

okdistribute avatar Apr 30 '20 16:04 okdistribute

Hello all. Not sure if the following would help, but I'm attempting this at the moment using nodejs-mobile-react-native.

To hopefully answer @fmsouza question and confirm @RangerMauve's suggestion:

I've found moving the node_modules folder outside of the nodejs-project into it's parent nodejs-assets works (as node will still resolve a package one level up).

My webpack.config.js output's to ~/nodejs-assets/nodejs-project/main.js. Folder structure is as follows:

.
+-- nodejs-assets
|   +-- node_modules
|   +-- nodejs-project
|   |   +-- main.js 
|   +-- src
|   |   +-- index.js
|   +-- package.json
|   +-- webpack.config.js

Only issue is nodejs-mobile doesn't currently support WebAssembly on iOS (ChakraCore) so DatSDKs version of sodium won't run.

Making attempts this week irrespective.

LeslieOA avatar Aug 11 '20 11:08 LeslieOA

@martinheidegger and I are currently working on making sure sodium-javascript works in RN.

We're setting up a continuous integration testing suite that'll run it on RN and then we'll be fixing bugs.

RangerMauve avatar Aug 11 '20 18:08 RangerMauve

Actually, @LeslieOA would you be down for chatting more about how we could collaborate on pushing this RN stuff forward? My email is [email protected]

RangerMauve avatar Aug 12 '20 18:08 RangerMauve

Actually, @LeslieOA would you be down for chatting more about how we could collaborate on pushing this RN stuff forward? My email is [email protected]

Emailed 🙂

LeslieOA avatar Aug 12 '20 19:08 LeslieOA

Now that we have hyperspace support in the SDK it might make sense to use nodejs-mobile to spin up a hyperspace instance on the native side and use just the client portion for hyper-sdk in the react-native thread.

RangerMauve avatar Apr 27 '21 19:04 RangerMauve