Socket
Socket
Sign inDemoInstall

@akiroz/thalamus

Package Overview
Dependencies
50
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.1 to 0.4.0

74

dist/rpc.js

@@ -65,2 +65,3 @@ "use strict";

var js_base64_1 = require("js-base64");
var events_1 = require("events");
function generateCallId(size) {

@@ -102,2 +103,4 @@ if (typeof window !== 'undefined') {

};
var subscribedPrefix = new Map();
var responseMessage = new events_1.EventEmitter();
exports.defaultCallOptions = {

@@ -111,3 +114,3 @@ timeout: 10000,

return __awaiter(this, void 0, void 0, function () {
var id, strId, responseTopic, msg, _a, result, error;
var callId, responsePrefix, responseTopic, msg, _a, result, error;
var _this = this;

@@ -118,25 +121,50 @@ return __generator(this, function (_b) {

opt = Object.assign({}, exports.defaultCallOptions, opt);
id = generateCallId(opt.idSize);
strId = js_base64_1.Base64.fromUint8Array(id, true);
responseTopic = "".concat(topic, "/").concat(strId);
return [4 /*yield*/, new Promise(function (rsov, rjct) {
var timeoutId = setTimeout(function () {
client.unsubscribe(responseTopic);
rjct({ message: "timeout", data: { topic: topic, params: params, opt: opt, id: id } });
}, opt.timeout);
client.subscribe(responseTopic, function (msg) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
clearTimeout(timeoutId);
client.unsubscribe(responseTopic);
rsov(msg);
return [2 /*return*/];
});
}); }, { persistent: false }).then(function () {
return client.publish(topic, MsgPack.encode({ id: id, params: params }));
}).catch(function (err) {
clearTimeout(timeoutId);
client.unsubscribe(responseTopic);
rjct({ message: "pub/sub error: ".concat(err), data: err });
callId = generateCallId(opt.idSize);
responsePrefix = "".concat(topic, "/+");
responseTopic = "".concat(topic, "/").concat(js_base64_1.Base64.fromUint8Array(callId, true));
return [4 /*yield*/, new Promise(function (rsov, rjct) { return __awaiter(_this, void 0, void 0, function () {
var timeoutId, err_1;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
timeoutId = setTimeout(function () {
responseMessage.removeAllListeners(responseTopic);
rjct({ message: "timeout", data: { topic: topic, params: params, opt: opt, id: callId } });
}, opt.timeout);
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
if (!subscribedPrefix.has(responsePrefix)) {
subscribedPrefix.set(responsePrefix, client.subscribe(responsePrefix, function (msg, topic) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
responseMessage.emit(topic, msg);
return [2 /*return*/];
});
}); }).catch(function (err) {
subscribedPrefix.delete(responsePrefix);
return Promise.reject(err);
}));
}
return [4 /*yield*/, subscribedPrefix.get(responsePrefix)];
case 2:
_a.sent();
responseMessage.once(responseTopic, function (msg) {
clearTimeout(timeoutId);
rsov(msg);
});
return [4 /*yield*/, client.publish(topic, MsgPack.encode({ id: callId, params: params }))];
case 3:
_a.sent();
return [3 /*break*/, 5];
case 4:
err_1 = _a.sent();
clearTimeout(timeoutId);
responseMessage.removeAllListeners(responseTopic);
rjct({ message: "pub/sub error: ".concat(err_1), data: err_1 });
return [3 /*break*/, 5];
case 5: return [2 /*return*/];
}
});
})];
}); })];
case 1:

@@ -143,0 +171,0 @@ msg = _b.sent();

{
"name": "@akiroz/thalamus",
"version": "0.3.1",
"version": "0.4.0",
"repository": "github:akiroz/Thalamus",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc