Commit Graph

144 Commits

Author SHA1 Message Date
Damien Arrachequesne
05a190a9db chore(release): 6.5.5
Diff: https://github.com/socketio/socket.io-adapter/compare/2.5.4...2.5.5
socket.io-adapter@2.5.5
2024-06-18 12:23:45 +02:00
Andrew Bromwich
93fe19019e chore(deps): bump ws from 8.11.0 to 8.17.1 (#93)
Includes the following security fix: e55e5106f1

Advisory: https://github.com/advisories/GHSA-3h5v-q93c-6h6q
Diff: https://github.com/websockets/ws/compare/8.11.0...8.17.1
2024-06-18 12:21:29 +02:00
Damien Arrachequesne
5eae5a0b54 chore(release): 2.5.4
Diff: https://github.com/socketio/socket.io-adapter/compare/2.5.3...2.5.4
2024-02-22 09:33:01 +01:00
Damien Arrachequesne
005d546767 ci: test with older TypeScript version 2024-02-22 09:31:39 +01:00
Damien Arrachequesne
a13f35f0e6 fix: ensure the order of the commands
Before this change, the broadcast() method would send the BROADCAST
command and then apply it locally (which is required to retrieve the
offset of the message, when connection state recovery is enabled),
while the other commands like disconnectSockets() would first apply it
locally and then send the command to the other nodes.

So, for example:

```js
io.emit("bye");
io.disconnectSockets();
```

In that case, the clients connected to the io instance would not receive
the "bye" event, while the clients connected to the other server
instances would receive it before being disconnected.

Related:

- https://github.com/socketio/socket.io-redis-streams-adapter/issues/13
- https://github.com/socketio/socket.io-postgres-adapter/issues/12
2024-02-22 09:15:45 +01:00
Damien Arrachequesne
207c0dba1a refactor: break circular dependency (2) 2024-02-22 08:34:29 +01:00
Damien Arrachequesne
abc93a9ac7 refactor: break circular dependency (1)
This will be done in two steps, in order to preserve the history of the
index.ts file.
2024-02-22 08:32:40 +01:00
Damien Arrachequesne
9d4c4a75a4 refactor(cluster): export ClusterAdapterOptions and MessageType types
Related:

- 89d00a49e4/lib/adapter.ts (L17)
- 89d00a49e4/lib/adapter.ts (L191)
2024-02-22 08:01:30 +01:00
Damien Arrachequesne
ca397f3afe fix(types): ensure compatibility with TypeScript < 4.5
"import { type ... }" was added in TypeScript 4.5.

Reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/

Related:

- https://github.com/socketio/socket.io-adapter/issues/86
- https://github.com/socketio/socket.io/issues/3891
2024-02-22 07:54:48 +01:00
Damien Arrachequesne
549156c064 chore(release): 2.5.3
Diff: https://github.com/socketio/socket.io-adapter/compare/2.5.2...2.5.3
2024-02-21 12:33:48 +01:00
Damien Arrachequesne
5dcd182736 refactor(cluster): make onMessage() method synchronous
The fetchSockets() method of the parent class is synchronous, so the
onMessage() method does not need to be asynchronous.
2024-02-21 12:09:29 +01:00
Damien Arrachequesne
1d8da64514 ci: upgrade to actions/checkout@4 and actions/setup-node@4
Reference: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/
2024-02-21 11:46:21 +01:00
Damien Arrachequesne
48eddc19ea ci: use Node.js 20
Reference: https://github.com/nodejs/Release
2024-02-21 11:46:21 +01:00
Damien Arrachequesne
2df5e94c81 test(cluster): init the test suite for the clustered adapter
The test suite is imported from [1].

[1]: 193883b9ca/test/index.ts
2024-02-21 11:38:16 +01:00
Damien Arrachequesne
2a6a215600 refactor(cluster): add explicit types 2024-02-20 16:49:23 +01:00
Damien Arrachequesne
d99a71b558 perf(cluster): use timer.refresh()
Reference: https://nodejs.org/api/timers.html#timeoutrefresh
2024-02-20 16:49:23 +01:00
Damien Arrachequesne
39d4220814 refactor(cluster): catch publish errors
Note: the current API does not currently allow the user to handle those
errors (and retry, for example). This might be worth investigating for
the next major version, maybe something like:

```js
try {
  await io.emit("hello");
} catch (e) {
  // something went wrong
}
```

Related: https://github.com/socketio/socket.io-mongo-adapter/issues/15
2024-02-20 16:49:12 +01:00
Damien Arrachequesne
1011ab3bfb refactor(cluster): allow to call onMessage() with a cluster response
The Redis adapter is currently the only adapter which makes a
distinction between publishing messages (one channel for all) and
responses (one channel for each node).
2024-02-20 16:21:50 +01:00
Damien Arrachequesne
0e23ff0cc6 fix(cluster): notify the other nodes when closing
The clustered adapter will now:

- periodically check if a node has left the cluster
- send an event when it leaves the cluster

This should reduce the number of "timeout reached: only x responses
received out of y" errors.
2024-02-20 16:12:47 +01:00
Damien Arrachequesne
80af4e939c fix(cluster): fix count in fetchSockets() method
Related: bd32763043
2024-02-20 15:53:08 +01:00
Damien Arrachequesne
b2d36951ef refactor(cluster): add explicit message types 2024-02-20 15:53:04 +01:00
Damien Arrachequesne
b157e9e1ac refactor: import the ClusterAdapter abstract class
Imported from ef5f0da0b4/lib/cluster-adapter.ts

This abstract class is currently used by the sharded Redis adapter. We
import it here because the logic can be reused by the other adapters,
which will then only need to handle the pub/sub mechanism.
2024-02-20 15:46:13 +01:00
Damien Arrachequesne
28f60b880a chore(release): 2.5.2
Diff: https://github.com/socketio/socket.io-adapter/compare/2.5.1...2.5.2
2023-01-12 08:09:40 +01:00
Damien Arrachequesne
ca39942ce0 chore: move ws from peerDependencies to dependencies
In order to prevent issues like [1].

Note: the version matches the one imported by the `engine.io` package

See: https://github.com/socketio/engine.io/blob/6.3.0/package.json#L43

[1]: https://github.com/socketio/socket.io-redis-adapter/issues/478
2023-01-12 08:02:52 +01:00
Damien Arrachequesne
4e3991f740 chore(release): 2.5.1
Diff: https://github.com/socketio/socket.io-adapter/compare/2.5.0...2.5.1
2023-01-06 12:02:23 +01:00
Damien Arrachequesne
99b0f18819 fix: properly precompute the WebSocket frames
The named import is not supported in some cases:

> node_modules/socket.io-adapter/dist/index.js:170
>            packetOpts.wsPreEncodedFrame = ws_1.WebSocket.Sender.frame(data, {
>                                                          ^
>
> TypeError: Cannot read properties of undefined (reading 'Sender')
>     at RedisAdapter._encode (/.../node_modules/socket.io-adapter/dist/index.js:170:59)
>     at RedisAdapter.broadcast (/.../node_modules/socket.io-adapter/dist/index.js:117:37)

Related: https://github.com/socketio/socket.io-redis-adapter/issues/478
2023-01-06 11:58:04 +01:00
Damien Arrachequesne
00a8e7589e chore(release): 2.5.0
Diff: https://github.com/socketio/socket.io-adapter/compare/2.4.0...2.5.0
2023-01-06 09:26:10 +01:00
Damien Arrachequesne
5f7b47d40f perf: precompute the WebSocket frames when broadcasting
Note:

- only packets without binary attachments are affected
- the permessage-deflate extension must be disabled (which is the default)

Previous attempt:

- wsPreEncoded option: 5579d40c24
- fix for binary packets: a33e42bb7b
- revert: 88eee5948a
2023-01-06 08:42:51 +01:00
Damien Arrachequesne
6fffc2c3d7 ci: upgrade to actions/checkout@3 and actions/setup-node@3
Reference: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/
2023-01-05 08:40:16 +01:00
Damien Arrachequesne
f5294126a8 feat: implement connection state recovery
More information about how this feature is supposed to work will be
provided in the main repository.
2023-01-05 08:39:19 +01:00
Damien Arrachequesne
d5c56d4094 refactor: bump prettier to version 2.8.1
This major bump creates a lot of noise, but it is necessary for
prettier to be able to parse new syntax.
2023-01-05 08:21:31 +01:00
Damien Arrachequesne
060745ada3 test: migrate to TypeScript 2023-01-02 11:28:45 +01:00
Damien Arrachequesne
3410584a93 refactor: use correct type for BroadcastOptions#except
The 'except' attribute is a set of room IDs, which is then converted to
a set of socket IDs in the computeExceptSids() method.

That wasn't caught because both types are aliases for 'string', but
Room could be extended to all primitive values in the future.

Reference: https://developer.mozilla.org/en-US/docs/Glossary/Primitive

Related: https://github.com/socketio/socket.io-adapter/issues/82
2022-05-25 07:06:27 +02:00
Damien Arrachequesne
b92d65cf9c chore(release): 2.4.0
Diff: https://github.com/socketio/socket.io-adapter/compare/2.3.3...2.4.0
2022-03-30 08:03:38 +02:00
Damien Arrachequesne
af9d7936e9 chore: bump lockfile to v2 2022-03-30 07:59:34 +02:00
dependabot[bot]
d9909203cf chore(deps): bump ansi-regex from 3.0.0 to 3.0.1 (#81)
Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 3.0.0 to 3.0.1.
- [Release notes](https://github.com/chalk/ansi-regex/releases)
- [Commits](https://github.com/chalk/ansi-regex/compare/v3.0.0...v3.0.1)

---
updated-dependencies:
- dependency-name: ansi-regex
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-30 07:55:46 +02:00
Damien Arrachequesne
808c0450d8 refactor: do not throw on serverSideEmit() call
Related: https://github.com/socketio/socket.io-adapter/issues/75
2022-03-30 07:49:49 +02:00
Damien Arrachequesne
6c21bceb59 chore: add note about integers used as room identifier 2022-03-29 09:05:31 +02:00
Damien Arrachequesne
38ee887fef feat: notify listeners for each outgoing packet
Related:

- https://github.com/socketio/socket.io/pull/4145
- https://github.com/socketio/socket.io-adapter/pull/78
2022-03-29 08:56:26 +02:00
Damien Arrachequesne
a7f1c90a32 feat: broadcast and expect multiple acks
Tests will be added in the parent repository.

Related:

- https://github.com/socketio/socket.io/issues/1811
- https://github.com/socketio/socket.io/issues/4163
2022-03-29 08:54:54 +02:00
dependabot[bot]
75455fa8ba chore(deps): bump minimist from 1.2.5 to 1.2.6 (#80)
Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-28 07:47:01 +02:00
Damien Arrachequesne
75854a7518 chore(release): 2.3.3
Diff: https://github.com/socketio/socket.io-adapter/compare/2.3.2...2.3.3
2021-11-16 15:30:32 +01:00
Damien Arrachequesne
88eee5948a fix: fix broadcasting volatile packets with binary attachments
The binary attachments of volatile packets were discarded (only the
header packet was sent) due to a bug introduced in [1].

Note: the `wsPreEncoded` option is removed by this commit, as I wasn't
able to find an elegant (read: non explosive) way to keep it.

[1]: 5579d40c24

Related: https://github.com/socketio/socket.io/issues/3919
2021-11-16 15:24:55 +01:00
dependabot[bot]
83cce96d1a chore(deps): bump y18n from 4.0.0 to 4.0.3 (#79)
Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.3.
- [Release notes](https://github.com/yargs/y18n/releases)
- [Changelog](https://github.com/yargs/y18n/blob/y18n-v4.0.3/CHANGELOG.md)
- [Commits](https://github.com/yargs/y18n/compare/v4.0.0...y18n-v4.0.3)

---
updated-dependencies:
- dependency-name: y18n
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-11-16 15:24:26 +01:00
Damien Arrachequesne
d4ef54cccb chore(release): 2.3.2
Diff: https://github.com/socketio/socket.io-adapter/compare/2.3.1...2.3.2
2021-08-28 08:19:55 +02:00
Damien Arrachequesne
12ee96147e ci: add Node.js 16 in the test matrix 2021-08-28 08:10:50 +02:00
dependabot[bot]
2b4cec08a3 chore(deps): bump glob-parent from 5.1.1 to 5.1.2 (#72)
Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 5.1.1 to 5.1.2.
- [Release notes](https://github.com/gulpjs/glob-parent/releases)
- [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md)
- [Commits](https://github.com/gulpjs/glob-parent/compare/v5.1.1...v5.1.2)

---
updated-dependencies:
- dependency-name: glob-parent
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-28 08:07:27 +02:00
dependabot[bot]
5fe8cacd6a chore(deps): bump path-parse from 1.0.6 to 1.0.7 (#73)
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-28 08:07:11 +02:00
Shrikant Sharat Kandula
912e13ad30 fix: fix race condition when leaving rooms (#74)
This should fix the related issue:

```
TypeError: Cannot read property 'size' of undefined
    at Adapter._del (/app/node_modules/socket.io-adapter/dist/index.js:67:37)
    at Adapter.delAll (/app/node_modules/socket.io-adapter/dist/index.js:83:18)
    at Socket.leaveAll (/app/node_modules/socket.io/dist/socket.js:190:22)
    at Socket._onclose (/app/node_modules/socket.io/dist/socket.js:334:14)
    at Client.onclose (/app/node_modules/socket.io/dist/client.js:245:20)
    at Socket.emit (events.js:412:35)
    at Socket.onClose (/app/node_modules/engine.io/lib/socket.js:348:12)
    at Object.onceWrapper (events.js:519:28)
    at WebSocket.emit (events.js:400:28)
    at WebSocket.onClose (/app/node_modules/engine.io/lib/transport.js:106:10)
```

A test case was added, which reproduces the issue by adding a listener
to the "leave-room" event. This does not seem to be the case for the
user reporting the issue though, which may indicate that the root cause
is elsewhere.
2021-08-28 07:51:31 +02:00
Damien Arrachequesne
0667d826f6 chore(release): 2.3.1
Diff: https://github.com/socketio/socket.io-adapter/compare/2.3.0...2.3.1
2021-05-20 00:47:01 +02:00