πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

websocket-rpc-client

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

websocket-rpc-client - npm Package Compare versions

Comparing version

to
0.2.0

23

dest/ws/events.js

@@ -20,2 +20,8 @@ 'use strict';

/**
* @param {string} name - channel name
* @param {function} cb - callback
*
* @return {WSEvents}
* */
subscribe: function subscribe(name, cb) {

@@ -30,3 +36,12 @@

}
return this;
},
/**
* @param {string} name - channel name
* @param {function} cb - callback
*
* @return {WSEvents}
* */
unsubscribe: function unsubscribe(name, cb) {

@@ -45,3 +60,11 @@ if (name) {

}
return this;
},
/**
* @private
* @param {Object} resp - JSON-RPC event
*
* */
resolveEvent: function resolveEvent(resp) {

@@ -48,0 +71,0 @@ var cbs = this.pool.get(resp.method);

135

dest/ws/packet.js

@@ -13,2 +13,6 @@ 'use strict';

var _defer = require('lodash/defer');
var _defer2 = _interopRequireDefault(_defer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -21,78 +25,75 @@

* @class
* @classdesc ΠžΠΏΠΈΡΡ‹Π²Π°Π΅Ρ‚ ΠΏΠ°ΠΊΠ΅Ρ‚ запроса. ΠžΠΏΡ€Π΅Π΄Π΅Π»ΡΠ΅Ρ‚ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ для Ρ€Π΅Π·ΠΎΠ»Π²Π° Π²Ρ‹Π·ΠΎΠ²Π°, Ρ‚ΠΈΠΏ ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌΡ‹Ρ… Π΄Π°Π½Π½Ρ‹Ρ… ΠΈ описаниС ошибки
*
* @property {number} id - ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ сообщСния
* @property {object} data - Π΄Π°Π½Π½Ρ‹Π΅ ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½Ρ‹Π΅ Π² Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π΅ запроса
* @property {object|string} error - сСрвСрная ошибка
* @property {function} reject - ΠΌΠ΅Ρ‚ΠΎΠ΄ промиса
* @propery {function} resolve - ΠΌΠ΅Ρ‚ΠΎΠ΄ промиса
* @propery {object} config - описаниС Ρ‚Π΅Π»Π° запроса
* @property {number} id - id message
* @property {object} data - request data
* @property {object|string} error - server error
* @property {function} reject - reject promise
* @propery {function} resolve - resolve promise
* @propery {object} config - describe body
* */
exports.default = function () {
var WSPacket = function () {
/**
* @constructor
* @param {number} id - ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ сообщСния
* */
var WSPacket = function () {
/**
* @constructor
* @param {number} id - ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ сообщСния
* */
function WSPacket(id) {
_classCallCheck(this, WSPacket);
function WSPacket(id) {
_classCallCheck(this, WSPacket);
this.id = id;
this.message = {};
this.id = id;
this.message = {};
}
_createClass(WSPacket, [{
key: 'create',
value: function create(method, params, resolve, reject) {
this.message.id = this.id;
this.message.method = method;
this.message.params = params;
this.rejectCb = reject;
this.resolveCb = resolve;
}
_createClass(WSPacket, [{
key: 'create',
value: function create(method, params, resolve, reject) {
this.message.id = this.id;
this.message.method = method;
this.message.params = params;
this.rejectCb = reject;
this.resolveCb = resolve;
}, {
key: 'getMessage',
value: function getMessage() {
return this.message;
}
}, {
key: 'resolve',
value: function resolve(data) {
if ((0, _isFunction2.default)(this.resolveCb)) {
(0, _defer2.default)(this.resolveCb, {
data: data
});
}
}, {
key: 'getMessage',
value: function getMessage() {
return this.message;
return this;
}
}, {
key: 'reject',
value: function reject(error) {
if ((0, _isFunction2.default)(this.rejectCb)) {
(0, _defer2.default)(this.rejectCb, {
error: error
});
}
}, {
key: 'resolve',
value: function resolve(data) {
if ((0, _isFunction2.default)(this.resolveCb)) {
this.resolveCb({
data: data
});
}
return this;
}
}, {
key: 'reject',
value: function reject(error) {
if ((0, _isFunction2.default)(this.rejectCb)) {
this.rejectCb({
error: error
});
}
return this;
}
}, {
key: 'clear',
value: function clear() {
/*delete this.id;
this.message = {};
delete this.data;
delete this.rejectCb;
delete this.resolveCb;
delete this.sourceOut;
delete this.sourceIn;
delete this.error;*/
}
}]);
return this;
}
}, {
key: 'clear',
value: function clear() {
/*delete this.id;
this.message = {};
delete this.data;
delete this.rejectCb;
delete this.resolveCb;
delete this.sourceOut;
delete this.sourceIn;
delete this.error;*/
}
}]);
return WSPacket;
}();
return WSPacket;
}();
return WSPacket;
}();
exports.default = WSPacket;

@@ -15,6 +15,2 @@ 'use strict';

var _packet = require('./packet');
var _packet2 = _interopRequireDefault(_packet);
var _isString = require('lodash/isString');

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

_this2.ws.onmessage = _this2.onMessage.bind(_this2);
_pool2.default.init(100);
_pool2.default.init(_this2.config.poolSize);
resolve(e);

@@ -116,14 +112,14 @@ };

onMessage: function onMessage(data) {
if (data.data instanceof ArrayBuffer) {
this.ws.isBinary = true;
//try {
this.resolve(JSON.parse(_pako2.default.inflate(new Uint8Array(data.data), { to: 'string' })));
/*} catch (e) {
this.resolve({
error: e
})
}*/
} else {
this.resolve(JSON.parse(data.data));
try {
var msg = data.data;
if (data.data instanceof ArrayBuffer) {
this.ws.isBinary = true;
msg = _pako2.default.inflate(new Uint8Array(data.data), { to: 'string' });
}
this.resolve(JSON.parse(msg));
} catch (e) {
this.reject({
error: e
});
}
},

@@ -130,0 +126,0 @@ resolve: function resolve(response) {

{
"name": "websocket-rpc-client",
"version": "0.1.12",
"version": "0.2.0",
"description": "websocket JSON-RPC 2.0 client ",

@@ -5,0 +5,0 @@ "main": "./dest/index.js",

@@ -8,2 +8,8 @@ import defer from 'lodash/defer';

/**
* @param {string} name - channel name
* @param {function} cb - callback
*
* @return {WSEvents}
* */
subscribe(name, cb) {

@@ -18,4 +24,11 @@

}
return this;
},
/**
* @param {string} name - channel name
* @param {function} cb - callback
*
* @return {WSEvents}
* */
unsubscribe(name, cb) {

@@ -34,5 +47,11 @@ if(name) {

}
return this;
},
/**
* @private
* @param {Object} resp - JSON-RPC event
*
* */
resolveEvent(resp) {

@@ -39,0 +58,0 @@ var cbs = this.pool.get(resp.method);

import isFunction from 'lodash/isFunction';
import defer from 'lodash/defer';

@@ -7,65 +8,60 @@ /***

* @class
* @classdesc ΠžΠΏΠΈΡΡ‹Π²Π°Π΅Ρ‚ ΠΏΠ°ΠΊΠ΅Ρ‚ запроса. ΠžΠΏΡ€Π΅Π΄Π΅Π»ΡΠ΅Ρ‚ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ для Ρ€Π΅Π·ΠΎΠ»Π²Π° Π²Ρ‹Π·ΠΎΠ²Π°, Ρ‚ΠΈΠΏ ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌΡ‹Ρ… Π΄Π°Π½Π½Ρ‹Ρ… ΠΈ описаниС ошибки
*
* @property {number} id - ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ сообщСния
* @property {object} data - Π΄Π°Π½Π½Ρ‹Π΅ ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½Ρ‹Π΅ Π² Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π΅ запроса
* @property {object|string} error - сСрвСрная ошибка
* @property {function} reject - ΠΌΠ΅Ρ‚ΠΎΠ΄ промиса
* @propery {function} resolve - ΠΌΠ΅Ρ‚ΠΎΠ΄ промиса
* @propery {object} config - описаниС Ρ‚Π΅Π»Π° запроса
* @property {number} id - id message
* @property {object} data - request data
* @property {object|string} error - server error
* @property {function} reject - reject promise
* @propery {function} resolve - resolve promise
* @propery {object} config - describe body
* */
export default (function(){
class WSPacket {
/**
* @constructor
* @param {number} id - ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ сообщСния
* */
constructor(id) {
this.id = id;
this.message = {}
}
export default class WSPacket {
/**
* @constructor
* @param {number} id - ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ сообщСния
* */
constructor(id) {
this.id = id;
this.message = {}
}
create(method, params, resolve, reject) {
this.message.id = this.id;
this.message.method = method;
this.message.params = params;
this.rejectCb = reject;
this.resolveCb = resolve;
}
create(method, params, resolve, reject) {
this.message.id = this.id;
this.message.method = method;
this.message.params = params;
this.rejectCb = reject;
this.resolveCb = resolve;
}
getMessage() {
return this.message;
}
getMessage() {
return this.message;
}
resolve(data) {
if(isFunction(this.resolveCb)) {
this.resolveCb({
data: data
});
}
return this;
resolve(data) {
if(isFunction(this.resolveCb)) {
defer(this.resolveCb, {
data: data
});
}
return this;
}
reject(error) {
if(isFunction(this.rejectCb )) {
this.rejectCb({
error: error
});
}
return this;
reject(error) {
if(isFunction(this.rejectCb )) {
defer(this.rejectCb, {
error: error
});
}
return this;
}
clear() {
/*delete this.id;
this.message = {};
delete this.data;
delete this.rejectCb;
delete this.resolveCb;
delete this.sourceOut;
delete this.sourceIn;
delete this.error;*/
}
clear() {
/*delete this.id;
this.message = {};
delete this.data;
delete this.rejectCb;
delete this.resolveCb;
delete this.sourceOut;
delete this.sourceIn;
delete this.error;*/
}
return WSPacket;
})()
}
import WSPool from './pool';
import WSEvents from './events';
import WSPacket from './packet';
import isString from 'lodash/isString';

@@ -47,3 +46,3 @@ import isUndefined from 'lodash/isUndefined';

this.ws.onmessage = this.onMessage.bind(this);
WSPool.init(100);
WSPool.init(this.config.poolSize);
resolve(e);

@@ -88,13 +87,13 @@ };

onMessage(data) {
if (data.data instanceof ArrayBuffer) {
this.ws.isBinary = true;
//try {
this.resolve(JSON.parse(pako.inflate(new Uint8Array(data.data), {to: 'string'})))
/*} catch (e) {
this.resolve({
error: e
})
}*/
} else {
this.resolve(JSON.parse(data.data));
try {
var msg = data.data;
if(data.data instanceof ArrayBuffer) {
this.ws.isBinary = true;
msg = pako.inflate(new Uint8Array(data.data), {to: 'string'});
}
this.resolve(JSON.parse(msg));
} catch (e) {
this.reject({
error: e
})
}

@@ -101,0 +100,0 @@ },