Commit Graph

7651 Commits

Author SHA1 Message Date
dependabot[bot]
218c3443f6 chore: bump express from 4.17.3 to 4.19.2 (#718)
Bumps [express](https://github.com/expressjs/express) from 4.17.3 to 4.19.2.
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/master/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.17.3...4.19.2)

---
updated-dependencies:
- dependency-name: express
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-26 08:15:20 +01:00
Damien Arrachequesne
b0568b20c1 docs: add example with Next.js (with pages router) 2024-03-25 18:05:22 +01:00
Damien Arrachequesne
50176812a1 chore(release): 4.7.5
Diff: https://github.com/socketio/socket.io/compare/4.7.4...4.7.5
4.7.5 socket.io@4.7.5
2024-03-14 17:55:23 +01:00
Damien Arrachequesne
4f6030f2c4 chore(release): 4.7.5
Diff: https://github.com/socketio/socket.io-client/compare/4.7.4...4.7.5
socket.io-client@4.7.5
2024-03-14 17:43:43 +01:00
Damien Arrachequesne
34cbfbb532 fix: discard acknowledgements upon disconnection
Previously, getting disconnected while waiting for an acknowledgement
would create a memory leak, as the acknowledgement was never received
and the handler would stay in memory forever.

This commit fixes the issue:

- handlers that do accept an error as first argument, such as:

* `socket.emit("test", (err, value) => { ... })` with `ackTimeout` option
* `socket.timeout(5000).emit("test", (err, value) => { ... })`
* `const value = await socket.emitWithAck("test")`

will now properly resolve with an error and get discarded.

- handlers that don't like `socket.emit("test", (value) => { ... });`
will simply be discarded upon disconnection

Note: the structure of the 'acks' attribute has been left untouched, in
order to prevent any breaking change.

Related:

- https://github.com/socketio/socket.io-client/issues/1546
- https://github.com/socketio/socket.io/issues/4964
2024-03-14 17:34:29 +01:00
Damien Arrachequesne
bf64870957 fix: close the adapters when the server is closed
Related:

- https://github.com/socketio/socket.io-mongo-adapter/issues/9
- https://github.com/socketio/socket.io-postgres-adapter/issues/13
- 0e23ff0cc6
2024-02-23 12:10:29 +01:00
Jonathan Perret
0efa04b584 fix(types): make socket.request writable (#697)
Related: https://github.com/socketio/engine.io/issues/696
2024-02-23 10:21:43 +01:00
Damien Arrachequesne
748e18c22e ci: test with older TypeScript version
Related: https://github.com/socketio/socket.io/issues/3891
2024-02-22 10:12:18 +01: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
Wang Guan
b9ce6a25d1 refactor: create specific adapter for parent namespaces (#4950) 2024-02-19 22:01:29 +01:00
Damien Arrachequesne
54dabe5bff 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-12 18:16:10 +01:00
Damien Arrachequesne
e426f3e8e1 fix: remove duplicate pipeline when serving bundle
Related: https://github.com/socketio/socket.io/issues/4946
2024-02-12 18:11:38 +01:00
Damien Arrachequesne
69d02dd754 chore(release): 5.2.2
Diff: https://github.com/socketio/engine.io-parser/compare/5.2.1...5.2.2
engine.io-parser@5.2.2
2024-02-05 18:35:35 +01:00
Damien Arrachequesne
0305b4a7a5 fix(typescript): properly import the TransformStream type
When compiling with TypeScript with module set to "node16" and
moduleResolution to "node16", the following error would be thrown:

> node_modules/engine.io-parser/build/cjs/index.d.ts:6:54 - error TS2304: Cannot find name 'TransformStream'.
> 6 export declare function createPacketEncoderStream(): TransformStream<Packet, any>;
>                                                        ~~~~~~~~~~~~~~~
> node_modules/engine.io-parser/build/cjs/index.d.ts:7:96 - error TS2304: Cannot find name 'TransformStream'.
> 7 export declare function createPacketDecoderStream(maxPayload: number, binaryType: BinaryType): TransformStream<Uint8Array, any>;
>                                                                                                  ~~~~~~~~~~~~~~~
> Found 2 errors in the same file, starting at: node_modules/engine.io-parser/build/cjs/index.d.ts:6

This is because the TransformStream object is not exposed in the global
scope in the `@types/node` package, even though it is since Node.js
`v18.0.0`.

Reference: https://nodejs.org/api/webstreams.html#class-transformstream

Note: we only import the TransformStream type (not value) because it
isn't defined on older Node.js versions.

Related:

- https://github.com/socketio/engine.io-parser/issues/136
- https://github.com/socketio/socket.io-client/issues/1606
2024-02-05 18:20:49 +01:00
Damien Arrachequesne
08cff77a48 chore: bump prettier to version 3
This change is necessary to be able to write "import type { ... }".
2024-02-05 18:20:30 +01:00
Damien Arrachequesne
e36062ca2d docs: update the webtransport example
Reference: https://github.com/fails-components/webtransport#changes-for-version-1xx
2024-01-17 13:01:57 +01:00
Damien Arrachequesne
0bbe8aec77 docs: only execute the passport middleware once
Before this change, the session and user context were retrieved once
per HTTP request and not once per session.
2024-01-13 17:56:17 +01:00
Damien Arrachequesne
914a8bd2b9 docs: add example with JWT
Related: https://github.com/socketio/socket.io/issues/4910
2024-01-13 17:14:01 +01:00
Damien Arrachequesne
d943c3e0b0 docs: update the Passport.js example 2024-01-12 17:08:19 +01:00
Damien Arrachequesne
6ab2509d52 chore(release): 4.7.4
Diff: https://github.com/socketio/socket.io/compare/4.7.3...4.7.4
4.7.4
2024-01-12 11:09:14 +01:00
Damien Arrachequesne
8cfea8c30b chore(release): 4.7.4
Diff: https://github.com/socketio/socket.io-client/compare/4.7.3...4.7.4
2024-01-12 11:03:23 +01:00
Zachary Soare
d9fb2f64b6 chore(tests): add a test for noArgs in a namespace 2024-01-08 06:38:57 +01:00
Zachary Soare
2c0a81cd87 chore(tests): fix issues due to client#id type change 2024-01-08 06:38:57 +01:00
Zachary Soare
f8d2644921 chore(tests): add type defs for expectjs and fix invalid expectations 2024-01-08 06:38:57 +01:00
Zachary Soare
04640d68cf chore(tests): indicate a future ts error with version 2024-01-08 06:38:57 +01:00
Zachary Soare
cb6d2e02aa fix(typings): calling io.emit with no arguments incorrectly errored
Refs: #4914
2024-01-08 06:38:57 +01:00
Damien Arrachequesne
80b2c34478 chore: bump socket.io-client version 2024-01-03 21:37:25 +01:00
Damien Arrachequesne
0d893196f8 chore(release): 4.7.3
Diff: https://github.com/socketio/socket.io/compare/4.7.2...4.7.3
4.7.3
2024-01-03 21:33:29 +01:00
Damien Arrachequesne
ca5d50ebac chore(release): 4.7.3
Diff: https://github.com/socketio/socket.io-client/compare/4.7.2...4.7.3
2024-01-03 21:25:21 +01:00
BCCSTeam
df8e70f798 fix: return the first response when broadcasting to a single socket (#4878) 2024-01-02 17:43:10 +01:00
Damien Arrachequesne
f9c16f2265 fix(typings): fix the type of the socket#id attribute
Related: https://github.com/socketio/socket.io/issues/4884
2024-01-02 15:55:56 +01:00