Commit Graph

1574 Commits

Author SHA1 Message Date
Damien Arrachequesne
b9252e2074 feat: add details to the "close" event
The close event will now include additional details to help debugging
if anything has gone wrong.

Example when a payload is over the maxHttpBufferSize value in HTTP
long-polling mode:

```js
socket.on("close", (reason, details) => {
  console.log(reason); // "transport error"

  // in that case, details is an error object
  console.log(details.message); "xhr post error"
  console.log(details.description); // 413 (the HTTP status of the response)

  // details.context refers to the XMLHttpRequest object
  console.log(details.context.status); // 413
  console.log(details.context.responseText); // ""
});
```

Note: the error object was already included before this commit and is
kept for backward compatibility

Example when a payload is over the maxHttpBufferSize value with
WebSockets:

```js
socket.on("close", (reason, details) => {
  console.log(reason); // "transport close"

  // in that case, details is a plain object
  console.log(details.description); // "websocket connection closed"

  // details.context is a CloseEvent object
  console.log(details.context.code); // 1009 (which means "Message Too Big")
  console.log(details.context.reason); // ""
});
```

Example within a cluster without sticky sessions:

```js
socket.on("close", (reason, details) => {
  console.log(details.context.status); // 400
  console.log(details.context.responseText); // '{"code":1,"message":"Session ID unknown"}'
});
```

Note: we could also print some warnings in development for the "usual"
errors:

- CORS error
- HTTP 400 with multiple nodes
- HTTP 413 with maxHttpBufferSize

but that would require an additional step when going to production
(i.e. setting NODE_ENV variable to "production"). This is open to
discussion!

Related:

- https://github.com/socketio/socket.io/issues/3946
- https://github.com/socketio/socket.io/issues/1979
- https://github.com/socketio/socket.io-client/issues/1518
2022-04-11 17:15:08 +02:00
Damien Arrachequesne
6e1bbff784 chore: add Node.js 16 in the test matrix
See also: https://github.com/nodejs/Release
2022-03-12 11:12:19 +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
f4725f1021 test: exclude iOS 15 from the test matrix for now
Related:

- https://bugs.webkit.org/show_bug.cgi?id=228296
- https://github.com/socketio/socket.io/issues/4263
2022-03-12 06:24:02 +01:00
dependabot[bot]
f51ca4ac3e chore: bump cached-path-relative from 1.0.2 to 1.1.0 (#686)
Bumps [cached-path-relative](https://github.com/ashaffer/cached-path-relative) from 1.0.2 to 1.1.0.
- [Release notes](https://github.com/ashaffer/cached-path-relative/releases)
- [Commits](https://github.com/ashaffer/cached-path-relative/commits)

---
updated-dependencies:
- dependency-name: cached-path-relative
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-08 07:10:28 +01:00
dependabot[bot]
00c673475a chore: bump ajv from 6.10.2 to 6.12.6 (#687)
Bumps [ajv](https://github.com/ajv-validator/ajv) from 6.10.2 to 6.12.6.
- [Release notes](https://github.com/ajv-validator/ajv/releases)
- [Commits](https://github.com/ajv-validator/ajv/compare/v6.10.2...v6.12.6)

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

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-16 06:26:38 +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
1c0fd939a9 docs(changelog): add changelog for version 6.0.3 2021-11-14 08:28:06 +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
6e798fbb5b fix: add package name in nested package.json
Related: https://github.com/socketio/socket.io-client/issues/1513
2021-11-14 07:57:25 +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
Luigi Pinca
27936285ea chore: make postcompile.sh script work on macOS (#681)
On macOS the script was interpreted as the value of the `-i` option. It
will now use an empty extension for the `-i` option and the `-e` option
to specify the script.
2021-11-13 06:33:06 +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
e7ebf4b7dc chore: update caniuse-lite 2021-11-05 07:45:47 +01:00
Damien Arrachequesne
c813fff67c test: skip flaky test
This test fails in CI on chrome 95 / Windows 2012.
2021-11-05 07:42:38 +01:00
Damien Arrachequesne
018e1afcc5 fix(typings): allow any value in the query option
Related: https://github.com/socketio/engine.io-client/issues/679
2021-11-05 07:26:32 +01:00
Kaan Gökdemir
8f68f77825 fix(typings): allow port to be a number (#680)
`string` is kept for backward compatibility (and `location.port` is a
string).

Reference: https://developer.mozilla.org/en-US/docs/Web/API/Location/port

Related: https://github.com/socketio/socket.io-client/issues/1444
2021-11-05 07:22:58 +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
49719142f6 fix: fix usage with vite
It seems vite has issues with absolute dependencies in the "browser"
field, so we'll provide a quick workaround.

Related:

- https://github.com/socketio/socket.io-client/issues/1494
- https://github.com/socketio/socket.io-client/issues/1495
2021-10-14 13:47:29 +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
c6561928be refactor: remove XDomainRequest support
This was used in IE8 (but behind a flag).

BREAKING CHANGE: the enableXDR option is removed

Related: https://github.com/socketio/engine.io-client/issues/674
2021-10-08 13:11:19 +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
b2c73812e9 refactor: remove JSONP polling
JSONP polling was only used in IE7/8, which are not supported anymore.

BREAKING CHANGE: the jsonp and forceJSONP options are removed.
2021-10-08 11:49:15 +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
dependabot[bot]
1cf70a30f1 chore: bump path-parse from 1.0.6 to 1.0.7 (#678)
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-29 08:09:31 +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
08db7f62e4 ci: increase the build timeout
The CI sometimes fails after the 10 minutes timeout.
2021-07-30 09:13:02 +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
589d3ad638 fix: emit ping when receiving a ping from the server
The "ping" event was forgotten when reversing the ping-pong mechanism
in [1]. It will now be properly emitted when receiving a ping from the
server.

[1]: 81d7171c6b

Related: https://github.com/socketio/socket.io-client/issues/1475
2021-06-23 00:44:06 +02:00
Damien Arrachequesne
2525f14888 chore: npm audit fix 2021-06-23 00:14:36 +02:00
Xiaoxin Lu
f30a10b7f4 fix(websocket): fix timer blocking writes (#670)
An immediate setTimeout was used to unblock the WebSocket write.
Unfortunately, this setTimeout can be throttled by browsers when the
tab is backgrounded.

This can lead to missed pong responses to server pings, which
eventually leads to disconnection.

Related: https://github.com/socketio/engine.io-client/issues/649
2021-06-22 23:58:27 +02:00
dependabot[bot]
52847fd958 chore: bump browserslist from 4.15.0 to 4.16.6 (#665)
Bumps [browserslist](https://github.com/browserslist/browserslist) from 4.15.0 to 4.16.6.
- [Release notes](https://github.com/browserslist/browserslist/releases)
- [Changelog](https://github.com/browserslist/browserslist/blob/main/CHANGELOG.md)
- [Commits](https://github.com/browserslist/browserslist/compare/4.15.0...4.16.6)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-03 16:41:35 +02:00
dependabot[bot]
3c9c8603fa chore: bump ws from 7.4.2 to 7.4.6 (#666)
Bumps [ws](https://github.com/websockets/ws) from 7.4.2 to 7.4.6.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/7.4.2...7.4.6)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-02 23:03:08 +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
Damien Arrachequesne
bddd9928fc fix: fix JSONP transport on IE9
This fixes the following error:

> Unable to get value of the property 'readyState': object is null or undefined

Which was introduced in c46611ce44
2021-05-11 08:22:36 +02:00
Damien Arrachequesne
df6a54772d docs(changelog): include changelog for releases 3.5.2 & 4.1.4 2021-05-05 22:45:20 +02:00
Damien Arrachequesne
0acbe5fded chore(release): 5.1.0
Diff: https://github.com/socketio/engine.io-client/compare/5.0.1...5.1.0
2021-05-04 09:40:44 +02:00
Damien Arrachequesne
c46611ce44 refactor: remove "self" references 2021-05-04 09:28:21 +02:00
Damien Arrachequesne
dcb85e902d feat: add the "closeOnBeforeunload" option
Since [1], the socket is now closed when receiving the "beforeunload"
event in the browser.

This change was meant to fix a discrepancy between Chrome and Firefox
when the user reloads/closes a browser tab: Firefox would close the
connection (and emit a "disconnect" event, at the Socket.IO level), but
not Chrome (see [2]).

But it also closes the connection when there is another "beforeunload"
handler, for example when the user is prompted "are you sure you want
to leave this page?".

Note: calling "stopImmediatePropagation()" was a possible workaround:

```js
window.addEventListener('beforeunload', (event) => {
  event.preventDefault();
  event.stopImmediatePropagation();
  event.returnValue = 'are you sure you want to leave this page?';
});
```

This commit adds a "closeOnBeforeunload" option, which controls whether
a handler is registered for the "beforeunload" event.

Syntax:

```js
const socket = require('engine.io-client')('ws://localhost', {
  closeOnBeforeunload: false // defaults to true
});
```

[1]: ed48b5dc34
[2]: https://github.com/socketio/socket.io/issues/3639

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-client/issues/1451

Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
2021-05-04 08:45:09 +02:00
Damien Arrachequesne
9eeed5e0c0 chore(release): 5.0.1
Diff: https://github.com/socketio/engine.io-client/compare/5.0.0...5.0.1
2021-03-31 23:59:36 +02:00