Commit Graph

7693 Commits

Author SHA1 Message Date
Damien Arrachequesne
84397cb0cd feat: add support for typed events
The StrictEventEmitter class that was defined in the socket.io-client
repository ([1]) is moved here, so we don't need to create an
intermediary class (Socket > StrictEventEmitter > Emitter) to get the
proper types.

As an additional benefit, the final bundle size should be decreased.

BREAKING CHANGE: we now use a named export instead of a default export

```js
// before
import Emitter from "@socket.io/component-emitter"

// after
import { Emitter } from "@socket.io/component-emitter"
```

[1]: a9e5b85580/lib/typed-events.ts
2021-10-14 12:25:39 +02:00
Abd Ul-Hameed Maree
a9e5b85580 feat(typings): add missing types for some emitter methods (#1502)
Co-authored-by: Abd UlHameed Maree <abd.maree@scandinaviatech.com>
2021-10-14 10:58:32 +02:00
Damien Arrachequesne
60edecb3bd feat: serve ESM bundle
Related:

- 0661564dc2
- https://github.com/socketio/socket.io-client/issues/1198
2021-10-13 18:17:12 +02:00
Damien Arrachequesne
0661564dc2 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">)

Related: https://github.com/socketio/socket.io-client/issues/1198
2021-10-13 18:09:41 +02:00
Damien Arrachequesne
16b65698ae feat: provide an ESM build with and without debug
See also: 00d7e7d7ee

Related:

- https://github.com/socketio/socket.io-client/issues/1188
- https://github.com/socketio/socket.io-client/issues/1378
2021-10-13 18:09:41 +02:00
Damien Arrachequesne
eb5fdbd03e chore: bump engine.io to version 6.0.0
Release notes: https://github.com/socketio/engine.io/releases/tag/6.0.0
Diff: https://github.com/socketio/engine.io/compare/5.2.0...6.0.0
2021-10-12 00:05:10 +02:00
Damien Arrachequesne
718745305f chore: bump socket.io-parser to version 4.1.0
Diff: https://github.com/socketio/socket.io-parser/compare/4.0.4...4.1.0
2021-10-11 23:19:51 +02:00
Damien Arrachequesne
91fbd47e1e chore: bump engine.io-client to version 6.0.0
Release notes: https://github.com/socketio/engine.io-client/releases/6.0.0
Diff: https://github.com/socketio/engine.io-client/compare/5.2.0...6.0.0
2021-10-11 23:19:51 +02:00
Damien Arrachequesne
5ad3e5cc4b chore(release): 4.1.0
Diff: https://github.com/socketio/socket.io-parser/compare/4.0.4...4.1.0
2021-10-11 22:37:46 +02:00
Damien Arrachequesne
388c616a92 feat: provide an ESM build with and without debug
See also: 00d7e7d7ee
2021-10-11 22:35:12 +02:00
Damien Arrachequesne
fe5d97fc3d chore(release): 6.0.0
Diff: https://github.com/socketio/engine.io/compare/5.2.0...6.0.0
2021-10-08 16:12:32 +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
401f4b6069 chore: add an ES module wrapper 2021-10-08 15:23:57 +02:00
Damien Arrachequesne
64d5754511 chore: bump ws
Release notes: https://github.com/websockets/ws/releases/tag/8.0.0
2021-10-08 15:05:51 +02:00
Damien Arrachequesne
c0d6eaa1ba chore: migrate to TypeScript
Related: https://github.com/socketio/engine.io/issues/510
2021-10-08 14:55:30 +02:00
roh-kan
4974e9077c docs: update .NET client library link (#4115) 2021-10-08 14:18:03 +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
965a567ca0 chore(release): 5.0.0
Diff: https://github.com/socketio/engine.io-parser/compare/4.0.3...5.0.0
2021-10-04 11:02:35 +02:00
Damien Arrachequesne
59b4bad558 chore(release): 2.0.0
Diff: https://github.com/socketio/emitter/compare/1.3.0...2.0.0
2021-10-04 08:12:06 +02:00
Damien Arrachequesne
b19524608b chore: update package name 2021-10-04 08:06:06 +02:00
Damien Arrachequesne
2fd2d6bb0e chore: add default export
So that we can use `import Emitter from ...` in both CommonJS and ESM
modules.
2021-10-04 08:04:09 +02:00
Damien Arrachequesne
908fbc4f4c chore: add removeListener typings
Related: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55968
2021-10-04 08:01:23 +02:00
Damien Arrachequesne
e4d9fce4d8 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-01 10:39:52 +02:00
douira
033c5d399a fix(typings): add name field to cookie option (#4099)
Reference: 18a6eb89fb/lib/server.js (L355)
2021-09-20 09:13:38 +02:00
Damien Arrachequesne
7a74b66872 test: remove hardcoded ports
Related: https://github.com/socketio/socket.io/issues/3447
2021-09-09 08:57:11 +02:00
Damien Arrachequesne
dc81fcf461 fix: send volatile packets with binary attachments
The binary attachments of volatile packets were discarded (only the
header packet was sent) due to a bug introduced by [1].

Related: https://github.com/socketio/socket.io/issues/3919

[1]: dc381b72c6
2021-09-09 08:55:51 +02:00
mingkaili
18a6eb89fb docs: remove the extra bracket in README (#627) 2021-09-09 07:21:04 +02:00
Damien Arrachequesne
c100b7b61c chore(release): 4.2.0
Diff: https://github.com/socketio/socket.io/compare/4.1.3...4.2.0
4.2.0
2021-08-30 09:21:00 +02:00
Damien Arrachequesne
0a7efc8217 chore(release): 4.2.0
Diff: https://github.com/socketio/socket.io-client/compare/4.1.3...4.2.0
2021-08-30 09:15:30 +02:00
Damien Arrachequesne
f03eeca39a chore: bump dependencies 2021-08-30 08:27:46 +02:00
Damien Arrachequesne
ec3a784fa6 chore: bump dependencies 2021-08-30 08:21:47 +02:00
Damien Arrachequesne
66e00b7dd7 fix(typings): allow async listener in typed events
So that:

```ts
socket.on("my-event", async () => {
  // ...
});
```

is valid under the @typescript-eslint/no-misused-promises rule.

Related: https://github.com/socketio/socket.io-client/issues/1486
2021-08-30 08:21:47 +02:00
Damien Arrachequesne
d8cc8aef7e docs: update the link of the Repl.it badge
The link will now point towards a sample project, instead of the root
repository.

Related: https://github.com/socketio/socket.io/issues/3934
2021-08-30 08:03:55 +02:00
Damien Arrachequesne
ccfd8caba6 fix(typings): allow async listener in typed events
So that:

```ts
socket.on("my-event", async () => {
  // ...
});
```

is valid under the @typescript-eslint/no-misused-promises rule.

Related: https://github.com/socketio/socket.io-client/issues/1486
2021-08-30 08:01:29 +02:00
Tim Düsterhus
24fee27ba3 feat: ignore the query string when serving client JavaScript (#4024)
Related: https://github.com/socketio/socket.io/issues/4023
2021-08-30 07:59:47 +02:00
Michael Vartan
4e1b65699d feat: add an option to use native timer functions (#1479)
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

Related: 5d1d5bea11
2021-08-29 09:31:25 +02:00
dependabot[bot]
ebb36f298d chore(deps): bump xmlhttprequest-ssl from 1.5.5 to 2.0.0 (#626)
Bumps [xmlhttprequest-ssl](https://github.com/mjwwit/node-XMLHttpRequest) from 1.5.5 to 2.0.0.
- [Release notes](https://github.com/mjwwit/node-XMLHttpRequest/releases)
- [Commits](https://github.com/mjwwit/node-XMLHttpRequest/compare/1.5.5...2.0.0)

---
updated-dependencies:
- dependency-name: xmlhttprequest-ssl
  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 09:08:48 +02:00
Damien Arrachequesne
313ca50ce8 chore(release): 5.2.0
Diff: https://github.com/socketio/engine.io/compare/5.1.1...5.2.0
2021-08-29 08:32:20 +02:00
Kamil93
b9dc43c3e1 docs: add documentation about heartbeat event (#623) 2021-08-29 08:25:06 +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
Damien Arrachequesne
78cd3bc7b9 test: remove duplicate test 2021-08-29 08:05:05 +02:00
Damien Arrachequesne
412bcc4298 chore(release): 4.0.3
Diff: https://github.com/socketio/engine.io-parser/compare/4.0.2...4.0.3
2021-08-29 07:55:13 +02:00
Damien Arrachequesne
6d7dd76130 fix: respect the offset and length of TypedArray objects
The parser now returns the TypedArray object instead of the underlying
array buffer, so its offset and length are now taken in account (which
is the behavior of the classic WebSocket implementation).

Notes:

- this was already the case for the Node.js implementation

- in v3, the TypedArray object was always converted to an array buffer
because a byte was added at the beginning ("message" type)

- we could also have used "data.slice().buffer", but it would have
resulted in the copy of the buffer

Related:

- https://github.com/socketio/engine.io-parser/issues/122
- https://github.com/socketio/engine.io-client/issues/677
2021-08-29 07:54:03 +02:00
dependabot[bot]
6dfab6970c chore: bump path-parse from 1.0.6 to 1.0.7 (#120)
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 07:53:56 +02:00