@socket.io/redis-streams-adapter 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,28 +2,9 @@
2
2
 
3
3
  The `@socket.io/redis-streams-adapter` package allows broadcasting packets between multiple Socket.IO servers.
4
4
 
5
- Supported features:
6
-
7
- - [broadcasting](https://socket.io/docs/v4/broadcasting-events/)
8
- - [utility methods](https://socket.io/docs/v4/server-instance/#Utility-methods)
9
- - [`socketsJoin`](https://socket.io/docs/v4/server-instance/#socketsJoin)
10
- - [`socketsLeave`](https://socket.io/docs/v4/server-instance/#socketsLeave)
11
- - [`disconnectSockets`](https://socket.io/docs/v4/server-instance/#disconnectSockets)
12
- - [`fetchSockets`](https://socket.io/docs/v4/server-instance/#fetchSockets)
13
- - [`serverSideEmit`](https://socket.io/docs/v4/server-instance/#serverSideEmit)
14
- - [connection state recovery](https://socket.io/docs/v4/connection-state-recovery)
15
-
16
- Related packages:
17
-
18
- - Redis adapter: https://github.com/socketio/socket.io-redis-adapter/
19
- - Redis emitter: https://github.com/socketio/socket.io-redis-emitter/
20
- - MongoDB adapter: https://github.com/socketio/socket.io-mongo-adapter/
21
- - MongoDB emitter: https://github.com/socketio/socket.io-mongo-emitter/
22
- - Postgres adapter: https://github.com/socketio/socket.io-postgres-adapter/
23
- - Postgres emitter: https://github.com/socketio/socket.io-postgres-emitter/
24
-
25
5
  **Table of contents**
26
6
 
7
+ - [Supported features](#supported-features)
27
8
  - [Installation](#installation)
28
9
  - [Usage](#usage)
29
10
  - [With the `redis` package](#with-the-redis-package)
@@ -34,6 +15,15 @@ Related packages:
34
15
  - [How it works](#how-it-works)
35
16
  - [License](#license)
36
17
 
18
+ ## Supported features
19
+
20
+ | Feature | `socket.io` version | Support |
21
+ |---------------------------------|---------------------|------------------------------------------------|
22
+ | Socket management | `4.0.0` | :white_check_mark: YES (since version `0.1.0`) |
23
+ | Inter-server communication | `4.1.0` | :white_check_mark: YES (since version `0.1.0`) |
24
+ | Broadcast with acknowledgements | `4.5.0` | :white_check_mark: YES (since version `0.1.0`) |
25
+ | Connection state recovery | `4.6.0` | :white_check_mark: YES (since version `0.1.0`) |
26
+
37
27
  ## Installation
38
28
 
39
29
  ```
package/dist/adapter.js CHANGED
@@ -178,10 +178,10 @@ class RedisStreamsAdapter extends socket_io_adapter_1.ClusterAdapterWithHeartbea
178
178
  for (const entry of entries) {
179
179
  if (entry.message.nsp === this.nsp.name && entry.message.type === "3") {
180
180
  const message = RedisStreamsAdapter.decode(entry.message);
181
- // @ts-ignore
182
- if (shouldIncludePacket(session.rooms, message.data.opts)) {
183
- // @ts-ignore
184
- session.missedPackets.push(message.data.packet.data);
181
+ const { packet, opts } = message.data;
182
+ if (shouldIncludePacket(session.rooms, opts)) {
183
+ packet.data.push(entry.id);
184
+ session.missedPackets.push(packet.data);
185
185
  }
186
186
  }
187
187
  offset = entry.id;
package/dist/util.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export declare function hasBinary(obj: any, toJSON?: boolean): boolean;
2
- export declare function randomId(): string;
3
2
  /**
4
3
  * @see https://redis.io/commands/xread/
5
4
  */
package/dist/util.js CHANGED
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GETDEL = exports.SET = exports.XRANGE = exports.XADD = exports.XREAD = exports.randomId = exports.hasBinary = void 0;
4
- const crypto_1 = require("crypto");
5
- const redis_1 = require("redis");
3
+ exports.GETDEL = exports.SET = exports.XRANGE = exports.XADD = exports.XREAD = exports.hasBinary = void 0;
6
4
  function hasBinary(obj, toJSON) {
7
5
  if (!obj || typeof obj !== "object") {
8
6
  return false;
@@ -29,10 +27,6 @@ function hasBinary(obj, toJSON) {
29
27
  return false;
30
28
  }
31
29
  exports.hasBinary = hasBinary;
32
- function randomId() {
33
- return (0, crypto_1.randomBytes)(8).toString("hex");
34
- }
35
- exports.randomId = randomId;
36
30
  /**
37
31
  * Whether the client comes from the `redis` package
38
32
  *
@@ -64,16 +58,18 @@ function mapResult(result) {
64
58
  */
65
59
  function XREAD(redisClient, streamName, offset, readCount) {
66
60
  if (isRedisV4Client(redisClient)) {
67
- return redisClient.xRead((0, redis_1.commandOptions)({
68
- isolated: true,
69
- }), [
70
- {
71
- key: streamName,
72
- id: offset,
73
- },
74
- ], {
75
- COUNT: readCount,
76
- BLOCK: 5000,
61
+ return Promise.resolve().then(() => require("redis")).then((redisPackage) => {
62
+ return redisClient.xRead(redisPackage.commandOptions({
63
+ isolated: true,
64
+ }), [
65
+ {
66
+ key: streamName,
67
+ id: offset,
68
+ },
69
+ ], {
70
+ COUNT: readCount,
71
+ BLOCK: 5000,
72
+ });
77
73
  });
78
74
  }
79
75
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socket.io/redis-streams-adapter",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "The Socket.IO adapter based on Redis Streams, allowing to broadcast events between several Socket.IO servers",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,11 +17,12 @@
17
17
  "format:check": "prettier --parser typescript --check \"lib/**/*.ts\" \"test/**/*.ts\"",
18
18
  "format:fix": "prettier --parser typescript --write \"lib/**/*.ts\" \"test/**/*.ts\"",
19
19
  "prepack": "npm run compile",
20
- "test": "npm run format:check && npm run compile && npm run test:redis-standalone && npm run test:redis-cluster && npm run test:ioredis-standalone && npm run test:ioredis-cluster",
20
+ "test": "npm run format:check && npm run compile && npm run test:redis-standalone && npm run test:redis-cluster && npm run test:ioredis-standalone && npm run test:ioredis-cluster && npm run test:valkey-standalone",
21
21
  "test:redis-standalone": "nyc mocha --require ts-node/register test/**/*.ts",
22
22
  "test:redis-cluster": "cross-env REDIS_CLUSTER=1 mocha --require ts-node/register test/**/*.ts",
23
23
  "test:ioredis-standalone": "cross-env REDIS_LIB=ioredis mocha --require ts-node/register test/**/*.ts",
24
- "test:ioredis-cluster": "cross-env REDIS_LIB=ioredis REDIS_CLUSTER=1 mocha --require ts-node/register test/**/*.ts"
24
+ "test:ioredis-cluster": "cross-env REDIS_LIB=ioredis REDIS_CLUSTER=1 mocha --require ts-node/register test/**/*.ts",
25
+ "test:valkey-standalone": "cross-env VALKEY=1 mocha --require ts-node/register test/**/*.ts"
25
26
  },
26
27
  "prettier": {
27
28
  "endOfLine": "auto"