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

socket.io-amqp0

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socket.io-amqp0 - npm Package Compare versions

Comparing version 6.4.0 to 7.0.0

6

CHANGELOG.md
# socket.io-amqp0
## 7.0.0
### Major Changes
- 5ba7b2b: switched to esm
## 6.4.0

@@ -4,0 +10,0 @@

2

dist/index.d.ts
import { BroadcastOptions, Room, SocketId, Adapter } from 'socket.io-adapter';
import { Namespace } from 'socket.io';
import { Connection } from 'amqplib';
export declare enum SidRoomRouting {
export declare const enum SidRoomRouting {
normal = "normal",

@@ -6,0 +6,0 @@ local = "local",

@@ -1,17 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AmqpAdapter = exports.createAdapter = exports.SidRoomRouting = void 0;
const tslib_1 = require("tslib");
/* eslint-disable no-console */
const socket_io_adapter_1 = require("socket.io-adapter");
const debug_1 = tslib_1.__importDefault(require("debug"));
const os_1 = require("os");
const util_1 = require("./util");
const util_2 = require("util");
var SidRoomRouting;
(function (SidRoomRouting) {
SidRoomRouting["normal"] = "normal";
SidRoomRouting["local"] = "local";
SidRoomRouting["banned"] = "banned";
})(SidRoomRouting || (exports.SidRoomRouting = SidRoomRouting = {}));
import { Adapter } from 'socket.io-adapter';
import debugFactory from 'debug';
import { hostname } from 'os';
import { randomString, mapIter, filterIter } from './util';
import { promisify } from 'util';
const nullSet = new Set([null]);

@@ -23,6 +13,6 @@ Object.freeze(nullSet);

const defaultExchangeName = 'socket.io';
const createAdapter = function ({ name, ...opts }) {
export const createAdapter = function ({ name, ...opts }) {
const shim = class AmqpAdapterWrapper extends AmqpAdapter {
constructor(nsp) {
super(nsp, opts, name !== null && name !== void 0 ? name : 'default');
super(nsp, opts, name ?? 'default');
}

@@ -33,6 +23,4 @@ };

};
exports.createAdapter = createAdapter;
class AmqpAdapter extends socket_io_adapter_1.Adapter {
export class AmqpAdapter extends Adapter {
constructor(nsp, options, name) {
var _a, _b, _c, _d;
super(nsp);

@@ -46,10 +34,10 @@ this.nsp = nsp;

this.localRouting = new Set();
this.debug = (0, debug_1.default)(`socket.io-amqp:${name}`);
this.instanceName = (_a = options.instanceName) !== null && _a !== void 0 ? _a : (0, os_1.hostname)();
this.exchangeName = (_b = options.exchangeName) !== null && _b !== void 0 ? _b : defaultExchangeName;
this.queuePrefix = (_c = options.queuePrefix) !== null && _c !== void 0 ? _c : defaultExchangeName;
(_d = options.shutdownCallbackCallback) === null || _d === void 0 ? void 0 : _d.call(options, async () => {
this.debug = debugFactory(`socket.io-amqp:${name}`);
this.instanceName = options.instanceName ?? hostname();
this.exchangeName = options.exchangeName ?? defaultExchangeName;
this.queuePrefix = options.queuePrefix ?? defaultExchangeName;
options.shutdownCallbackCallback?.(async () => {
this.debug('called shutdownCallback');
this.closed = true;
await Promise.all((0, util_1.mapIter)(this.roomListeners.values(), (unsub) => unsub()));
await Promise.all(mapIter(this.roomListeners.values(), (unsub) => unsub()));
});

@@ -100,3 +88,2 @@ this.init(); // hack until issue in socket.io is resolved

async init() {
var _a, _b;
this.debug('start init w/ exchange name', this.exchangeName);

@@ -109,3 +96,3 @@ // console.log('ohai', this.exchangeName);

this.debug('end init');
(_b = (_a = this.options).readyCallback) === null || _b === void 0 ? void 0 : _b.call(_a);
this.options.readyCallback?.();
}

@@ -115,3 +102,3 @@ async close() {

this.closed = true;
await Promise.all((0, util_1.mapIter)(this.roomListeners.values(), (unsub) => unsub()));
await Promise.all(mapIter(this.roomListeners.values(), (unsub) => unsub()));
}

@@ -144,5 +131,5 @@ async setupRoom(room) {

]);
this.debug('gonna bind', this.exchangeName, room !== null && room !== void 0 ? room : defaultRoomName);
await this.consumeChannel.bindQueue(queueName, this.exchangeName, room !== null && room !== void 0 ? room : defaultRoomName);
this.debug('did bind', this.exchangeName, room !== null && room !== void 0 ? room : defaultRoomName);
this.debug('gonna bind', this.exchangeName, room ?? defaultRoomName);
await this.consumeChannel.bindQueue(queueName, this.exchangeName, room ?? defaultRoomName);
this.debug('did bind', this.exchangeName, room ?? defaultRoomName);
return queueName;

@@ -158,3 +145,3 @@ }

this.debug('Starting room listener for', room);
let consumerTag = (0, util_1.randomString)();
let consumerTag = randomString();
const consumeReply = await this.consumeChannel.consume(queueName, async (msg) => {

@@ -182,5 +169,5 @@ if (!msg)

if (room === id) {
if (this.options.sidRoomRouting === SidRoomRouting.banned)
if (this.options.sidRoomRouting === "banned" /* SidRoomRouting.banned */)
continue;
if (this.options.sidRoomRouting === SidRoomRouting.local) {
if (this.options.sidRoomRouting === "local" /* SidRoomRouting.local */) {
this.localRouting.add(room);

@@ -201,3 +188,3 @@ continue;

await Promise.all([
...(0, util_1.mapIter)(newRooms, async (room) => {
...mapIter(newRooms, async (room) => {
const queueName = await this.createRoomExchangeAndQueue(room);

@@ -210,3 +197,2 @@ const unsub = await this.createRoomListener(room, queueName);

del(id, room) {
var _a;
if (this.sids.has(id)) {

@@ -221,3 +207,3 @@ this.sids.get(id).delete(room);

// tear down the room listener
(_a = this.roomListeners.get(room)) === null || _a === void 0 ? void 0 : _a();
this.roomListeners.get(room)?.();
this.roomListeners.delete(room);

@@ -239,10 +225,9 @@ }

this.debug('Publishing message for rooms', rooms, envelope);
const routeKeys = rooms.map((room) => room !== null && room !== void 0 ? room : defaultRoomName);
const routeKeys = rooms.map((room) => room ?? defaultRoomName);
const buffer = Buffer.from(JSON.stringify(envelope));
await (0, util_2.promisify)(this.publishChannel.publish).bind(this.publishChannel)(this.exchangeName, routeKeys[0], buffer, { ...(routeKeys.length > 1 ? { CC: routeKeys.slice(1) } : {}) });
await promisify(this.publishChannel.publish).bind(this.publishChannel)(this.exchangeName, routeKeys[0], buffer, { ...(routeKeys.length > 1 ? { CC: routeKeys.slice(1) } : {}) });
}
async broadcast(packet, opts) {
var _a;
this.debug('broadcast', packet, opts);
if ((_a = opts.flags) === null || _a === void 0 ? void 0 : _a.local) {
if (opts.flags?.local) {
return super.broadcast(packet, opts);

@@ -255,5 +240,5 @@ }

const rooms = opts.rooms && opts.rooms.size ? opts.rooms : nullSet;
const nonlocalRooms = [...(0, util_1.filterIter)(rooms, (room) => !this.localRouting.has(room))];
const nonlocalRooms = [...filterIter(rooms, (room) => !this.localRouting.has(room))];
await Promise.all([
...(0, util_1.mapIter)((0, util_1.filterIter)(rooms, (room) => this.localRouting.has(room)), async (room) => {
...mapIter(filterIter(rooms, (room) => this.localRouting.has(room)), async (room) => {
await this.broadcast(packet, {

@@ -287,3 +272,3 @@ ...opts,

}
callback === null || callback === void 0 ? void 0 : callback(sids);
callback?.(sids);
return Promise.resolve(sids);

@@ -298,3 +283,2 @@ }

}
exports.AmqpAdapter = AmqpAdapter;
//# sourceMappingURL=index.js.map

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.delay = exports.randomString = exports.filterIter = exports.mapIter = void 0;
function* mapIter(iterable, proj) {
export function* mapIter(iterable, proj) {
for (const x of iterable) {

@@ -9,4 +6,3 @@ yield proj(x);

}
exports.mapIter = mapIter;
function* filterIter(iterable, pred) {
export function* filterIter(iterable, pred) {
for (const x of iterable) {

@@ -17,4 +13,3 @@ if (pred(x))

}
exports.filterIter = filterIter;
function randomString(length = 8) {
export function randomString(length = 8) {
let text = '';

@@ -27,7 +22,5 @@ const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

}
exports.randomString = randomString;
function delay(ms) {
export function delay(ms) {
return new Promise((res, rej) => setTimeout(res, ms));
}
exports.delay = delay;
//# sourceMappingURL=util.js.map
{
"name": "socket.io-amqp0",
"version": "6.4.0",
"version": "7.0.0",
"description": "socket.io adapter for amqp 0.9.1+ (e.g. RabbitMQ)",

@@ -5,0 +5,0 @@ "main": "dist/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