Commit Graph

1665 Commits

Author SHA1 Message Date
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
Damien Arrachequesne
d291a4c9f6 fix: ignore packets when the transport is silently closed
In some cases, a "Transport not open" error could be thrown when the
transport was silently closed in the onbeforeunload event (added in
[1]).

To reproduce:

```js
window.addEventListener("unload", () => {
  socket.write("...");
});
```

[1]: ed48b5dc34

Related: https://github.com/socketio/socket.io/issues/3838
2021-03-31 23:53:09 +02:00
Damien Arrachequesne
fc5dc6b91e refactor: use ES6 syntax in tests 2021-03-31 11:35:12 +02:00
Damien Arrachequesne
14e81805ab chore(release): 5.0.0
The major bump is due to a breaking change on the server side.

Diff: https://github.com/socketio/engine.io-client/compare/4.1.2...5.0.0
2021-03-10 10:09:12 +01:00
Damien Arrachequesne
b8e06a8674 refactor: use globalObject "self" in webpack configuration 2021-03-10 10:05:36 +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
Damien Arrachequesne
9bf70c17bd docs(changelog): include changelog for release 3.5.1
Merged from the 3.5.x branch.
2021-03-02 09:45:18 +01:00
Damien Arrachequesne
c361bc691f feat: listen to the "offline" event
The connection will be closed once the "offline" event is emitted by
the browser, in order not to wait for the heartbeat mechanism to detect
the disconnection.

Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/offline_event

Related: https://github.com/socketio/socket.io-client/issues/1433
2021-03-02 09:24:21 +01:00
Damien Arrachequesne
6f7c89db76 chore(release): 4.1.2
Diff: https://github.com/socketio/engine.io-client/compare/4.1.1...4.1.2
2021-02-25 22:42:51 +01:00
Damien Arrachequesne
ed48b5dc34 fix: silently close the transport in the beforeunload hook
Related:

- https://github.com/socketio/socket.io/issues/3639
- https://github.com/socketio/socket.io/issues/3069
2021-02-25 00:32:18 +01:00