Commit Graph

7543 Commits

Author SHA1 Message Date
Damien Arrachequesne
71eaec477c docs(changelog): improve the changelog for version 6.6.0 2024-06-22 10:20:15 +02:00
Damien Arrachequesne
791aa58f4c chore(release): 6.6.0
Diff: https://github.com/socketio/engine.io/compare/6.5.4...6.6.0
engine.io@6.6.0
2024-06-21 14:32:55 +02:00
Damien Arrachequesne
a17cbc5418 chore(release): 6.6.0
Diff: https://github.com/socketio/engine.io-client/compare/6.5.3...6.6.0
engine.io-client@6.6.0
2024-06-21 14:11:15 +02:00
Damien Arrachequesne
6d8a0bea49 refactor: move the req attribute to the polling class 2024-06-21 14:03:22 +02:00
Damien Arrachequesne
c310b7b6b6 refactor: improve types 2024-06-21 14:03:01 +02:00
Damien Arrachequesne
362bc78191 fix: properly call the send callback during upgrade
The "drain" event (added in [1]) had two different meanings:

- the transport is ready to be written
- the packets are sent over the wire

For the WebSocket and the WebTransport transports, those two events
happen at the same time, but this is not the case for the HTTP
long-polling transport:

- the transport is ready to be written when the client sends a GET request
- the packets are sent over the wire when the server responds to the GET request

Which caused an issue with send callbacks during an upgrade, since the
packets were written but the client would not open a new GET request.

There are now two distinct events: "ready" and "drain"

Related: https://github.com/socketio/engine.io/issues/695

[1]: 2a93f06e27
2024-06-21 11:47:41 +02:00
dependabot[bot]
afd29341ee chore(dev-deps): bump ws and engine.io-client in /examples/memory-usage (#703)
Bumps [ws](https://github.com/websockets/ws) to 8.17.1 and updates ancestor dependency [engine.io-client](https://github.com/socketio/engine.io-client). These dependencies need to be updated together.


Updates `ws` from 8.11.0 to 8.17.1
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/8.11.0...8.17.1)

Updates `engine.io-client` from 6.5.3 to 6.5.4
- [Release notes](https://github.com/socketio/engine.io-client/releases)
- [Changelog](https://github.com/socketio/engine.io-client/blob/6.5.4/CHANGELOG.md)
- [Commits](https://github.com/socketio/engine.io-client/compare/6.5.3...6.5.4)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: indirect
- dependency-name: engine.io-client
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-18 20:18:57 +02:00
dependabot[bot]
56c4664bcf chore(deps-dev): bump braces from 3.0.2 to 3.0.3 (#701)
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-18 20:18:35 +02:00
Damien Arrachequesne
6b9e3e458e refactor: improve types 2024-06-18 17:37:12 +02:00
Damien Arrachequesne
f521cbab6d refactor: simplify the heartbeat code 2024-06-18 17:32:06 +02:00
Damien Arrachequesne
5359bae683 perf: do not reset the hearbeat timer on each packet
This behavior was added in [1]. However, there are two problems:

- a new timer is allocated every time a packet is received, which is
wasteful

- the next heartbeat is not actually delayed, since it's the timeout
timer which gets reset, and not the interval timer

Note: delaying the next heartbeat would be a breaking change.

[1]: be7b4e7478
2024-06-18 17:17:17 +02:00
Semih Han Ordu
fb5904ee5f chore(deps): bump ws to version 8.17.1 (#5052)
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 14:40:30 +02:00
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
d3f45dca38 docs(changelog): add release notes for versions 3.6.2 and 6.5.5 2024-06-18 10:47:10 +02:00
Damien Arrachequesne
72408ad462 docs(changelog): include release notes from versions 3.5.3, 3.5.4 and 6.5.4 2024-06-18 10:43:04 +02:00
dependabot[bot]
3c4d314998 chore(deps): bump ws from 8.11.0 to 8.17.1 (#702)
Bumps [ws](https://github.com/websockets/ws) from 8.11.0 to 8.17.1.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/8.11.0...8.17.1)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-18 09:57:32 +02:00
dependabot[bot]
e97a4d3b82 chore: bump ws from 8.11.0 to 8.17.1 (#720)
Bumps [ws](https://github.com/websockets/ws) from 8.11.0 to 8.17.1.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/8.11.0...8.17.1)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-18 09:54:33 +02:00
Damien Arrachequesne
b0721e6407 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-06-17 17:50:39 +02:00
Damien Arrachequesne
9a68c8ce93 perf(websocket): use bound callbacks
Instead of allocating one temporary function for each WebSocket
`send()` call.

Regarding the test removal, the permessage-deflate threshold was
implemented in the "ws" package in [1], so it's not needed anymore.

[1]: 6b3904b42d
2024-06-17 17:47:46 +02:00
Damien Arrachequesne
62f59b6cf3 refactor: remove unnecessary array allocation
If the `packetsFn` array is empty, there is no need to allocate one new
array.
2024-06-14 01:07:48 +02:00
Damien Arrachequesne
407c3ad236 refactor: simplify the handling of the "drain" event
The two event handlers are merged into one.
2024-06-14 00:30:14 +02:00
Damien Arrachequesne
ef1c4c8bb7 refactor: remove the wsPreEncoded option
The wsPreEncoded option was added in the `socket.io-adapter` package
when broadcasting a message to multiple clients.

It was removed in [1] and is now superseded by the `wsPreEncodedFrame`
option, which directly computes the WebSocket frame once for all
clients (see [2]).

[1]: 88eee5948a
[2]: 5f7b47d40f
2024-06-13 23:55:16 +02:00
Damien Arrachequesne
8955eb7b75 docs(examples): add some examples to track the memory usage
Related: fc21c4a05f
2024-06-13 23:21:26 +02:00
Jonathan Perret
fc21c4a05f fix: fix websocket and webtransport send callbacks (#699)
With the `websocket` transport, the callbacks which indicate that the
packets are actually written were not properly called.

Example:

```js
socket.send("hello", () => {
  // the message has been written to the underlying transport
});
```

The bug was caused by the `websocket` transport (and `webtransport` as
well) having its `supportsFraming` property set to `true`, despite
having been changed in [1] to emit a single `drain` event for each
batch of messages written to the transport like the `polling` transport
always did. Note that although [1] is partially reverted in [2], the
new `drain` event behavior is preserved as called out in that commit's
message.

The `supportsFraming` attribute was introduced in [3] (amended by [4])
as a way to distinguish transports that emit one `drain` per message
from those that emit one `drain` per batch. Since the delivery of
`send` callbacks depends on matching `drain` events with
`transport.send` calls, that distinction is vital to correct behavior.

However, now that all transports have converged to "one `drain` per
batch" behavior, this `supportsFraming` property can be retired (and
the code for calling callbacks simplified).

[1]: https://github.com/socketio/engine.io/pull/618
[2]: a65a047526
[3]: https://github.com/socketio/engine.io/pull/130
[4]: https://github.com/socketio/engine.io/pull/132

Related: https://github.com/socketio/engine.io/issues/698
2024-06-13 23:02:22 +02:00
Jakub Szaredko
579d34412a chore: fix compilation on macOS (#1616) 2024-06-11 12:30:57 +02:00
Damien Arrachequesne
b624c50832 fix: add some randomness to the cache busting string generator
The yeast() method could generate the same string twice when used in
two different iframes, which can cause Safari to only send one HTTP
request (deduplication) and trigger an HTTP 400 error afterwards since
the two iframes share the same session ID.

This new method, combining 5 chars from the timestamp and 3 chars from
Math.random() should be sufficient for our use case.

Related: https://github.com/socketio/engine.io/issues/690

See also: 874484cc1e
2024-06-05 13:44:55 +02:00
Damien Arrachequesne
c087dc5f32 docs(changelog): include the size of the bundle 2024-06-04 17:19:31 +02:00
Damien Arrachequesne
ce13763b52 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-06-04 17:08:48 +02:00
Damien Arrachequesne
74cfb98f12 refactor: prefix private attributes to allow property mangling
|          | before  | after   |
|----------|---------|---------|
| min      | 27.3 KB | 26.1 KB |
| min+gzip | 8.8 KB  | 8.7 KB  |
| min+br   | 8.0 KB  | 7.8 KB  |

Reference: https://terser.org/docs/options/#mangle-properties-options
2024-06-04 17:06:29 +02:00
Damien Arrachequesne
2b9abbbfae chore: restore the debug package in the dev bundle
The debug package was not included anymore in the dev bundle since the
migration from webpack to rollup ([1]) in version 6.0.0.

[1]: 27de300de4

See also: 4683a954d4
2024-06-03 14:54:49 +02:00
Damien Arrachequesne
e105551ef1 fix: fix cookie management with WebSocket (Node.js only)
Before this commit, the cookies were only sent with the HTTP
long-polling transport, and not when upgrading to WebSocket.

See also: 5fc88a62d4
2024-06-03 09:58:56 +02:00
Damien Arrachequesne
3f6647897a chore: remove unused rollup plugin
This plugin is not needed anymore, since the
`@socket.io/component-emitter` package now includes an ESM version.
2024-05-31 18:46:37 +02:00
Damien Arrachequesne
4aec72a53c chore: use babel loose mode when transpiling classes
By default, Babel uses `Object.defineProperty()` when transpiling
classes. We'll now use the loose mode which creates a more terse
output.

|          | before | after  |
|----------|--------|--------|
| min+gzip | 8.8 KB | 8.6 KB |
| min+br   | 8.0 KB | 7.7 KB |

Reference: https://babeljs.io/docs/babel-plugin-transform-classes
2024-05-31 18:35:31 +02:00
Damien Arrachequesne
dd52844f09 chore: add a script to compute the bundle size 2024-05-31 18:10:02 +02:00
Damien Arrachequesne
f4d898ee96 feat: allow to provide a list of transport implementations
This commit adds the ability to provide a list of transport
implementations to use when connecting to an Engine.IO server.

This can be used to use HTTP long-polling based on `fetch()`, instead
of the default implementation based on the `XMLHttpRequest` object.

```
import { Socket, Fetch, WebSocket } from "engine.io-client";

const socket = new Socket({
  transports: [Fetch, WebSocket]
});
```

This is useful in some environments that do not provide a
`XMLHttpRequest` object, like Chrome extension background scripts.

> XMLHttpRequest() can't be called from a service worker, extension or
otherwise. Replace calls from your background script to
XMLHttpRequest() with calls to global fetch().

Source: https://developer.chrome.com/docs/extensions/develop/migrate/to-service-workers#replace-xmlhttprequest

Related:

- https://github.com/socketio/engine.io-client/issues/716
- https://github.com/socketio/socket.io/issues/4980

This is also useful when running the client with Deno or Bun, as it
allows to use the built-in `fetch()` method and `WebSocket` object,
instead of using the `xmlhttprequest-ssl` and `ws` Node.js packages.

Related: https://github.com/socketio/socket.io-deno/issues/12

This feature also comes with the ability to exclude the code related to
unused transports (a.k.a. "tree-shaking"):

```js
import { SocketWithoutUpgrade, WebSocket } from "engine.io-client";

const socket = new SocketWithoutUpgrade({
  transports: [WebSocket]
});
```

In that case, the code related to HTTP long-polling and WebTransport
will be excluded from the final bundle.

Related: https://github.com/socketio/socket.io/discussions/4393
2024-05-31 16:56:25 +02:00
Damien Arrachequesne
579b243e89 feat: add the ability to test all transports
When setting the `tryAllTransports` option to `true`, if the first
transport (usually, HTTP long-polling) fails, then the other transports
will be tested too.

This is useful in two cases:

> when HTTP long-polling is disabled on the server, or if CORS fails

Related:

- https://github.com/socketio/engine.io-client/issues/575
- https://github.com/socketio/socket.io-client/issues/1448

> when WebSocket is tested first (`transports: ["websocket", "polling"])

Related:

- https://github.com/socketio/engine.io-client/issues/714
- https://github.com/socketio/socket.io-client/issues/1599

The only potential downside is that the connection attempt could take
more time in case of failure, as there have been reports of WebSocket
connection errors taking several seconds before being detected (that's
one reason for using HTTP long-polling first). That's why the option
defaults to `false` for now.
2024-05-28 19:31:36 +02:00
tnfAngel
31f10f6808 fix(types): make io#httpServer public (#5035)
Related: https://github.com/socketio/socket.io/issues/5034
2024-05-27 18:09:14 +02:00
Damien Arrachequesne
2c1851d095 refactor: simplify transport creation
The try/catch clause was needed for the JSONP transport, which was
removed in [1].

[1]: b2c73812e9
2024-05-20 05:32:08 +02:00
Damien Arrachequesne
68f9e0d8e0 refactor: improve the types 2024-05-19 19:54:56 +02:00
Damien Arrachequesne
c060d65947 refactor: improve the constructor types 2024-05-19 19:41:36 +02:00
Damien Arrachequesne
cb10d01fac docs: improve documentation for the autoUnref option 2024-05-19 19:26:46 +02:00
Damien Arrachequesne
156d622c48 refactor: remove unused onlyBinaryUpgrades option
This option no longer has any effect since [1].

[1]: c46611ce44
2024-05-19 19:16:55 +02:00
pouria azad
89c4c7eb47 refactor(examples): minor tweak (#5017) 2024-05-10 05:00:20 +02:00
Gah Tang
239a2a82d0 fix: fix broadcasting from a parent namespace (#5009)
Following [1], emitting from a dynamic namespace to a room would throw
this error:

> node_modules/socket.io/dist/parent-namespace.js:88
>         this.children.forEach((nsp) => {
>                       ^
> 
> TypeError: Cannot read properties of undefined (reading 'forEach')
>     at ParentBroadcastAdapter.broadcast (node_modules/socket.io/dist/parent-namespace.js:88:23)
>    at BroadcastOperator.emit (node_modules/socket.io/dist/broadcast-operator.js:169:26)
>    at Socket.<anonymous> (server.js:60:33)
>    at Socket.emit (node:events:520:28)
>    at Socket.emitReserved (node_modules/socket.io/dist/typed-events.js:56:22)
>    at Socket._onclose (node_modules/socket.io/dist/socket.js:547:14)
>    at Client.onclose (node_modules/socket.io/dist/client.js:247:20)
>    at Socket.emit (node:events:532:35)
>    at Socket.onClose (node_modules/engine.io/build/socket.js:304:18)
>    at Object.onceWrapper (node:events:639:28)

Previous output code:

```js
class ParentNamespace extends namespace_1.Namespace {
    constructor(server) {
        super(server, "/_" + ParentNamespace.count++);
        this.children = new Set();
    }
    _initAdapter() {
        this.adapter = new ParentBroadcastAdapter(this, this.children);
    }
}
```

Here, `super()` calls `Namespace._initAdapter()`, but `this.children`
is not defined yet, hence the problem.

[1]: b9ce6a25d1

Related: https://github.com/socketio/socket.io/issues/4985
2024-04-26 15:36:26 +02:00
Damien Arrachequesne
b25e728da0 docs: update TypeScript example 2024-04-26 07:45:48 +02:00
Damien Arrachequesne
8a2ece1f36 chore(release): 3.1.2
Diff: https://github.com/socketio/emitter/compare/3.1.1...3.1.2
2024-04-26 07:31:29 +02:00
Damien Arrachequesne
e6aa1a331c fix: point towards the CommonJS types
In order to fix the following issue:

> error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@socket.io/component-emitter")' call instead.
>
> 1 import { Emitter } from "@socket.io/component-emitter";

This problem was introduced in [1], when reworking the dual packaging.

Related: https://github.com/socketio/socket.io-parser/issues/132

[1]: ba6b56de2c
2024-04-26 07:26:11 +02:00
Damien Arrachequesne
62cbed729d refactor: change URL max length to 8000
The previous limit of 2000 characters was a bit too low in certain cases.

From https://www.rfc-editor.org/rfc/rfc9110#section-4.1-5

> It is RECOMMENDED that all senders and recipients support, at a minimum, URIs with lengths of 8000 octets in protocol elements.

Related: https://github.com/socketio/engine.io-client/issues/715

See also: 707597df26
2024-04-23 11:23:18 +02:00
Damien Arrachequesne
b11763beec feat: add HTTP long-polling implementation based on fetch()
Usage:

```js
import { Socket, transports, Fetch } from "engine.io-client";

transports.polling = Fetch;

const socket = new Socket("https://example.com");
```

Note: tree-shaking unused transports is not currently supported and
will be added later.

Related:

- https://github.com/socketio/socket.io/issues/4980
- https://github.com/socketio/engine.io-client/issues/716
2024-04-23 11:09:57 +02:00