Commit Graph

1665 Commits

Author SHA1 Message Date
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
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]
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
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
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
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
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
fa47916425 chore(release): 6.5.3
Diff: https://github.com/socketio/engine.io-client/compare/6.5.2...6.5.3
2023-11-09 16:28:04 +01:00
Damien Arrachequesne
ef9ad7d1d6 ci: add Node.js 20 in the test matrix
Reference: https://github.com/nodejs/Release
2023-11-09 16:16:41 +01:00
Damien Arrachequesne
707597df26 fix: add a maximum length for the URL
The regular expression used to parse the URL provided by the user has a
time complexity of O(n^2), hence the length limitation.

Please note that this does not seem realistically exploitable, as an
attacker would have to be able to provide a malicious URL to the user
and inject it in the Engine.IO client.

We could also have:

- modified the regex, but there are a lot of edge cases and the current test coverage is probably not sufficient
- use the built-in URL object, but we would have to add a polyfill for old platforms like IE

Thanks to Young-jin Hwang from the Soonchunhyang University for the
responsible disclosure.
2023-11-09 15:35:57 +01:00
dependabot[bot]
8d86e0d892 chore: bump browserify-sign from 4.2.1 to 4.2.2 (#713)
Bumps [browserify-sign](https://github.com/crypto-browserify/browserify-sign) from 4.2.1 to 4.2.2.
- [Changelog](https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md)
- [Commits](https://github.com/crypto-browserify/browserify-sign/compare/v4.2.1...v4.2.2)

---
updated-dependencies:
- dependency-name: browserify-sign
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-09 15:19:00 +01:00
dependabot[bot]
f2aca29494 chore: bump @babel/traverse from 7.12.9 to 7.23.2 (#712)
Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.12.9 to 7.23.2.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)

---
updated-dependencies:
- dependency-name: "@babel/traverse"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-09 15:18:47 +01:00
James Baldassari
c1795ef568 refactor: export TransportError (#709) 2023-11-06 23:20:46 +01:00
Tyler Butler
46ef8512ed fix: improve compatibility with node16 module resolution (#711)
Related:

- https://github.com/microsoft/TypeScript/issues/46770#issuecomment-966612103
- https://github.com/socketio/socket.io-client/issues/1589
2023-11-06 23:18:25 +01:00
Damien Arrachequesne
3dcb88cb31 docs: add note about the agent option
Related: https://github.com/socketio/engine.io-client/pull/708
2023-09-13 11:58:29 +02:00
Damien Arrachequesne
10970563bf chore(release): 6.5.2
Diff: https://github.com/socketio/engine.io-client/compare/6.5.1...6.5.2
2023-08-02 01:57:14 +02:00
Chris Dewbery
ed34a45a07 refactor: reset ping timeout on any incoming packet (#706)
The client will now match the behavior of the server.

See also: be7b4e7478
2023-08-02 01:53:29 +02:00
Damien Arrachequesne
8270e00d5b fix(webtransport): honor the binaryType attribute
The Node.js client will now properly receive binary data as Buffers
instead of ArrayBuffers, when connecting with WebTransport. Browser
clients will still receive ArrayBuffers though (or Blobs, if
`socket.binaryType` is set to "blob").
2023-08-02 01:48:38 +02:00
Damien Arrachequesne
d55c39e0ed fix(webtransport): add proper framing
WebTransport being a stream-based protocol, the chunking boundaries are
not necessarily preserved. That's why we need a header indicating the
type of the payload (plain text or binary) and its length.

See also: a306db09e8
2023-08-02 01:42:23 +02:00
Damien Arrachequesne
500085dcf2 chore(release): 6.5.1
Diff: https://github.com/socketio/engine.io-client/compare/6.5.0...6.5.1
2023-06-28 08:44:52 +02:00
Damien Arrachequesne
a63066bdc8 fix: make closeOnBeforeunload default to false
Silently closing the connection when receiving a "beforeunload" event
is problematic, because it is emitted:

- when downloading a file from another host

Related: https://github.com/socketio/socket.io/issues/4436

- when the user already has a listener for the "beforeunload" event
(i.e. "are you sure you want to leave this page?")

Related:

- https://github.com/socketio/engine.io-client/issues/661
- https://github.com/socketio/engine.io-client/issues/658
- https://github.com/socketio/socket.io/issues/4065

That's why the `closeOnBeforeunload` option will now default to false.
2023-06-28 08:33:40 +02:00
Damien Arrachequesne
1fc61a3be5 refactor: expose the ESM build with debug (bis)
This reverts the previous commit ([1]), and expose the ESM build that
includes the debug package on a subpath:

```js
import { Socket } from "engine.io-client/debug";
```

Reference: https://nodejs.org/api/packages.html#subpath-exports

Related: https://github.com/socketio/socket.io-client/issues/1586

[1]: fe4d93ae20
2023-06-28 08:26:25 +02:00
Damien Arrachequesne
fe4d93ae20 refactor: expose the ESM build with debug
So that debug logs can be printed with vite:

```js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  server: {
    port: 4000
  },
  resolve: {
    conditions: ["development"]
  }
})
```

Reference: https://v2.vitejs.dev/config/#resolve-conditions

Related: 781d753a62
2023-06-27 15:00:05 +02:00
Damien Arrachequesne
6404391143 refactor: allow transportOptions to override all other options
Related: https://github.com/socketio/socket.io/issues/4719
2023-06-27 14:59:09 +02:00
Damien Arrachequesne
cf6aa1f43c fix(webtransport): properly handle abruptly closed connections 2023-06-27 14:25:52 +02:00
Damien Arrachequesne
01804d59c3 chore: update bundle 2023-06-16 11:59:43 +02:00
Damien Arrachequesne
4abc2ca3df chore(release): 6.5.0
Diff: https://github.com/socketio/engine.io-client/compare/6.4.0...6.5.0
2023-06-16 11:05:41 +02:00
Damien Arrachequesne
9d37b16e6a feat: favor WebTransport over WebSocket
This commit ensures that when there are multiple possible upgrades
(like WebSocket and WebTransport), then the WebTransport is favored and
the other upgrades are delayed.

Following 7195c0f305
2023-06-16 10:24:51 +02:00
Damien Arrachequesne
13d08bc0ac test: fix randomly failing test 2023-06-16 10:22:32 +02:00
Damien Arrachequesne
36724da521 refactor: cleanup URI creation
Following 7195c0f305
2023-06-13 17:57:01 +02:00
Damien Arrachequesne
e05367f6bb chore: bump caniuse-lite version 2023-06-13 17:40:54 +02:00
Damien Arrachequesne
73b2f11300 refactor: remove unused async attribute
The `async` flag was always true.
2023-06-13 17:39:59 +02:00
Damien Arrachequesne
2c16af3797 refactor: remove useless xscheme attribute
The xscheme attribute was used when XDomainRequest was supported (IE8).

Related: c6561928be
2023-06-13 17:38:40 +02:00
Damien Arrachequesne
5fc88a62d4 feat: implement cookie management for the Node.js client
When setting the `withCredentials` option to `true`, the Node.js client
will now include the cookies in the HTTP requests, making it easier to
use it with cookie-based sticky sessions.

Related: https://github.com/socketio/socket.io/issues/3812
2023-06-13 17:31:00 +02:00
Damien Arrachequesne
7195c0f305 feat: add support for WebTransport
Reference: https://developer.mozilla.org/en-US/docs/Web/API/WebTransport

Related:

- https://github.com/socketio/engine.io-client/issues/703
- https://github.com/socketio/socket.io/issues/3769
2023-06-12 09:58:47 +02:00