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

@creamery/socket.io-rpc

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@creamery/socket.io-rpc - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

2

lib/rpc-client.d.ts

@@ -10,4 +10,6 @@ /// <reference types="socket.io-client" />

create<T extends object>(id: string): T;
close(): void;
private createCall;
private createNotify;
private send;
}

@@ -17,7 +17,12 @@ "use strict";

this.client.on('notify', (seq, message) => {
const cb = this.handlers.get(seq);
if (typeof cb === 'function') {
cb(...message.params);
const h = this.handlers.get(seq);
if (h && typeof h.callback === 'function') {
h.callback.apply(null, message.params);
}
});
this.client.on('reconnect', () => {
this.handlers.forEach((h) => {
this.send(h.seq);
});
});
}

@@ -41,2 +46,5 @@ create(id) {

}
close() {
this.client.close();
}
createCall(id, name, params) {

@@ -64,4 +72,3 @@ return new Promise((resolve, reject) => {

const seq = this.seq++;
this.handlers.set(seq, cb);
this.client.emit('listen', {
const packet = {
id,

@@ -71,6 +78,22 @@ seq,

params,
};
this.handlers.set(seq, {
...packet,
callback: cb,
});
this.send(seq);
}
send(seq) {
const h = this.handlers.get(seq);
if (h) {
this.client.emit('listen', {
id: h.id,
seq: h.seq,
channel: h.channel,
params: h.params,
});
}
}
}
exports.SocketIORPCClient = SocketIORPCClient;
//# sourceMappingURL=rpc-client.js.map

27

lib/rpc-server.js

@@ -7,2 +7,16 @@ "use strict";

const socket_io_1 = __importDefault(require("socket.io"));
function createCallback({ seq, id, method }, client) {
function cb(...result) {
if (client.connected) {
client.emit('notify', seq, {
id,
method,
params: result,
});
}
else {
}
}
return cb;
}
function NotFoundResponse(id, method) {

@@ -51,6 +65,6 @@ return {

client.on('listen', (message) => {
this.notify(message, client.emit.bind(client));
this.notify(message, client);
});
}
notify(msg, emit) {
notify(msg, client) {
const { id, channel, params, seq } = msg;

@@ -63,12 +77,5 @@ const vendor = this.pool.get(id);

const method = `on${channel}`;
function callback(...result) {
emit('notify', seq, {
id,
method,
params: result,
});
}
if (typeof vendor[method] === 'function') {
try {
params.push(callback);
params.push(createCallback({ seq, id, method }, client));
vendor[method](...params);

@@ -75,0 +82,0 @@ }

{
"name": "@creamery/socket.io-rpc",
"version": "1.0.8",
"version": "1.0.9",
"description": "RPC for SocketIO",

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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