Commit Graph

7 Commits

Author SHA1 Message Date
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
13d08bc0ac test: fix randomly failing test 2023-06-16 10:22:32 +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
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
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
65516836b2 feat: add autoUnref option
With autoUnref set to true (default: false), the Engine.IO client will
allow the program to exit if there is no other active timer/socket in
the event system.

Note: the 'xmlhttprequest-ssl' package has been copied in the contrib/
directory, until the change is merged upstream

Related: https://github.com/socketio/engine.io-client/issues/653
2021-03-03 10:12:40 +01:00