@socket.io/redis-adapter
Advanced tools
Comparing version 7.0.0 to 7.0.1
@@ -0,1 +1,11 @@ | ||
## [7.0.1](https://github.com/socketio/socket.io-redis-adapter/compare/7.0.0...7.0.1) (2021-11-15) | ||
### Bug Fixes | ||
* allow numeric rooms ([214b5d1](https://github.com/socketio/socket.io-redis-adapter/commit/214b5d1a8d4f1bc037712ed53dceba7ee55ea643)) | ||
* ignore sessionStore in the fetchSockets method ([c5dce43](https://github.com/socketio/socket.io-redis-adapter/commit/c5dce438950491b608ed8ed46369b8f120fa82e4)) | ||
# [7.0.0](https://github.com/socketio/socket.io-redis-adapter/compare/6.1.0...7.0.0) (2021-05-11) | ||
@@ -2,0 +12,0 @@ |
@@ -50,2 +50,3 @@ import { Adapter, BroadcastOptions, Room, SocketId } from "socket.io-adapter"; | ||
private onmessage; | ||
private hasRoom; | ||
/** | ||
@@ -52,0 +53,0 @@ * Called on request from another node |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -22,2 +33,3 @@ exports.RedisAdapter = exports.createAdapter = void 0; | ||
})(RequestType || (RequestType = {})); | ||
const isNumeric = (str) => !isNaN(str) && !isNaN(parseFloat(str)); | ||
/** | ||
@@ -84,3 +96,3 @@ * Returns a function that will create a RedisAdapter instance. | ||
const room = channel.slice(this.channel.length, -1); | ||
if (room !== "" && !this.rooms.has(room)) { | ||
if (room !== "" && !this.hasRoom(room)) { | ||
return debug("ignore unknown room %s", room); | ||
@@ -102,2 +114,7 @@ } | ||
} | ||
hasRoom(room) { | ||
// @ts-ignore | ||
const hasNumericRoom = isNumeric(room) && this.rooms.has(parseFloat(room)); | ||
return hasNumericRoom || this.rooms.has(room); | ||
} | ||
/** | ||
@@ -213,8 +230,12 @@ * Called on request from another node | ||
requestId: request.requestId, | ||
sockets: localSockets.map((socket) => ({ | ||
id: socket.id, | ||
handshake: socket.handshake, | ||
rooms: [...socket.rooms], | ||
data: socket.data, | ||
})), | ||
sockets: localSockets.map((socket) => { | ||
// remove sessionStore from handshake, as it may contain circular references | ||
const _a = socket.handshake, { sessionStore } = _a, handshake = __rest(_a, ["sessionStore"]); | ||
return { | ||
id: socket.id, | ||
handshake, | ||
rooms: [...socket.rooms], | ||
data: socket.data, | ||
}; | ||
}), | ||
}); | ||
@@ -221,0 +242,0 @@ this.pubClient.publish(this.responseChannel, response); |
{ | ||
"name": "@socket.io/redis-adapter", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"description": "The Socket.IO Redis adapter, allowing to broadcast events between several Socket.IO servers", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
# socket.io-redis | ||
[![Build Status](https://github.com/socketio/socket.io-redis/workflows/CI/badge.svg?branch=master)](https://github.com/socketio/socket.io-redis/actions) | ||
[![NPM version](https://badge.fury.io/js/socket.io-redis.svg)](http://badge.fury.io/js/socket.io-redis) | ||
[![npm version](https://badge.fury.io/js/%40socket.io%2Fredis-adapter.svg)](https://badge.fury.io/js/%40socket.io%2Fredis-adapter) | ||
@@ -29,2 +29,3 @@ ## Table of contents | ||
- [Protocol](#protocol) | ||
- [Migrating from `socket.io-redis`](#migrating-from-socketio-redis) | ||
- [License](#license) | ||
@@ -316,4 +317,32 @@ | ||
## Migrating from `socket.io-redis` | ||
The package was renamed from `socket.io-redis` to `@socket.io/redis-adapter` in [v7](https://github.com/socketio/socket.io-redis-adapter/releases/tag/7.0.0), in order to match the name of the Redis emitter (`@socket.io/redis-emitter`). | ||
To migrate to the new package, you'll need to make sure to provide your own Redis clients, as the package will no longer create Redis clients on behalf of the user. | ||
Before: | ||
```js | ||
const redisAdapter = require("socket.io-redis"); | ||
io.adapter(redisAdapter({ host: "localhost", port: 6379 })); | ||
``` | ||
After: | ||
```js | ||
const { createClient } = require("redis"); | ||
const { createAdapter } = require("@socket.io/redis-adapter"); | ||
const pubClient = createClient({ host: "localhost", port: 6379 }); | ||
const subClient = pubClient.duplicate(); | ||
io.adapter(createAdapter(pubClient, subClient)); | ||
``` | ||
Please note that the communication protocol between the Socket.IO servers has not been updated, so you can have some servers with `socket.io-redis` and some others with `@socket.io/redis-adapter` at the same time. | ||
## License | ||
MIT |
47557
831
347