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

rpc-websockets

Package Overview
Dependencies
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rpc-websockets - npm Package Compare versions

Comparing version 3.1.1 to 3.2.0

22

dist/lib/client.js
/**
* Client wraps the "websockets/ws" library providing JSON RPC 2.0 support on top.
* Client wraps the "uWebSockets/bindings" library providing JSON RPC 2.0 support on top.
* @module Client

@@ -28,2 +28,6 @@ */

var _typeof2 = require("babel-runtime/helpers/typeof");
var _typeof3 = _interopRequireDefault(_typeof2);
var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");

@@ -110,2 +114,3 @@

* @param {Number} timeout - RPC reply timeout value
* @param {Object} uws_opts - options passed to uWebSockets
* @return {Promise}

@@ -117,3 +122,3 @@ */

key: "call",
value: function call(method, params, timeout) {
value: function call(method, params, timeout, uws_opts) {
var _this2 = this;

@@ -124,5 +129,12 @@

"[params]": ["object", Array],
"[timeout]": "number"
"[timeout]": "number",
"[uws_opts]": "object"
});
if (!uws_opts && "object" === (typeof timeout === "undefined" ? "undefined" : (0, _typeof3.default)(timeout))) {
uws_opts = timeout;
timeout = null;
console.log("yes");
}
return new _promise2.default(function (resolve, reject) {

@@ -140,3 +152,3 @@ if (!_this2.ready) return reject(new Error("socket not ready"));

_this2.socket.send((0, _stringify2.default)(message), function (error) {
_this2.socket.send((0, _stringify2.default)(message), uws_opts, function (error) {
if (error) return reject(error);

@@ -328,2 +340,4 @@

this.socket.on("message", function (message) {
if (message instanceof ArrayBuffer) message = Buffer.from(message).toString();
try {

@@ -330,0 +344,0 @@ message = JSON.parse(message);

109

dist/lib/server.js
/**
* Server wraps the "websockets/ws" library providing JSON RPC 2.0 support on top.
* Server wraps the "uWebSockets/bindings" library providing JSON RPC 2.0 support on top.
* @module Server

@@ -455,3 +455,3 @@ */

var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(data) {
var responses, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, message, _response, response;
var msg_options, responses, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, message, _response, response;

@@ -462,9 +462,18 @@ return _regenerator2.default.wrap(function _callee$(_context) {

case 0:
_context.prev = 0;
data = JSON.parse(data);_context.next = 7;
msg_options = {};
if (data instanceof ArrayBuffer) {
msg_options.binary = true;
data = Buffer.from(data).toString();
}
_context.prev = 2;
data = JSON.parse(data);_context.next = 9;
break;
case 4:
_context.prev = 4;
_context.t0 = _context["catch"](0);
case 6:
_context.prev = 6;
_context.t0 = _context["catch"](2);
return _context.abrupt("return", socket.send((0, _stringify2.default)({

@@ -474,7 +483,7 @@ jsonrpc: "2.0",

id: data.id || null
})));
}, msg_options)));
case 7:
case 9:
if (!Array.isArray(data)) {
_context.next = 44;
_context.next = 46;
break;

@@ -484,3 +493,3 @@ }

if (data.length) {
_context.next = 10;
_context.next = 12;
break;

@@ -493,5 +502,5 @@ }

id: null
})));
}, msg_options)));
case 10:
case 12:
responses = [];

@@ -501,8 +510,8 @@ _iteratorNormalCompletion3 = true;

_iteratorError3 = undefined;
_context.prev = 14;
_context.prev = 16;
_iterator3 = (0, _getIterator3.default)(data);
case 16:
case 18:
if (_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done) {
_context.next = 27;
_context.next = 29;
break;

@@ -512,37 +521,37 @@ }

message = _step3.value;
_context.next = 20;
_context.next = 22;
return _this4._runMethod(message, socket._id, ns);
case 20:
case 22:
_response = _context.sent;
if (_response) {
_context.next = 23;
_context.next = 25;
break;
}
return _context.abrupt("continue", 24);
return _context.abrupt("continue", 26);
case 23:
case 25:
responses.push(_response);
case 24:
case 26:
_iteratorNormalCompletion3 = true;
_context.next = 16;
_context.next = 18;
break;
case 27:
_context.next = 33;
case 29:
_context.next = 35;
break;
case 29:
_context.prev = 29;
_context.t1 = _context["catch"](14);
case 31:
_context.prev = 31;
_context.t1 = _context["catch"](16);
_didIteratorError3 = true;
_iteratorError3 = _context.t1;
case 33:
_context.prev = 33;
_context.prev = 34;
case 35:
_context.prev = 35;
_context.prev = 36;

@@ -553,7 +562,7 @@ if (!_iteratorNormalCompletion3 && _iterator3.return) {

case 36:
_context.prev = 36;
case 38:
_context.prev = 38;
if (!_didIteratorError3) {
_context.next = 39;
_context.next = 41;
break;

@@ -564,11 +573,11 @@ }

case 39:
return _context.finish(36);
case 41:
return _context.finish(38);
case 40:
return _context.finish(33);
case 42:
return _context.finish(35);
case 41:
case 43:
if (responses.length) {
_context.next = 43;
_context.next = 45;
break;

@@ -579,14 +588,14 @@ }

case 43:
return _context.abrupt("return", socket.send((0, _stringify2.default)(responses)));
case 45:
return _context.abrupt("return", socket.send((0, _stringify2.default)(responses), msg_options));
case 44:
_context.next = 46;
case 46:
_context.next = 48;
return _this4._runMethod(data, socket._id, ns);
case 46:
case 48:
response = _context.sent;
if (response) {
_context.next = 49;
_context.next = 51;
break;

@@ -597,6 +606,6 @@ }

case 49:
return _context.abrupt("return", socket.send((0, _stringify2.default)(response)));
case 51:
return _context.abrupt("return", socket.send((0, _stringify2.default)(response), msg_options));
case 50:
case 52:
case "end":

@@ -606,3 +615,3 @@ return _context.stop();

}
}, _callee, _this4, [[0, 4], [14, 29, 33, 41], [34,, 36, 40]]);
}, _callee, _this4, [[2, 6], [16, 31, 35, 43], [36,, 38, 42]]);
}));

@@ -609,0 +618,0 @@

{
"name": "rpc-websockets",
"version": "3.1.1",
"version": "3.2.0",
"description": "JSON-RPC 2.0 implementation over WebSockets for Node.js",

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

@@ -94,3 +94,3 @@ <div align="center"><img src="misc/images/logo.png"/></div>

* `address` {String}: The URL of the WebSocket server. Defaults to 'ws://localhost:8080'.
* `options` {Object}: Client options that are also forwarded to `uws`.
* `options` {Object}: Client options that are also forwarded to `μws`.
* `autoconnect` {Boolean}: Client autoconnect upon Client class instantiation. Defaults to `true`.

@@ -101,3 +101,3 @@ * `reconnect` {Boolean}: Whether client should reconnect automatically once the connection is down. Defaults to `true`.

### ws.call(method[, params[, timeout]]) -> Promise
### ws.call(method[, params[, timeout[, μws_options]]]) -> Promise

@@ -110,2 +110,7 @@ Calls a registered RPC method on server. Resolves once the response is ready. Throws if an RPC error was received.

* `timeout` {Number}: Optional RPC reply timeout in milliseconds.
* `μws_options` {Object}: Optional parameters passed to μws.
* `compress` {Boolean}: Specifies whether data should be compressed or not. Defaults to true when permessage-deflate is enabled.
* `binary` {Boolean}: Specifies whether data should be sent as a binary or not. Default is autodetected.
* `mask` {Boolean} Specifies whether data should be masked or not. Defaults to true when websocket is not a server client.
* `fin` {Boolean} Specifies whether data is the last fragment of a message or not. Defaults to true.

@@ -185,7 +190,7 @@ ### ws.notify(method[, params])

Parameters:
* `options` {Object}: Server options that are also forwarded to `uws`.
* `options` {Object}: Server options that are also forwarded to `μws`.
* `port` {Number}: Port number on which the server will listen for incoming requests.
* `host` {String}: Address on which the server will listen for incoming requests.
Once the Server class is instantiated, you can use a `uws` library's instance via server.wss object.
Once the Server class is instantiated, you can use a `μws` library's instance via server.wss object.

@@ -192,0 +197,0 @@ ### server.register(method, handler[, namespace])

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