Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

synapsis

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

synapsis - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

.travis.yml

2

index.js
module.exports = require('./src/net-msg.js');
module.exports = require('./src/synapsis.js');
{
"name": "synapsis",
"version": "0.1.0",
"version": "0.2.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "./node_modules/.bin/mocha test/*.mocha.js --exit"
},

@@ -15,4 +15,11 @@ "dependencies": {

},
"author": "",
"license": "ISC"
"devDependencies": {
"mocha": "*"
},
"repository": {
"type": "git",
"url": "git://github.com/Unitech/synapsis.git"
},
"author": "Alexandre Strzelewicz @Unitech",
"license": "MIT"
}

@@ -9,2 +9,4 @@

Instanciate new peer:
```javascript

@@ -22,4 +24,7 @@ var Synapsis = require('synapsis');

});
```
// Router
Now expose actions that can be triggered by other peers:
```javascript
synapse.router('command:restart', () => {

@@ -36,3 +41,22 @@ console.log('Got Restart');

});
```
To send actions to other peers:
```javascript
// Broadcast a message to all nodes (w/o current) and do not wait for response
synapse.broadcast('command:restart');
// Broadcast a message + data to all nodes (w/o current) and do not wait for response
synapse.broadcast('command:restart', { some : 'data' });
// 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);
});
```
Extra:
```javascript
// Events

@@ -43,4 +67,4 @@ synapse.on('peer:connected', function(socket) {

synapse.on('peer:disconnected', function(err) {
console.error(err);
synapse.on('peer:disconnected', function(identity) {
console.error(identity);
});

@@ -53,12 +77,3 @@

synapse.on('ready', function() {
// Broadcast a message to all nodes (w/o current) and do not wait for response
synapse.broadcast('command:restart');
// Broadcast a message + data to all nodes (w/o current) and do not wait for response
synapse.broadcast('command:restart', { some : 'data' });
// 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);
});
// Ready
});

@@ -65,0 +80,0 @@ ```

@@ -17,3 +17,3 @@ 'use strict';

* 1/ Exchange diffie hellman keys
* 2/ TODO: Send password
* 2/ Send password
* 3/ Send Identity

@@ -34,3 +34,3 @@ *

if (this._socket_pool[peer.id] && this._socket_pool[peer.id].identity)
debug('peer %s errored', this._socket_pool[peer.id].identity.public_ip);
debug('peer %s errored', this._socket_pool[peer.id].identity.name);
socket.destroy();

@@ -42,9 +42,8 @@ //this.emit('error', err);

socket.on('close', () => {
if (this._socket_pool[peer.id] && this._socket_pool[peer.id].identity)
debug('peer %s left', this._socket_pool[peer.id].identity.public_ip);
if (this._socket_pool[peer.id] && this._socket_pool[peer.id].identity) {
debug('peer %s left', this._socket_pool[peer.id].identity.name);
this.emit('disconnected', this._socket_pool[peer.id].identity);
}
socket.destroy();
if (this._socket_pool[peer.id] && this._socket_pool[peer.id].identity)
this.emit('disconnected', JSON.parse(JSON.stringify(this._socket_pool[peer.id].identity)));
delete this._socket_pool[peer.id];

@@ -187,11 +186,6 @@ });

SocketPool.prototype.sendToId = function(id) {
var ret = [];
var that = this;
Object.keys(this._socket_pool).forEach(function(key) {
ret.push(that._socket_pool[key]);
});
return ret;
SocketPool.prototype.sendToId = function(id, route, data, cb) {
if (data)
return this._socket_pool[id].send(route, data, cb);
return this._socket_pool[id].send(route, cb);
};

@@ -198,0 +192,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc