Commit Graph

7693 Commits

Author SHA1 Message Date
Damien Arrachequesne
e2ab447d63 refactor: add missing .js extension for ESM usage 2022-04-18 00:43:40 +02:00
Damien Arrachequesne
582f4fe9ba chore: point the CI badge towards the main branch 2022-04-18 00:42:52 +02:00
Damien Arrachequesne
c7514b5aa6 chore(release): 4.2.0
Diff: https://github.com/socketio/socket.io-parser/compare/4.1.2...4.2.0
2022-04-18 00:26:27 +02:00
Damien Arrachequesne
931f1526a4 chore: add Node.js 16 in the test matrix
See also: https://github.com/nodejs/Release
2022-04-18 00:21:14 +02:00
Damien Arrachequesne
6c9cb27aeb chore: bump @socket.io/component-emitter to version 3.1.0
Related: https://github.com/socketio/socket.io-client/issues/1536
2022-04-18 00:20:17 +02:00
David Pfeffer
b08bc1a93e feat: allow the usage of custom replacer and reviver (#112)
Co-authored-by: Mocanu Cristian <mocanu.cristian93@gmail.com>
2022-04-18 00:19:02 +02:00
Damien Arrachequesne
d7e3ab7956 chore(release): 6.2.0
Diff: https://github.com/socketio/engine.io/compare/6.1.3...6.2.0
2022-04-17 23:53:53 +02:00
Damien Arrachequesne
d0773b8e6d chore(release): 6.2.0
Diff: https://github.com/socketio/engine.io-client/compare/6.1.1...6.2.0
2022-04-17 23:46:57 +02:00
Damien Arrachequesne
bc3cefb57b refactor: replace custom clone method by Object.assign() 2022-04-17 23:35:52 +02:00
Damien Arrachequesne
71cd3ba911 chore: bump @socket.io/component-emitter to version 3.1.0
Release notes: https://github.com/socketio/emitter/releases/tag/3.1.0
2022-04-17 23:28:12 +02:00
Damien Arrachequesne
ab6a6d4db8 chore(release): 3.1.0 2022-04-17 23:21:08 +02:00
Damien Arrachequesne
54468cf7a3 feat: add ESM version
Related: https://github.com/socketio/socket.io-client/issues/1536
2022-04-17 23:18:40 +02:00
Damien Arrachequesne
df32277c3f refactor: import single-file 3rd party modules
This commit allows to:

- provide an ESM version of those modules ([1])
- reduce the attack surface in case of supply chain attacks
- reduce the size of the bundle with tree-shaking

As a downside, we won't receive security updates for those modules
anymore.

[1]: https://github.com/socketio/socket.io-client/issues/1536
2022-04-13 08:31:02 +02:00
Damien Arrachequesne
b4b3ed5c68 refactor: merge the polling.ts and polling-xhr.ts files
In the past, there were two implementations of the HTTP long-polling
feature, one with XMLHttpRequest and one based on JSONP for ancient
browsers (IE7/IE8). The JSONP implementation has been removed in [1].

[1]: b2c73812e9
2022-04-11 18:57:43 +02:00
Damien Arrachequesne
b9252e2074 feat: add details to the "close" event
The close event will now include additional details to help debugging
if anything has gone wrong.

Example when a payload is over the maxHttpBufferSize value in HTTP
long-polling mode:

```js
socket.on("close", (reason, details) => {
  console.log(reason); // "transport error"

  // in that case, details is an error object
  console.log(details.message); "xhr post error"
  console.log(details.description); // 413 (the HTTP status of the response)

  // details.context refers to the XMLHttpRequest object
  console.log(details.context.status); // 413
  console.log(details.context.responseText); // ""
});
```

Note: the error object was already included before this commit and is
kept for backward compatibility

Example when a payload is over the maxHttpBufferSize value with
WebSockets:

```js
socket.on("close", (reason, details) => {
  console.log(reason); // "transport close"

  // in that case, details is a plain object
  console.log(details.description); // "websocket connection closed"

  // details.context is a CloseEvent object
  console.log(details.context.code); // 1009 (which means "Message Too Big")
  console.log(details.context.reason); // ""
});
```

Example within a cluster without sticky sessions:

```js
socket.on("close", (reason, details) => {
  console.log(details.context.status); // 400
  console.log(details.context.responseText); // '{"code":1,"message":"Session ID unknown"}'
});
```

Note: we could also print some warnings in development for the "usual"
errors:

- CORS error
- HTTP 400 with multiple nodes
- HTTP 413 with maxHttpBufferSize

but that would require an additional step when going to production
(i.e. setting NODE_ENV variable to "production"). This is open to
discussion!

Related:

- https://github.com/socketio/socket.io/issues/3946
- https://github.com/socketio/socket.io/issues/1979
- https://github.com/socketio/socket.io-client/issues/1518
2022-04-11 17:15:08 +02:00
Damien Arrachequesne
be3d7f0f1f docs(examples): add TODO example with Postgres and Node.js cluster 2022-04-07 12:35:00 +02:00
Damien Arrachequesne
d12aab2d69 docs(examples): add example with express-session
Related: https://github.com/socketio/socket.io/issues/3933
2022-04-02 11:08:26 +02:00
Damien Arrachequesne
9f758689f6 docs(examples): pin the version of karma-jasmine-html-reporter
Related:

- https://github.com/socketio/socket.io/issues/4325
- https://github.com/dfederm/karma-jasmine-html-reporter/issues/54
2022-04-01 14:42:34 +02:00
Damien Arrachequesne
0b35dc77c0 refactor: make the protocol implementation stricter
This commit handles several edge cases that were silently ignored
before:

- receiving several CONNECT packets during a session
- receiving any packet without CONNECT packet first
2022-03-31 12:24:31 +02:00
Damien Arrachequesne
531104d332 feat: add support for catch-all listeners for outgoing packets
This is similar to `onAny()`, but for outgoing packets.

Syntax:

```js
socket.onAnyOutgoing((event, ...args) => {
  console.log(event);
});
```
2022-03-31 10:35:09 +02:00
Damien Arrachequesne
8b204570a9 feat: broadcast and expect multiple acks
Syntax:

```js
io.timeout(1000).emit("some-event", (err, responses) => {
  // ...
});
```

The adapter exposes two additional methods:

- `broadcastWithAck(packets, opts, clientCountCallback, ack)`

Similar to `broadcast(packets, opts)`, but:

* `clientCountCallback()` is called with the number of clients that
  received the packet (can be called several times in a cluster)
* `ack()` is called for each client response

- `serverCount()`

It returns the number of Socket.IO servers in the cluster (1 for the
in-memory adapter).

Those two methods will be implemented in the other adapters (Redis,
Postgres, MongoDB, ...).

Related:

- https://github.com/socketio/socket.io/issues/1811
- https://github.com/socketio/socket.io/issues/4163
- https://github.com/socketio/socket.io-redis-adapter/issues/445
2022-03-31 07:49:09 +02:00
Damien Arrachequesne
0b7d70ca42 chore: bump lockfile to v2 2022-03-30 08:15:41 +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
6e1bbff784 chore: add Node.js 16 in the test matrix
See also: https://github.com/nodejs/Release
2022-03-12 11:12:19 +01:00
Damien Arrachequesne
46fdc2f0ed feat: slice write buffer according to the maxPayload value
The server will now include a "maxPayload" field in the handshake
details, allowing the clients to decide how many packets they have to
send to stay under the maxHttpBufferSize value.

Related:

- https://github.com/socketio/socket.io-client/issues/1531
- 088dcb4dff
2022-03-12 11:11:17 +01:00
Damien Arrachequesne
f4725f1021 test: exclude iOS 15 from the test matrix for now
Related:

- https://bugs.webkit.org/show_bug.cgi?id=228296
- https://github.com/socketio/socket.io/issues/4263
2022-03-12 06:24:02 +01:00
Damien Arrachequesne
088dcb4dff feat: add the "maxPayload" field in the handshake details
So that clients in HTTP long-polling can decide how many packets they
have to send to stay under the maxHttpBufferSize value.

This is a backward compatible change which should not mandate a new
major revision of the protocol (we stay in v4), as we only add a field
in the JSON-encoded handshake data:

```
0{"sid":"lv_VI97HAXpY6yYWAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000,"maxPayload":1000000}
```

Related: https://github.com/socketio/socket.io-client/issues/1531
2022-03-10 14:20:54 +01:00
Damien Arrachequesne
657f04e0b8 chore: add Node.js 16 in the test matrix
See also: https://github.com/nodejs/Release
2022-03-10 14:20:36 +01:00
dependabot[bot]
f51ca4ac3e chore: bump cached-path-relative from 1.0.2 to 1.1.0 (#686)
Bumps [cached-path-relative](https://github.com/ashaffer/cached-path-relative) from 1.0.2 to 1.1.0.
- [Release notes](https://github.com/ashaffer/cached-path-relative/releases)
- [Commits](https://github.com/ashaffer/cached-path-relative/commits)

---
updated-dependencies:
- dependency-name: cached-path-relative
  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-08 07:10:28 +01:00
Damien Arrachequesne
97f2fa3269 docs: add test suite for checking server compliance
Related: https://github.com/socketio/socket.io-protocol/issues/14
2022-03-01 07:59:50 +01:00
Damien Arrachequesne
e24b27b8ef refactor: return an HTTP 413 response for too large payloads
Before this, the connection was closed abrutly with an HTTP 502
response.

See also: f8100f9237

Related: https://github.com/socketio/socket.io/issues/4293
2022-02-28 07:21:53 +01:00
Damien Arrachequesne
ce3fe9d80b chore(release): 6.1.3
Diff: https://github.com/socketio/engine.io/compare/6.1.2...6.1.3
2022-02-23 07:40:31 +01:00
Damien Arrachequesne
1bc5b1a2fd chore: bump engine.io-parser to version 5.0.3
In order to make sure the types added in [1] are included.

Related:

- https://github.com/socketio/engine.io/issues/639
- https://github.com/socketio/engine.io/issues/640

[1]: ad5bd7ddf5
2022-02-23 07:36:58 +01:00
e3dio
5df4f18f3e perf(uws): remove nested inner functions 2022-02-23 07:16:25 +01:00
e3dio
3367440308 fix(uws): properly handle chunked content (#642)
With the engine based on µWebSockets.js (introduced in version 6.1.0),
a huge request body split in multiple chunks would throw the following
error:

> node:buffer:254
>   TypedArrayPrototypeSet(target, source, targetStart);
>   ^
>
> TypeError: Cannot perform %TypedArray%.prototype.set on a detached ArrayBuffer
>     at Buffer.set (<anonymous>)
>     at _copyActual (node:buffer:254:3)
> node:buffer:254
>   TypedArrayPrototypeSet(target, source, targetStart);
>   ^
>
> TypeError: Cannot perform %TypedArray%.prototype.set on a detached ArrayBuffer
>     at Buffer.set (<anonymous>)
>     at _copyActual (node:buffer:254:3)
>     at Function.concat (node:buffer:562:12)
>     at onEnd (.../node_modules/engine.io/build/transports-uws/polling.js:126:32)
>     at .../node_modules/engine.io/build/transports-uws/polling.js:143:17

Note: µWebSockets.js does not currently support chunked transfer
encoding.
2022-02-23 07:16:25 +01:00
Damien Arrachequesne
d3ae7ab878 docs: add test suite for checking server compliance
Related: https://github.com/socketio/socket.io-protocol/issues/14
2022-02-20 07:34:08 +01:00
dependabot[bot]
4952193c04 chore: bump cached-path-relative from 1.0.2 to 1.1.0 (#125)
Bumps [cached-path-relative](https://github.com/ashaffer/cached-path-relative) from 1.0.2 to 1.1.0.
- [Release notes](https://github.com/ashaffer/cached-path-relative/releases)
- [Commits](https://github.com/ashaffer/cached-path-relative/commits)

---
updated-dependencies:
- dependency-name: cached-path-relative
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-17 07:48:15 +01:00
Damien Arrachequesne
aed252c742 chore(release): 4.1.2
Diff: https://github.com/socketio/socket.io-parser/compare/4.1.1...4.1.2
2022-02-17 07:37:18 +01:00
dependabot[bot]
89209fa22a chore: bump cached-path-relative from 1.0.2 to 1.1.0 (#113)
Bumps [cached-path-relative](https://github.com/ashaffer/cached-path-relative) from 1.0.2 to 1.1.0.
- [Release notes](https://github.com/ashaffer/cached-path-relative/releases)
- [Commits](https://github.com/ashaffer/cached-path-relative/commits)

---
updated-dependencies:
- dependency-name: cached-path-relative
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-17 07:19:50 +01:00
dependabot[bot]
0a3b556de3 chore: bump path-parse from 1.0.6 to 1.0.7 (#108)
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>
2022-02-17 07:18:40 +01:00
Gabba90
7f6b262ac8 fix: allow objects with a null prototype in binary packets (#114) 2022-02-17 07:18:11 +01:00
Jeffrey van Norden
a463d268ed fix(typings): allow CorsOptionsDelegate as cors options (#641)
Reference: https://www.npmjs.com/package/cors#configuring-cors-asynchronously

Related: 54a59cd8f0
2022-02-17 06:36:49 +01:00
dependabot[bot]
2b70ceee63 chore: bump ajv from 6.12.2 to 6.12.6 (#126)
Bumps [ajv](https://github.com/ajv-validator/ajv) from 6.12.2 to 6.12.6.
- [Release notes](https://github.com/ajv-validator/ajv/releases)
- [Commits](https://github.com/ajv-validator/ajv/compare/v6.12.2...v6.12.6)

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

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-16 21:58:23 +01:00