Open jvntf opened 5 years ago
@jvntf Hey, thanks for you interest. This repo is still work in progress and used as a proof of concept for this issue: https://github.com/mafintosh/hypercore/issues/198
In my test app I have this packages and overrides in the package.json:
"react-native": {
"net": "@hawkingnetwork/react-native-tcp",
"tls": "@hawkingnetwork/react-native-tcp/tls",
"crypto": "react-native-crypto"
},
"dependencies": {
"@hawkingnetwork/react-native-tcp": "^3.3.2",
"hypercore": "https://github.com/alexindigo/hypercore.git",
"hypercore-crypto": "https://github.com/alexindigo/hypercore-crypto.git#master",
"hypercore-protocol": "https://github.com/alexindigo/hypercore-protocol.git#master",
"react-native-crypto": "^2.1.2",
"react-native-gesture-handler": "^1.0.12",
"react-native-randombytes": "^3.5.1",
"react-native-sodium": "^0.3.2",
Then I have
hyper-test.js
:
import net from 'net';
import hypercore from 'hypercore';
export default function connectHyper(callback) {
const client = net.createConnection(10000);
client.on('error', (error) => callback(error));
const feed = hypercore('./my-test-dataset', '3b72dd08c093544b9763789201802811ea8e944946c9b0af25741dfd050fe5e8', {valueEncoding: 'utf-8'})
feed.on('error', (err) => callback(err))
feed.on('ready', function()
{
console.log('READY:', feed.key.toString('hex'));
// console.log('ARCHIVE:', archive.key.toString('hex'));
// console.log('DISCOVERY:', archive.discoveryKey.toString('hex'));
feed.get(0, (err, data) => callback(null, data));
feed.get(1, (err, data) => callback(null, data));
client.pipe(feed.replicate()).pipe(client)
// client.on('data', function(data) {
// console.log('message was received', data);
// });
});
}
And this is piece I have in App.js
:
import hyperConnect from './hyper-test';
class App extends Component<Props> {
constructor(props){
super(props);
this.state = { netMessages: [] };
}
componentDidMount = () => {
hyperConnect((err, message) => {
const netMessages = this.state.netMessages;
netMessages.push(message);
this.setState({ netMessages });
})
};
}
And it all starts without errors, but I wasn't able to make a successful connection.
And then I got sick and still recovering, so no real progress since then. :)
thanks @alexindigo! I would guess my problem is based on the overrides.
For now I have figured out a work around using nodejs-mobile to handle the hypercore
routines
@jvntf Interesting, I'd be curious to see what you've got, if there is a chance :)
Sure, here is the repo which is a bit chaotic and very WIP at the moment but the interesting stuff is here in App.js and in main.js
App.js
is the React Native app, it runs main.js
as a node-js thread. main.js
handles all of the actual hypercore / hyperdiscovery and can pass info back and forth via rn-bridge
module (basically a bidirectional pipe. A bit clunky, but seems to get the job done. Haven't stress tested or looked into the security of this yet. Let me know if you what you think!
Trying to use
react-native-hypercore
in a react native app, but when I try toimport hypercore from 'hypercore'
(have also triedrequire()
), I get the following error:I have installed and linked
hypercore
, tried installingfs
manually, following the above instructions to clear the caches...but it still won't run. Any idea what I am doing wrong? Using versions: npm: 6.4.1 node: 10.15.3 react-native: 0.59.1 (node is outdated because newer versions of node or not compatible with another module I need) Thanks!