Commit Graph

1769 Commits

Author SHA1 Message Date
Damien Arrachequesne
273093ceae refactor: prepare the migration to a monorepo 2024-07-04 17:35:42 +02:00
Jakub Szaredko
579d34412a chore: fix compilation on macOS (#1616) 2024-06-11 12:30:57 +02:00
Damien Arrachequesne
4f6030f2c4 chore(release): 4.7.5
Diff: https://github.com/socketio/socket.io-client/compare/4.7.4...4.7.5
socket.io-client@4.7.5
2024-03-14 17:43:43 +01:00
Damien Arrachequesne
34cbfbb532 fix: discard acknowledgements upon disconnection
Previously, getting disconnected while waiting for an acknowledgement
would create a memory leak, as the acknowledgement was never received
and the handler would stay in memory forever.

This commit fixes the issue:

- handlers that do accept an error as first argument, such as:

* `socket.emit("test", (err, value) => { ... })` with `ackTimeout` option
* `socket.timeout(5000).emit("test", (err, value) => { ... })`
* `const value = await socket.emitWithAck("test")`

will now properly resolve with an error and get discarded.

- handlers that don't like `socket.emit("test", (value) => { ... });`
will simply be discarded upon disconnection

Note: the structure of the 'acks' attribute has been left untouched, in
order to prevent any breaking change.

Related:

- https://github.com/socketio/socket.io-client/issues/1546
- https://github.com/socketio/socket.io/issues/4964
2024-03-14 17:34:29 +01:00
Damien Arrachequesne
8cfea8c30b chore(release): 4.7.4
Diff: https://github.com/socketio/socket.io-client/compare/4.7.3...4.7.4
2024-01-12 11:03:23 +01:00
Damien Arrachequesne
ca5d50ebac chore(release): 4.7.3
Diff: https://github.com/socketio/socket.io-client/compare/4.7.2...4.7.3
2024-01-03 21:25:21 +01:00
Damien Arrachequesne
f9c16f2265 fix(typings): fix the type of the socket#id attribute
Related: https://github.com/socketio/socket.io/issues/4884
2024-01-02 15:55:56 +01:00
Damien Arrachequesne
b3f0cab1a0 ci: add Node.js 20 in the test matrix
Reference: https://github.com/nodejs/Release
2023-11-24 08:48:19 +01:00
Damien Arrachequesne
5a3eafed1c fix(typings): accept string | undefined as init argument
Related: https://github.com/socketio/socket.io/issues/4873
2023-11-24 08:48:08 +01:00
Tyler Butler
605de78d2c fix: improve compatibility with node16 module resolution (#1595)
Related:

- https://github.com/microsoft/TypeScript/issues/46770#issuecomment-966612103
- https://github.com/socketio/socket.io-client/issues/1589
2023-11-06 23:34:58 +01:00
Damien Arrachequesne
d00ccd253d ci: bump appiumVersion for Android tests in SauceLabs
> Error: Appium 1.22.1 does not support Android latest.
2023-10-23 11:54:38 +02:00
Damien Arrachequesne
928d76d255 chore(release): 4.7.2
Diff: https://github.com/socketio/socket.io-client/compare/4.7.1...4.7.2
2023-08-03 01:40:17 +02:00
Damien Arrachequesne
74ca7ac0c7 chore: bump engine.io-client to version 6.5.2
Diff: https://github.com/socketio/engine.io-client/compare/6.5.1...6.5.2
Release notes: https://github.com/socketio/engine.io-client/releases/tag/6.5.2
2023-08-03 00:30:57 +02:00
Damien Arrachequesne
0536fccfc2 chore(release): 4.7.1
Diff: https://github.com/socketio/socket.io-client/compare/4.7.0...4.7.1
2023-06-28 09:18:27 +02:00
Damien Arrachequesne
6169bb8782 chore: bump dev dependencies 2023-06-28 09:11:32 +02:00
Damien Arrachequesne
84ec6cf427 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 { io } from "socket.io-client/debug";
```

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

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

[1]: 781d753a62
2023-06-28 09:11:24 +02:00
Damien Arrachequesne
630ff412a4 chore: bump engine.io-client to version 6.5.1
Diff: https://github.com/socketio/engine.io-client/compare/6.5.0...6.5.1
Release notes: https://github.com/socketio/engine.io-client/releases/tag/6.5.1
2023-06-28 08:56:49 +02:00
Damien Arrachequesne
9b235ec01d chore(release): 4.7.0
Diff: https://github.com/socketio/socket.io-client/compare/4.6.2...4.7.0
2023-06-22 11:20:22 +02:00
Max Stepanov
f2892aba0b fix: use same scope for setTimeout and clearTimeout calls (#1568)
Details:

- engine.io-client sets clearTimeoutFn and setTimeoutFn function
  depending on settings passed to manager

- socker.io-client is using manager.setTimeoutFn to start connection
  monitoring timer, but is using regular clearTimeout function to
  stop it when connection is established

- in some setups it is causing timer fail to stop and it will break
  connection every _timeout_ milliseconds (which is 20000 by default)
2023-06-22 09:33:11 +02:00
Damien Arrachequesne
5bc94b56bc fix: properly report timeout error when connecting
In some specific cases (Node.js client with WebSocket only), the reason
attached to the "connect_error" event was "websocket error" instead of
"timeout".

Related: https://github.com/socketio/socket.io/issues/4062
2023-06-20 18:48:11 +02:00
Ray Foss
781d753a62 feat: expose ESM build with debug (#1585)
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:

- https://github.com/socketio/socket.io/issues/4731
- https://github.com/socketio/socket.io/issues/4635
- https://github.com/socketio/socket.io-client/issues/1516
2023-06-20 14:30:54 +02:00
Damien Arrachequesne
8f14b98fff chore: bump engine.io-client to version 6.5.0
Diff: https://github.com/socketio/engine.io-client/compare/6.4.0...6.5.0
Release notes: https://github.com/socketio/engine.io-client/releases/tag/6.5.0
2023-06-16 12:40:51 +02:00
Damien Arrachequesne
a04ae1b094 chore(release): 4.6.2
Diff: https://github.com/socketio/socket.io-client/compare/4.6.1...4.6.2
2023-05-31 11:07:13 +02:00
Damien Arrachequesne
7c1db9d225 chore: bump socket.io-parser to version 4.2.3
Reference: https://github.com/advisories/GHSA-cqmj-92xf-r6r9
2023-05-31 11:02:00 +02:00
Damien Arrachequesne
61dea7135f refactor: remove invalid comma from package.json 2023-05-25 15:00:46 +02:00
Mateusz Burzyński
7ead241ecf fix(exports): move types condition to the top (#1580)
Related: https://github.com/microsoft/TypeScript/issues/50762
2023-05-04 07:29:00 +02:00
Damien Arrachequesne
d0c0557c1b docs(changelog): add version of transitive dependencies 2023-03-27 17:55:46 +02:00
Damien Arrachequesne
89175d0481 chore(release): 4.6.1
Diff: https://github.com/socketio/socket.io-client/compare/4.6.0...4.6.1
2023-02-20 17:46:20 +01:00
Damien Arrachequesne
121fd7c73d refactor: do not reuse the same packet ID for retries
The packet ID cannot be used for deduplication, because it's only
unique for the given session. If you reconnect on another server and
try to resend a packet, then the server won't be able to know whether
the packet has already been processed or not.
2023-02-20 17:31:02 +01:00
Damien Arrachequesne
46213a647e fix: prevent duplicate connections when multiplexing
This bug was introduced in [1]: a multiplexed socket could in some
cases send multiple CONNECT packets, resulting in duplicate connections
on the server side.

A cached socket will now be reopened only if it was inactive, that is,
if one had explicitly called socket.disconnect() before.

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

[1]: b7dd891e89
2023-02-20 17:09:50 +01:00
Damien Arrachequesne
4996f9ee71 fix: do not drain the queue while the socket is offline
In the previous implementation added in [1], the socket would try to
send the packet even if it was disconnected, which would needlessly
exhaust the number of retries.

[1]: 655dce9755
2023-02-20 17:01:22 +01:00
Damien Arrachequesne
5980918b89 chore(release): 4.6.0
Diff: https://github.com/socketio/socket.io-client/compare/4.5.4...4.6.0
2023-02-07 00:26:46 +01:00
Damien Arrachequesne
dff34a3f17 chore: bump engine.io-client to version 6.4.0
The minor bump is due to changes on the server side, but we'll keep the
versions in sync.

Diff: https://github.com/socketio/engine.io-client/compare/6.3.1...6.4.0
Release notes: https://github.com/socketio/engine.io-client/releases/tag/6.4.0
2023-02-06 17:23:45 +01:00
Damien Arrachequesne
4d6d95e079 fix(typings): do not expose browser-specific types
Related:

- https://github.com/socketio/socket.io-client/issues/1561
- b862924b7f
- 37d7a0aa79
2023-02-04 08:21:59 +01:00
Damien Arrachequesne
c54e09d092 test: add more tests for the retry mechanism 2023-02-04 08:04:38 +01:00
Damien Arrachequesne
0110e46842 chore: bump engine.io-client to version 6.3.1
Diff: https://github.com/socketio/engine.io-client/compare/6.3.0...6.3.1
Release notes: https://github.com/socketio/engine.io-client/releases/tag/6.3.1
2023-02-04 07:29:54 +01:00
Damien Arrachequesne
5ba0d498dc refactor: minor edit
Following 655dce9755
2023-02-03 08:27:15 +01:00
Damien Arrachequesne
b1eed5fd75 chore: bump engine.io-client to version 6.3.0
Diff: https://github.com/socketio/engine.io-client/compare/6.2.3...6.3.0
Release notes: https://github.com/socketio/engine.io-client/releases/tag/6.3.0
2023-02-03 08:20:45 +01:00
Damien Arrachequesne
b7dd891e89 fix: ensure manager.socket() returns an active socket
Related: https://github.com/socketio/socket.io-client/issues/1460
2023-02-03 08:16:38 +01:00
Damien Arrachequesne
655dce9755 feat: implement retry mechanism
Syntax:

```js
const socket = io({
  retries: 3,
  ackTimeout: 10000
});

// "my-event" will be sent up to 4 times (1 + 3), until the server sends an acknowledgement
socket.emit("my-event", (err) => {});
```

Notes:

- the order of the packets is guaranteed, as we send packets one by one
- the same packet id is reused for consecutive retries, in order to
allow deduplication on the server side
2023-02-01 08:19:34 +01:00
Damien Arrachequesne
9f3292525b test: add test with onAnyOutgoing() and binary attachments 2023-01-30 08:26:56 +01:00
Damien Arrachequesne
f27cba5b33 refactor: add recovered flag after a successful recovery
Following b4e20c5c70
2023-01-30 08:14:45 +01:00
Damien Arrachequesne
47b979d573 feat: add promise-based acknowledgements
This commit adds some syntactic sugar around acknowledgements:

```js
// without timeout
const response = await socket.emitWithAck("hello", "world");

// with a specific timeout
try {
  const response = await socket.timeout(1000).emitWithAck("hello", "world");
} catch (err) {
  // the server did not acknowledge the event in the given delay
}
```

Note: enviroments that do not support Promises ([1]) will need to add a
polyfill in order to use this feature

See also: 184f3cf7af

[1]: https://caniuse.com/promises
2023-01-30 08:08:06 +01:00
Damien Arrachequesne
b4e20c5c70 feat: implement connection state recovery
Connection state recovery allows a client to reconnect after a
temporary disconnection and restore its state:

- id
- rooms
- data
- missed packets

See also: 54d5ee05a6
2023-01-25 09:21:08 +01:00
Damien Arrachequesne
a1c528b089 fix(typings): properly type emits with timeout (2)
This follows [1], in order to keep the label of each argument.

[1]: 33e417258c

Related:

- https://github.com/socketio/socket.io-client/pull/1570#issuecomment-1384075633
- https://github.com/microsoft/TypeScript/issues/39941
- https://github.com/microsoft/TypeScript/issues/48049
2023-01-17 15:56:37 +01:00
Engin Aydogan
33e417258c fix(typings): properly type emits with timeout (#1570)
When emitting with a timeout (added in version 4.4.0), the "err"
argument was not properly typed and would require to split the client
and server typings. It will now be automatically inferred as an Error
object.

Workaround for previous versions:

```ts
type WithTimeoutAck<isEmitter extends boolean, args extends any[]> = isEmitter extends true ? [Error, ...args] : args;

interface ClientToServerEvents<isEmitter extends boolean = false> {
    withAck: (data: { argName: boolean }, callback: (...args: WithTimeoutAck<isEmitter, [string]>) => void) => void;
}

interface ServerToClientEvents<isEmitter extends boolean = false> {

}

const io = new Server<ClientToServerEvents, ServerToClientEvents<true>>(3000);

io.on("connection", (socket) => {
    socket.on("withAck", (val, cb) => {
        cb("123");
    });
});

const socket: Socket<ServerToClientEvents, ClientToServerEvents<true>> = ioc("http://localhost:3000");

socket.timeout(100).emit("withAck", { argName: true }, (err, val) => {
  // ...
});
```

Related: https://github.com/socketio/socket.io-client/issues/1555
2023-01-16 12:31:01 +01:00
Damien Arrachequesne
18c6e0a6da chore: add security policy 2022-12-14 07:46:55 +01:00
Damien Arrachequesne
91ef8395d5 chore(release): 4.5.4
Diff: https://github.com/socketio/socket.io-client/compare/4.5.3...4.5.4
2022-11-22 22:28:31 +01:00
Damien Arrachequesne
d882822908 ci: migrate from zuul to webdriver.io
zuul is now archived [1] and does not support the new W3C WebDriver
protocol, since it relies on the wd package [2] under the hood, which
uses the (now deprecated) JSON Wire Protocol.

We will now use the webdriver.io test framework, which allows to run
our tests in local and on Sauce Labs (cross-browser and mobile tests).
This allows us to run our tests on latest versions of Android and iOS,
since Sauce Labs only supports the W3C WebDriver protocol for these
platforms ([3]).

[1]: https://github.com/defunctzombie/zuul
[2]: https://github.com/admc/wd
[3]: https://docs.saucelabs.com/dev/w3c-webdriver-capabilities/
2022-11-17 09:51:12 +01:00
Dirk Stolle
e8912891b2 ci: update actions in GitHub Actions workflows (#1564) 2022-11-15 11:34:22 +01:00