fingerprint-container-node-sdk
Advanced tools
Comparing version 0.1.4 to 0.1.5
require('./encoder'); | ||
require('./decoder'); |
@@ -0,0 +0,0 @@ var Encoder = require('../encoder'); |
@@ -0,0 +0,0 @@ var Encoder = require('../encoder'); |
@@ -0,0 +0,0 @@ var util = require('util'); |
@@ -0,0 +0,0 @@ var util = require('util'); |
@@ -0,0 +0,0 @@ var Buffer = require('buffer').Buffer; |
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,0 +0,0 @@ module.exports = { |
{ | ||
"name": "fingerprint-container-node-sdk", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "fingerprint container's sdk", | ||
@@ -20,2 +20,3 @@ "main": "fpc.js", | ||
"dependencies": { | ||
"bignumber.js": "^3.0.1", | ||
"buffer-crc32": "^0.2.13", | ||
@@ -22,0 +23,0 @@ "getmac": "^1.2.1", |
@@ -0,0 +0,0 @@ FPC NODE SDK |
@@ -0,0 +0,0 @@ var FLAG = require('./flag'); |
@@ -0,0 +0,0 @@ var util = require('util'); |
@@ -8,2 +8,3 @@ var util = require('util'); | ||
var _ = require('underscore'); | ||
var BigNumber = require('bignumber.js'); | ||
@@ -24,3 +25,3 @@ var Encoder = require('./encoder'); | ||
this.name = name; | ||
this.rand = +new Date() % 65536; | ||
this.rand = Math.ceil(Math.random() * 65536); | ||
this.closed = false; | ||
@@ -54,11 +55,11 @@ this.uniqid = 0; | ||
Service.prototype.register = function () { | ||
Service.prototype.register = function() { | ||
var _me = this; | ||
var body = {}; | ||
thenjs(function (cont) { | ||
getmac.getMac(function (error, macAddress) { | ||
thenjs(function(cont) { | ||
getmac.getMac(function(error, macAddress) { | ||
cont(error, macAddress); | ||
}); | ||
}).then(function (cont, macAddress) { | ||
}).then(function(cont, macAddress) { | ||
var macInts = macAddress.split(/:|\-/); | ||
@@ -70,5 +71,5 @@ if (macInts.length < 6) { | ||
var pid = process.pid + _me.rand; | ||
body.tag = Number('0x' + macInts.join('') + (pid % 65536).toString(16)); | ||
body.strtag = new BigNumber('0x' + macInts.join('') + (pid % 65536).toString(16)).toString(10); | ||
body.name = _me.name || 'service_' + body.tag; | ||
body.accepts = _.map(_me.accepts, function (val, key) { | ||
body.accepts = _.map(_me.accepts, function(val, key) { | ||
return { | ||
@@ -81,6 +82,6 @@ service: key, | ||
cont(); | ||
}).then(function () { | ||
}).then(function() { | ||
var msg = _me.encoder.encode(body, _me._genMsg(CONTAINNER_COMM_REGISTER)); | ||
_me.client.write(msg); | ||
}).fail(function (cont, error) { | ||
}).fail(function(cont, error) { | ||
// TODO log error | ||
@@ -91,3 +92,3 @@ console.log(error); | ||
Service.prototype.rpcRequest = function (body, msg) { | ||
Service.prototype.rpcRequest = function(body, msg) { | ||
msg = this.encoder.encode(body, msg); | ||
@@ -97,4 +98,6 @@ this.client.write(msg); | ||
Service.prototype.eventRequest = function (serviceName, body) { | ||
var msg = this._genMsg(serviceName, {flag: FLAG.EVENT}); | ||
Service.prototype.eventRequest = function(serviceName, body) { | ||
var msg = this._genMsg(serviceName, { | ||
flag: FLAG.EVENT | ||
}); | ||
msg = this.encoder.encode(body, msg); | ||
@@ -104,3 +107,3 @@ this.client.write(msg); | ||
Service.prototype.close = function () { | ||
Service.prototype.close = function() { | ||
if (!this.closed) { | ||
@@ -112,3 +115,3 @@ this.closed = true; | ||
Service.prototype.destroy = function () { | ||
Service.prototype.destroy = function() { | ||
this.close(); | ||
@@ -121,19 +124,19 @@ this.decoder.removeAllListeners('message'); | ||
Service.prototype._onConnectHandler = function () { | ||
Service.prototype._onConnectHandler = function() { | ||
this.emit('connect'); | ||
}; | ||
Service.prototype._onCloseHandler = function () { | ||
Service.prototype._onCloseHandler = function() { | ||
this.emit('close'); | ||
}; | ||
Service.prototype._onDataHandler = function (buffer) { | ||
Service.prototype._onDataHandler = function(buffer) { | ||
this.decoder.decode(buffer); | ||
}; | ||
Service.prototype._onErrorHandler = function (error) { | ||
Service.prototype._onErrorHandler = function(error) { | ||
this.emit('error', error); | ||
}; | ||
Service.prototype._onMessage = function (msg) { | ||
Service.prototype._onMessage = function(msg) { | ||
var serviceName = msg.service; | ||
@@ -154,3 +157,3 @@ var body = msg.body; | ||
Service.prototype._genMsg = function (serviceName, opt) { | ||
Service.prototype._genMsg = function(serviceName, opt) { | ||
return _.extend({ | ||
@@ -164,3 +167,2 @@ service: crc32.unsigned(serviceName), | ||
module.exports = Service; | ||
module.exports = Service; |
@@ -6,6 +6,6 @@ var assert = require('assert'); | ||
var SERVICE_HOST = '172.16.90.42'; | ||
var SERVICE_HOST = '172.16.50.46'; | ||
var SERVICE_PORT = 9900; | ||
describe('Client', function () { | ||
describe('Client', function() { | ||
var index = 0; | ||
@@ -15,9 +15,9 @@ var serviceName = ''; | ||
beforeEach(function () { | ||
beforeEach(function() { | ||
serviceName = 'unit_test_' + (index++); | ||
}); | ||
it('connect', function (done) { | ||
it('connect', function(done) { | ||
var client = new Client(SERVICE_HOST, SERVICE_PORT); | ||
client.on('connect', function () { | ||
client.on('connect', function() { | ||
done(); | ||
@@ -27,8 +27,8 @@ }); | ||
it('register', function (done) { | ||
it('register', function(done) { | ||
var client = new Client(SERVICE_HOST, SERVICE_PORT); | ||
client.on('connect', function () { | ||
client.on('connect', function() { | ||
client.register(); | ||
}); | ||
client.on('register', function () { | ||
client.on('register', function() { | ||
done(); | ||
@@ -38,5 +38,5 @@ }); | ||
it('eventRequest', function (done) { | ||
it('eventRequest', function(done) { | ||
var server = new Server(SERVICE_HOST, SERVICE_PORT); | ||
server.addHandler(serviceName, function (res) { | ||
server.addHandler(serviceName, function(res) { | ||
var body = res.msg.body; | ||
@@ -46,15 +46,15 @@ if (body.name == serviceName) { | ||
} | ||
}); | ||
}, true); | ||
server.on('connect', function () { | ||
server.on('connect', function() { | ||
server.register(); | ||
}); | ||
server.on('register', function () { | ||
server.on('register', function() { | ||
var client = new Client(SERVICE_HOST, SERVICE_PORT); | ||
client.on('connect', function () { | ||
client.on('connect', function() { | ||
client.register(); | ||
}); | ||
client.on('register', function () { | ||
client.on('register', function() { | ||
client.eventRequest(serviceName, { | ||
@@ -66,64 +66,64 @@ name: serviceName | ||
}); | ||
// | ||
// it('rpcRequest', function (done) { | ||
// var server = new Server(SERVICE_HOST, SERVICE_PORT); | ||
// server.addHandler(serviceName, function (res) { | ||
// res.send({ | ||
// name: 'unit_test_1' | ||
// }); | ||
// }); | ||
// | ||
// server.on('connect', function () { | ||
// server.register(); | ||
// }); | ||
// | ||
// server.on('register', function () { | ||
// var client = new Client(SERVICE_HOST, SERVICE_PORT); | ||
// client.on('connect', function () { | ||
// client.register(); | ||
// }); | ||
// | ||
// client.on('register', function () { | ||
// client.rpcRequest(serviceName, { | ||
// name: serviceName | ||
// }, function (body) { | ||
// if (body.name == "unit_test_1") { | ||
// done(); | ||
// } | ||
// }); | ||
// }); | ||
// }); | ||
// }); | ||
// | ||
// it('rpcRequest timeout', function (done) { | ||
// var server = new Server(SERVICE_HOST, SERVICE_PORT); | ||
// server.addHandler(serviceName, function (res) { | ||
// setTimeout(function () { | ||
// res.send({ | ||
// name: 'unit_test_1' | ||
// }); | ||
// }, 2000); | ||
// }); | ||
// | ||
// server.on('connect', function () { | ||
// server.register(); | ||
// }); | ||
// | ||
// server.on('register', function () { | ||
// var client = new Client(SERVICE_HOST, SERVICE_PORT); | ||
// client.on('connect', function () { | ||
// client.register(); | ||
// }); | ||
// | ||
// client.on('register', function () { | ||
// client.rpcRequest(serviceName, { | ||
// name: serviceName | ||
// }, function () { | ||
// | ||
// }, function () { | ||
// done(); | ||
// }, 2000); | ||
// }); | ||
// }); | ||
// }); | ||
it('rpcRequest', function(done) { | ||
var server = new Server(SERVICE_HOST, SERVICE_PORT); | ||
server.addHandler(serviceName, function(res) { | ||
res.send({ | ||
name: 'unit_test_1' | ||
}); | ||
}); | ||
server.on('connect', function() { | ||
server.register(); | ||
}); | ||
server.on('register', function() { | ||
var client = new Client(SERVICE_HOST, SERVICE_PORT); | ||
client.on('connect', function() { | ||
client.register(); | ||
}); | ||
client.on('register', function() { | ||
client.rpcRequest(serviceName, { | ||
name: serviceName | ||
}, function(body) { | ||
if (body.name == "unit_test_1") { | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('rpcRequest timeout', function(done) { | ||
var server = new Server(SERVICE_HOST, SERVICE_PORT); | ||
server.addHandler(serviceName, function(res) { | ||
setTimeout(function() { | ||
res.send({ | ||
name: 'unit_test_1' | ||
}); | ||
}, 2000); | ||
}); | ||
server.on('connect', function() { | ||
server.register(); | ||
}); | ||
server.on('register', function() { | ||
var client = new Client(SERVICE_HOST, SERVICE_PORT); | ||
client.on('connect', function() { | ||
client.register(); | ||
}); | ||
client.on('register', function() { | ||
client.rpcRequest(serviceName, { | ||
name: serviceName | ||
}, function() { | ||
}, function() { | ||
done(); | ||
}, 2000); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -0,0 +0,0 @@ var assert = require("assert"); |
@@ -0,0 +0,0 @@ var assert = require("assert"); |
@@ -5,10 +5,10 @@ var assert = require('assert'); | ||
var SERVICE_HOST = '172.16.90.42'; | ||
var SERVICE_HOST = '172.16.50.46'; | ||
var SERVICE_PORT = 9900; | ||
var noop = function () { | ||
var noop = function() { | ||
// something to do... | ||
}; | ||
describe('Server', function () { | ||
describe('Server', function() { | ||
var index = 0; | ||
@@ -18,9 +18,9 @@ var serviceName = ''; | ||
beforeEach(function () { | ||
beforeEach(function() { | ||
serviceName = 'unit_test_' + (index++); | ||
}); | ||
it('connect', function (done) { | ||
it('connect', function(done) { | ||
var server = new Server(SERVICE_HOST, SERVICE_PORT); | ||
server.on('connect', function () { | ||
server.on('connect', function() { | ||
done(); | ||
@@ -30,8 +30,8 @@ }); | ||
it('register', function (done) { | ||
it('register', function(done) { | ||
var server = new Server(SERVICE_HOST, SERVICE_PORT); | ||
server.on('connect', function () { | ||
server.on('connect', function() { | ||
server.register(); | ||
}); | ||
server.on('register', function () { | ||
server.on('register', function() { | ||
done(); | ||
@@ -41,13 +41,13 @@ }); | ||
it('addHandler', function (done) { | ||
it('addHandler', function(done) { | ||
var server = new Server(SERVICE_HOST, SERVICE_PORT); | ||
server.addHandler(serviceName, function () { | ||
server.addHandler(serviceName, function() { | ||
// something to do... | ||
}); | ||
server.on('connect', function () { | ||
server.on('connect', function() { | ||
server.register(); | ||
}); | ||
server.on('register', function () { | ||
server.on('register', function() { | ||
done(); | ||
@@ -57,3 +57,3 @@ }); | ||
it('removeHandler', function () { | ||
it('removeHandler', function() { | ||
var crc32Name = crc32.unsigned(serviceName); | ||
@@ -60,0 +60,0 @@ var server = new Server(SERVICE_HOST, SERVICE_PORT); |
@@ -0,0 +0,0 @@ require('./encoder'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
31916
5
811
+ Addedbignumber.js@^3.0.1
+ Addedbignumber.js@3.1.2(transitive)