Comparing version 0.2.0 to 0.3.0
{ | ||
"name": "synapsis", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,4 +7,8 @@ | ||
![http://inkican.com/wp-content/uploads/2016/11/67300035-mesh-wallpapers-1-1024x576.jpg](http://inkican.com/wp-content/uploads/2016/11/67300035-mesh-wallpapers-1-1024x576.jpg) | ||
## Usage | ||
### Instanciate Peer | ||
Instanciate new peer: | ||
@@ -17,13 +21,17 @@ | ||
namespace: 'namespace-name', | ||
password: '123456', | ||
password: 'long-password-16-random-caracters-recommended', | ||
// Identity will be shared to all peers | ||
identity: { | ||
name : 'dashboard1', | ||
hostname : process.env.HOSTNAME | ||
name : require('os').hostname() | ||
} | ||
}); | ||
// Now start the peer | ||
synapse.start(); | ||
``` | ||
Now expose actions that can be triggered by other peers: | ||
### Expose Socket Routes | ||
Now expose socket routes that can be triggered by other peers: | ||
```javascript | ||
@@ -43,2 +51,4 @@ synapse.router('command:restart', () => { | ||
### Send/Broadcast Actions to Peers | ||
To send actions to other peers: | ||
@@ -54,13 +64,20 @@ | ||
// Broadcast a message to all nodes (w/o current) and receive messages from each (RPC like) | ||
synapse.broadcast('command:sync_db', { my : { db : true } }, function(err, response) { | ||
console.log(err, response); | ||
synapse.broadcast('command:sync_db', { my : { db : true } }, function(err, response, identity) { | ||
console.log(`Err= ${err} Response = ${response} from = ${identity.name}`); | ||
}); | ||
``` | ||
Extra: | ||
Or send to a specific peer: | ||
```javascript | ||
// Events | ||
synapse.on('peer:connected', function(socket) { | ||
console.log('New peer detected', socket.identity); | ||
var peer = synapse.getPeers()[0]; | ||
synapse.send(peer.id, 'command:restart'); | ||
``` | ||
### Event Handling | ||
```javascript | ||
synapse.on('peer:connected', function(identity, socket) { | ||
console.log('New peer detected', identity); | ||
}); | ||
@@ -77,8 +94,12 @@ | ||
synapse.on('ready', function() { | ||
// Ready | ||
console.log('Peer Ready'); | ||
}); | ||
``` | ||
## Test | ||
Checkout test/ folder for more examples/ | ||
## License | ||
MIT |
@@ -185,4 +185,9 @@ 'use strict'; | ||
if (data) | ||
return this._socket_pool[id].send(route, data, cb); | ||
return this._socket_pool[id].send(route, cb); | ||
return this._socket_pool[id].send(route, data, (err, data) => { | ||
return cb(err, data, this._socket_pool[id].identity); | ||
}); | ||
return this._socket_pool[id].send(route, (err, data) => { | ||
return cb(err, data, this._socket_pool[id].identity); | ||
}); | ||
}; | ||
@@ -195,4 +200,9 @@ | ||
if (data) | ||
return router.send(route, data, cb); | ||
router.send(route, cb); | ||
return router.send(route, data, function(err, data) { | ||
cb(err, data, router.identity); | ||
}); | ||
router.send(route, function(err, data) { | ||
return cb(err, data, router.identity); | ||
}); | ||
}); | ||
@@ -199,0 +209,0 @@ }; |
@@ -157,2 +157,11 @@ | ||
it('should send lot of data and check that everything is good', function(done) { | ||
var length = 999999; | ||
var buffer = Buffer(length).fill('A'); | ||
p1.broadcast('getInfo', { db : buffer }, function(err, data) { | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22069
12
682
101