Comparing version 0.9.7 to 0.9.8
@@ -8,10 +8,3 @@ /** | ||
const beson = (()=>{ | ||
try { | ||
return require(require.resolve('beson', {paths:require.main.paths})); | ||
} | ||
catch(e) { | ||
return require('beson'); | ||
} | ||
})(); | ||
const beson = require('beson'); | ||
const events = require('events'); | ||
@@ -127,3 +120,3 @@ const net = require('net'); | ||
auto_reconnect=false, retry_count=-1, retry_interval=5, | ||
debug=false, | ||
debug=false, serializer=beson.Serialize, deserializer=beson.Deserialize | ||
} = options; | ||
@@ -134,4 +127,8 @@ if ( !host || !port || !channel_id ) { | ||
if ( typeof serializer !== "function" || typeof deserializer !== "function" ) { | ||
throw new Error("Client serializer and deserializer must be functions!"); | ||
} | ||
const inst = new events.EventEmitter(); | ||
@@ -156,2 +153,4 @@ const client = Object.create(null); | ||
client.num_reties = 0; | ||
client.serialize = serializer; | ||
client.deserialize = deserializer; | ||
PRIVATE.set(inst, client); | ||
@@ -201,3 +200,3 @@ | ||
const client = PRIVATE.get(this); | ||
const {socket, state} = client; | ||
const {socket, state, serialize} = client; | ||
const type = Buffer.from([MSG_TYPE.CALL]); | ||
@@ -229,3 +228,3 @@ const unique_id = GenInstId(true); | ||
for(const arg of args) { | ||
const payload = Buffer.from(beson.Serialize(arg)); | ||
const payload = Buffer.from(serialize(arg)); | ||
const payload_len = Buffer.alloc(4); | ||
@@ -240,3 +239,3 @@ payload_len.writeUInt32LE(payload.length); | ||
for(const arg of args) { | ||
const payload = Buffer.from(beson.Serialize(arg)); | ||
const payload = Buffer.from(serialize(arg)); | ||
const payload_len = Buffer.alloc(4); | ||
@@ -260,3 +259,3 @@ payload_len.writeUInt32LE(payload.length); | ||
const client = PRIVATE.get(this); | ||
const {socket, state} = client; | ||
const {socket, state, serialize} = client; | ||
const type = Buffer.from([MSG_TYPE.EVNT]); | ||
@@ -267,3 +266,3 @@ const event_name = Buffer.from(event, "utf8"); | ||
const payload = Buffer.from(beson.Serialize(arg)); | ||
const payload = Buffer.from(serialize(arg)); | ||
const payload_len = Buffer.alloc(4); | ||
@@ -295,3 +294,2 @@ payload_len.writeUInt32LE(payload.length); | ||
}; | ||
function BuildConnection(client) { | ||
@@ -332,5 +330,2 @@ const {remote_host:host, remote_port:port, inst} = client; | ||
} | ||
function _PARSE_CLIENT_DATA() { | ||
@@ -401,3 +396,3 @@ CLIENT_STATE.timeout = null; | ||
else { | ||
const payload = Buffer.from(beson.Serialize(arg)); | ||
const payload = Buffer.from(client.serialize(arg)); | ||
len.writeUInt32LE(payload.length); | ||
@@ -419,3 +414,3 @@ | ||
else { | ||
const payload = Buffer.from(beson.Serialize(arg)); | ||
const payload = Buffer.from(client.serialize(arg)); | ||
len.writeUInt32LE(payload.length); | ||
@@ -501,3 +496,3 @@ client.socket.write(len); | ||
args.push(beson.Deserialize(arg)); | ||
args.push(client.deserialize(arg)); | ||
} | ||
@@ -530,3 +525,3 @@ } | ||
client.chunk = client.chunk.slice(reader.offset); | ||
return { type:MSG_TYPE.CALL_SUCC, unique_id, result:beson.Deserialize(result), client }; | ||
return { type:MSG_TYPE.CALL_SUCC, unique_id, result:client.deserialize(result), client }; | ||
} | ||
@@ -550,3 +545,3 @@ | ||
client.chunk = client.chunk.slice(reader.offset); | ||
return { type:MSG_TYPE.CALL_FAIL, unique_id, error:beson.Deserialize(error), client }; | ||
return { type:MSG_TYPE.CALL_FAIL, unique_id, error:client.deserialize(error), client }; | ||
} | ||
@@ -573,3 +568,3 @@ | ||
client.chunk = client.chunk.slice(reader.offset); | ||
return {type:MSG_TYPE.EVNT, event, arg:beson.Deserialize(arg), client}; | ||
return {type:MSG_TYPE.EVNT, event, arg:client.deserialize(arg), client}; | ||
} | ||
@@ -576,0 +571,0 @@ |
{ | ||
"name": "ipevt", | ||
"version": "0.9.7", | ||
"version": "0.9.8", | ||
"description": "A small library that allows peers to communicate via a central server", | ||
@@ -5,0 +5,0 @@ "main": "ipevt-client.js", |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
48947
0
1509