Commit Graph

445 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
Damien Arrachequesne
89487d8a66 chore(release): 6.4.0
Diff: https://github.com/socketio/engine.io-client/compare/6.3.1...6.4.0
2023-02-06 17:10:22 +01:00
Damien Arrachequesne
828d447f57 chore(release): 6.3.1
Diff: https://github.com/socketio/engine.io-client/compare/6.3.0...6.3.1
2023-02-04 07:20:23 +01:00
Damien Arrachequesne
e2b39b63f1 chore(release): 6.3.0
Diff: https://github.com/socketio/engine.io-client/compare/6.2.3...6.3.0
2023-01-10 17:05:58 +01:00
Damien Arrachequesne
528a61f86f 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 such as:

- typed imports: `import { type xxx } from ...`
- private attributes: `class A { #b; #c() {} }`
2022-12-13 15:36:28 +01:00
Damien Arrachequesne
824ab4cdd8 chore: bump ws to version 8.11.0
Diff: https://github.com/websockets/ws/compare/8.2.3...8.11.0
2022-12-09 09:36:46 +01:00
Damien Arrachequesne
9d772e36b5 chore(release): 6.2.3
Diff: https://github.com/socketio/engine.io-client/compare/6.2.2...6.2.3
2022-10-13 12:36:04 +02:00
Damien Arrachequesne
1975c5c995 chore(release): 6.2.2
Diff: https://github.com/socketio/engine.io-client/compare/6.2.1...6.2.2
2022-05-02 10:11:32 +02:00
Damien Arrachequesne
8437600aee chore(release): 6.2.1 2022-04-18 00:46:54 +02:00
Damien Arrachequesne
a2946fc697 chore: bump engine.io-parser to version 5.0.3
In order to make sure the types added in [1] are included.

[1]: ad5bd7ddf5
2022-04-18 00:45:25 +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
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
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
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
dependabot[bot]
56af9c59b9 chore: bump engine.io from 4.0.2 to 4.1.2 (#685)
Bumps [engine.io](https://github.com/socketio/engine.io) from 4.0.2 to 4.1.2.
- [Release notes](https://github.com/socketio/engine.io/releases)
- [Changelog](https://github.com/socketio/engine.io/blob/4.1.2/CHANGELOG.md)
- [Commits](https://github.com/socketio/engine.io/compare/4.0.2...4.1.2)

---
updated-dependencies:
- dependency-name: engine.io
  dependency-type: direct:development
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-01-15 07:59:15 +01:00
Damien Arrachequesne
3c40aa91b0 chore(release): 6.1.1
Diff: https://github.com/socketio/engine.io-client/compare/6.1.0...6.1.1
2021-11-14 08:03:50 +01:00
Damien Arrachequesne
c557707fb6 fix: fix vite build for CommonJS users
Related: https://github.com/socketio/socket.io-client/issues/1504
2021-11-14 07:57:25 +01:00
Sten Feldman
8de51c3e37 chore: add bundle files as exportable asset (#682)
This restores the possibility to import the bundle directly, without
getting the following error:
    
> [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/engine.io.min.js' is not defined by "exports"
2021-11-14 07:56:31 +01:00
Damien Arrachequesne
e7b4700d83 chore(release): 6.1.0
Diff: https://github.com/socketio/engine.io-client/compare/6.0.2...6.1.0
2021-11-08 08:29:00 +01:00
Damien Arrachequesne
68dc241444 chore(release): 6.0.2
Diff: https://github.com/socketio/engine.io-client/compare/6.0.1...6.0.2
2021-10-16 01:39:53 +02:00
Damien Arrachequesne
faa9f318e7 fix(bundle): fix vite build
Some bundlers (like vite) do not support having a "browser" field in a
nested package.json.

Note: the previous commit ([1]) fixed the resolution of the "browser"
field in the dev bundle, but the production bundle still failed.

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

[1]: 49719142f6
2021-10-16 01:36:18 +02:00
Damien Arrachequesne
9a622949a0 chore(release): 6.0.1
Diff: https://github.com/socketio/engine.io-client/compare/6.0.0...6.0.1
2021-10-14 14:01:49 +02:00
Damien Arrachequesne
00fcb6e540 chore: export package.json file
Reference: https://nodejs.org/api/packages.html#packages_package_entry_points
2021-10-14 13:49:06 +02:00
Damien Arrachequesne
b3bb73aac7 chore: bump @socket.io/component-emitter to version 3.0.0
The typed events have been moved from [1] to [2] in order to remove
the intermediary class and reduce the bundle size.

Diff: https://github.com/socketio/emitter/compare/2.0.0...3.0.0

[1]: https://github.com/socketio/socket.io-client
[2]: https://github.com/socketio/emitter/
2021-10-14 13:46:08 +02:00
Damien Arrachequesne
15244139e7 chore(release): 6.0.0
Diff: https://github.com/socketio/engine.io-client/compare/5.2.0...6.0.0
2021-10-08 15:50:55 +02:00
Damien Arrachequesne
00d7e7d7ee feat: provide an ESM build without debug
Removing the debug library and the debug calls from the final bundle is
unexpectedly quite hard.

Actually, there are several solutions, each with its own pro and cons:

> use webpack-remove-debug (our previous solution)

Pro: works well, even with ESM imports with a little hack

```js
import debugModule from "debug"; // debug()

const debug = debugModule("my-library"); // debug()

debug("hello world");
```

Cons: only for webpack

See also: https://github.com/johngodley/webpack-remove-debug

> NODE_ENV variable

```js
import debugModule from "debug";

let debug = () => {}

if (process.env.NODE_ENV !== "production") {
  debug = debugModule("my-library");
}
```

Pro: the `debug()` calls are properly removed when bundling for
production

Cons: some bundlers leave the debug library in the bundle, even if it
is not called (for example, rollup needs an additional
"moduleSideEffects: true")

Reference: https://rollupjs.org/guide/en/#treeshake

> dynamic import

```js
let debug = () => {}

if (process.env.NODE_ENV !== "production") {
  import("debug").then(debugModule => {
    debug = debugModule.default("my-library");
  });
}
```

Pro: the sanest solution, which allows to use debug in development

Cons: will likely break some bundlers due to the dynamic import (for
example, not supported for UMD bundles)

> browser field

```json
{
  "browser": {
    "debug": "./noop.js"
  }
}
```

Pro: the safest solution from a compatibility point of view

Cons: some bundlers leave the noop debug calls, even after minification

> remove debug from the source code

We could also remove the debug calls, but the ability to turn them with
a single env variable on is quite appealing (at least in a Node.js
environment):

```
DEBUG=* node index.js
```

> dual packaging (our selected solution)

We provide two ESM builds, one with debug and one without.

Pros:

- no tricky configuration for bundlers
- debug logs are still available in Node.js

Cons:

- no more debug logs in the browser

We will go with the latest solution for now, until there is a better
alternative.
2021-10-08 13:00:12 +02:00
Damien Arrachequesne
27de300de4 chore: migrate to rollup
This change allows us to:

- reduce the size of the bundle
- provide an ESM bundle (for usage in <script type="module">)

BREAKING CHANGE: due to how default export works with ES modules, we
have removed the default export of the library, which means the
following code:

```js
require("engine.io-client")(...);
```

will not work anymore. The named export must be used instead:

```js
const { Socket } = require("engine.io-client);
// or import { Socket } from "engine.io-client";

const socket = new Socket(...);
```

Note: the UMD build still exposes a function though:

```html
<script src="/path/to/engine.io.js"></script>
<script>
  const socket = eio(...);
</script>
```

Note: webpack is still used with zuul because of the custom builder
(zuul-builder-webpack)
2021-10-08 11:46:11 +02:00
Damien Arrachequesne
221433ed52 chore: bump ws
Release notes: https://github.com/websockets/ws/releases/tag/8.0.0
2021-10-08 11:45:53 +02:00
Damien Arrachequesne
7245b803e0 chore: migrate to TypeScript
This change introduces an ESM build which will allow tree shaking. A
CJS build is also provided for backward compatibility.
2021-10-04 23:12:09 +02:00
Damien Arrachequesne
c7e27b0b1d chore(release): 5.2.0
Diff: https://github.com/socketio/engine.io-client/compare/5.1.2...5.2.0
2021-08-29 08:20:47 +02:00
Michael Vartan
5d1d5bea11 feat: add an option to use native timer functions (#672)
This allows to control the behavior of mocked timers (@sinonjs/fake-timers),
depending on the value of the "useNativeTimers" option:

- true: use native setTimeout function
- false (default): use classic timers, that may be mocked

The "installTimerFunctions" method will also be used in the
`socket.io-client` package:

```
import { installTimerFunctions } from "engine.io-client/lib/util";
```

Note: we could also have put the method in its own library, but that
sounded a bit overkill

Related: https://github.com/socketio/socket.io-client/pull/1479
2021-07-30 09:11:49 +02:00
Damien Arrachequesne
c1713d1418 chore: revert zuul bump
The CI with the latest version of zuul (3.12.x) timeouts without any
logs.
2021-07-30 09:11:49 +02:00
Damien Arrachequesne
2de8b4ef97 refactor: remove forked xmlhttprequest-ssl
Our fork of the xmlhttprequest-ssl package, which was created for the
autoUnref feature (see [1]), is not needed anymore as our changes have
been merged upstream (see [2]).

[1]: 65516836b2
[2]: fd05315b41

Related: https://github.com/socketio/engine.io-client/issues/673
2021-07-13 09:10:27 +02:00
Damien Arrachequesne
9c79ba65f5 chore(release): 5.1.2
Diff: https://github.com/socketio/engine.io-client/compare/5.1.1...5.1.2
2021-06-24 08:24:07 +02:00
Damien Arrachequesne
2525f14888 chore: npm audit fix 2021-06-23 00:14:36 +02:00
Damien Arrachequesne
8bc9b3bb81 chore(release): 5.1.1
Diff: https://github.com/socketio/engine.io-client/compare/5.1.0...5.1.1
2021-05-11 08:34:14 +02:00