git ssb

1+

Rômulo Alves / dat-react-native



Tree: 0b835dd3b9f970b3fdb54c75f7deb520f1552357

Files: 0b835dd3b9f970b3fdb54c75f7deb520f1552357 / nodejs-assets / nodejs-project / main.js

992 bytesRaw
1const rnBridge = require('rn-bridge');
2const { join } = require('path');
3
4const { findFreePort } = require('./utils');
5const gateway = require('./gateway');
6const message = require('./message');
7
8// Echo every message received from react-native
9rnBridge.channel.on('message', async msg => {
10 const { type, data } = JSON.parse(msg);
11
12 try {
13
14 // Received app path, start Dat gateway
15 if (type === 'path') {
16
17 // Get a free port
18 const port = await findFreePort();
19
20 // Start the Dat gateway
21 await gateway(port, data);
22
23 console.log(`[dat-gateway] Now listening on port ${port} with path ${data}`);
24
25 // Send message with the server port
26 return rnBridge.channel.send(message.port(port));
27 }
28 } catch (err) {
29
30 console.error(err);
31
32 // Send an error message
33 return rnBridge.channel.send(message.error(err));
34 }
35
36});
37
38// Inform react-native node is initialized
39rnBridge.channel.send(message.ok());

Built with git-ssb-web