New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gracenode

Package Overview
Dependencies
Maintainers
1
Versions
381
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gracenode - npm Package Compare versions

Comparing version 3.9.30 to 3.10.0

3

package.json
{
"name": "gracenode",
"description": "A node.js framework for real-time applications over UDP and TCP protocols with extendable modules for quick and clean evelopment.",
"version": "3.9.30",
"version": "3.10.0",
"author": "Nobuyori Takahashi <voltrue2@yahoo.com>",

@@ -17,2 +17,3 @@ "repository": {

"cluster-mode": "1.3.3",
"mesh-link": "0.7.1",
"cookies": "0.7.2",

@@ -19,0 +20,0 @@ "gracelog": "0.7.5",

@@ -11,3 +11,3 @@ # gracenode 3

Version `4.0.0` or above.
Version `6.0.0` or above.

@@ -14,0 +14,0 @@ ## What gracenode does

'use strict';
const gn = require('../gracenode');
const announce = require('./announce');
const broker = require('./broker');
const meshNodes = require('./meshnodes');
const mlink = require('mesh-link');
const RUDP = 0;
const UDP = 1;
var conf;
module.exports = {
RUDP: broker.RUDP,
UDP: broker.UDP,
RUDP: RUDP,
UDP: UDP,
// internally used methods
config: config,
setup: setup,
// mesh network helper object
nodes: meshNodes,
// public methods for mesh network communication
emit: broker.emit,
emit: emit,
on: on,
// mesh network methods
info: broker.info,
info: mlink.info,
// mesh network node methods
setNodeValue: announce.setValue,
nodeExists: announce.nodeExists,
onAnnounce: announce.onAnnounce,
onNewNode: announce.onNewNode,
getNodes: announce.getNodes,
getAllNodes: announce.getAllNodes
prepareNodes: mlink.prepareNodes,
setNodeType: mlink.setType,
setNodeValue: mlink.setValue,
nodeExists: mlink.nodeExists,
onAnnounce: mlink.onUpdate,
onAnnounced: mlink.onUpdated,
onNewNodes: mlink.onNewNodes,
getType: mlink.getType,
getBackupNodes: mlink.getBackupNodes,
getNodeValue: mlink.getNodeValue,
getNodes: mlink.getNodesByType,
getAllNodes: mlink.getNodeEndPoints
};
function config(conf) {
function config(_conf) {
if (gn.isCluster() && gn.isMaster()) {
return;
}
announce.config(conf);
broker.config(conf);
conf = _conf;
}
function setup(cb) {
if (gn.isCluster() && gn.isMaster()) {
return cb();
}
broker.setup(function () {
announce.setup(cb);
gn.onExit(function _stopPortal(next) {
mlink.stop()
.then(next)
.catch(next);
});
if (!conf.prefix) {
conf.prefix = 'gn';
}
if (conf.type) {
mlink.setType(conf.type);
}
mlink.start(conf)
.then(cb)
.catch(cb);
}
/** @description A mesh network communication event listener
* @param {string} eventName - An event name of
* mesh network communication event
* @param {number} eventId - An event ID
* @param {function} handler - A listener handler

@@ -58,4 +70,29 @@ * @param {function} cb - Indicates as RUDP if given

*/
function on(eventName, handler) {
broker.on(eventName, handler);
function on(eventId, handler) {
mlink.handler(eventId, handler);
}
/** @description Sends a message to one or more mesh nodes
* @param {number} protocol - 0 for RUDP and 1 for UDP
* @param {number} eventId - An event ID that is pre-defined by .on()
* @param {array} nodes - An array of mesh node addresses and portes [ { address, port } ]
* @param {function} cb - A callback, if you want a response back
*/
function emit(protocol, eventId, nodes, data, cb) {
switch (protocol) {
case RUDP:
mlink.send(eventId, nodes, data, cb);
break;
case UDP:
mlink.usend(eventId, nodes, data, cb);
break;
default:
if (typeof cb === 'function') {
cb(new Error('InvalidProtocol ' + protocol));
} else {
throw new Error('InvalidProtocol ' + protocol);
}
break;
}
}

@@ -19,13 +19,13 @@ # Portal

gracenode.config({
portal: {
type: <string>,
address: <mesh network address>,
port: <mesh network port>,
relayLimit: <number>,
announce: {
host: '<host of Redis server>',
port: <port of Redis server>,
interval: <interval of announce in milliseconds>
}
}
portal: {
type: <string>,
address: <mesh network address>,
port: <mesh network port>,
relayLimit: <number>,
announce: {
host: '<host of Redis server>',
port: <port of Redis server>,
interval: <interval of announce in milliseconds>
}
}
});

@@ -66,3 +66,3 @@ ```

Registers a callback function (synchronous) to be invoked on every announce.
Registers a callback function (synchronous) to be invoked on every announce **BEFORE** the update.

@@ -75,3 +75,3 @@ It is useful when you need to update mesh node value on every announce.

gn.portal.onAnnounce(function () {
gn.portal.setNodeValue('onlineUsers', getNumberOfOnlineUsers());
gn.portal.setNodeValue('onlineUsers', getNumberOfOnlineUsers());
});

@@ -82,2 +82,6 @@ ```

### .onAnnounced(callback [Function])
Registers a callback function (synchronous) to be invoked on every announce **AFTER** the update.
### .onNewNode(callback [Function])

@@ -91,10 +95,10 @@

gn.portal.onNewNode(function (node) {
/**
node {
address,
port,
value,
type
}
*/
/**
node {
address,
port,
value,
type
}
*/
});

@@ -133,3 +137,3 @@ ```

### .emit(protocol [Number], name [String], nodeList [Array], data [Object], callback [Function])
### .emit(protocol [Number], emitId [Number], nodeList [Array], data [Object], callback [Function])

@@ -142,5 +146,5 @@ Sends mesh netowrk communication to multiple mesh network nodes.

#### name [String]
#### emitId [Number]
The name that has been defined by `.define(...)`.
A unique emitId of a number that is pre-defined by `.on(...)`.

@@ -159,12 +163,12 @@ #### data [Object]

[
{ address: '127.0.0.1', port: 8000 },
{ address: '127.0.0.1', port: 8001 }
{ address: '127.0.0.1', port: 8002 }
{ address: '127.0.0.1', port: 8003 }
{ address: '127.0.0.1', port: 8000 },
{ address: '127.0.0.1', port: 8001 }
{ address: '127.0.0.1', port: 8002 }
{ address: '127.0.0.1', port: 8003 }
]
```
### .on(name [String], callback [Function])
### .on(emitId [Num], callback [Function])
The listener for `name` pre-defined by `.define(...)`.
Registers a handler function for `emitId`.

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

describe('gracenode.portal', function () {
var one2two;

@@ -80,3 +80,3 @@

one2two = body;
done();
done();
});

@@ -102,3 +102,3 @@ });

assert.equal(body.message, 'OK');
done();
done();
});

@@ -120,7 +120,7 @@ });

assert.equal(JSON.stringify(one2two), JSON.stringify(body));
done();
done();
});
});
});
it('can clean up after the tests', function (done) {

@@ -142,6 +142,6 @@ clean(done);

if (error) {
createdir = true;
createdir = true;
}
next();
});
});
}

@@ -148,0 +148,0 @@ function _createdir(next) {

@@ -39,6 +39,4 @@ 'use strict';

gn.portal.onNewNode(function (node) {
gn.portal.onNewNodes(function (node) {
console.log(node);
prefix = 'deadbeef';

@@ -52,6 +50,4 @@ });

logger = gn.log.create();
gn.portal.on('two2one', function (payload) {
gn.portal.on(100, function (payload) {
console.log(payload);
remember.two2one = payload;

@@ -82,3 +78,3 @@ });

logger.debug('emit event one2two', nodes, data);
gn.portal.emit(gn.portal.RUDP, 'one2two', nodes, data, function (error, resp) {
gn.portal.emit(gn.portal.RUDP, 101, nodes, data, function (error, resp) {
if (error) {

@@ -85,0 +81,0 @@ return res.error(error);

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

logger = gn.log.create();
gn.portal.on('one2two', function (payload, cb) {
gn.portal.on(101, function (payload, cb) {
logger.debug('event one2two handled', payload);

@@ -57,5 +57,5 @@ remember.one2two = payload;

//data.obj.bin = new Buffer(data.obj.bin.data);
gn.portal.emit(gn.portal.UDP, 'two2one', nodes, data);
gn.portal.emit(gn.portal.UDP, 100, nodes, data);
res.json({ message: 'OK' });
});

Sorry, the diff of this file is not supported yet

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