Commit Graph

1606 Commits

Author SHA1 Message Date
Damien Arrachequesne
969debe88c refactor: rework of the Manager events
- rename "connect_error" to "error"
- remove "reconnecting" (duplicate of "reconnect_attempt")

The updated list of events emitted by the Manager:

- open:                successful (re)connection
- error:               (re)connection failure (previously: "connect_error") or error after a successful connection
- close:               disconnection

- ping:                ping packet
- packet:              data packet

- reconnect_attempt:   reconnection attempt (previously: "reconnect_attempt" & "reconnecting")
- reconnect:           successful reconnection
- reconnect_error:     reconnection failure
- reconnect_failed:    reconnection failure after all attempts

For reference, the Socket instance emits the following events:

- connect:             successful connection to a Namespace
- connect_error:       connection failure
- disconnect:          disconnection
2020-10-27 23:07:44 +01:00
Damien Arrachequesne
a9127cee83 chore(release): 3.0.0-rc3
Diff: https://github.com/socketio/socket.io-client/compare/3.0.0-rc2...3.0.0-rc3
2020-10-27 00:41:32 +01:00
Damien Arrachequesne
13e1db7c94 refactor: rename ERROR to CONNECT_ERROR
The meaning is not modified: this packet type is still used by the
server when the connection to a namespace is refused.

Breaking change: the Socket instance will now emit a "connect_error"
event instead of "error" (which is not a reserved event anymore)

```js
// before
socket.on("error", () => {});

// after
socket.on("connect_error", () => {});
```
2020-10-26 10:04:05 +01:00
Damien Arrachequesne
55f464f59e feat: add support for catch-all listeners
Inspired from EventEmitter2 [1]

The API is similar to the one on the server-side:

```js
socket.onAny((event, ...args) => {});

socket.prependAny((event, ...args) => {});

socket.offAny(); // remove all listeners

socket.offAny(listener);

const listeners = socket.listenersAny();
```

[1]: https://github.com/EventEmitter2/EventEmitter2
2020-10-26 10:03:27 +01:00
Damien Arrachequesne
71d60480af feat: add bundle with msgpack parser
Pros:

- events with binary content are sent as 1 WebSocket frame (instead of 2 with the default parser)
- payloads with lots of numbers should be smaller

Cons:

- no IE9 support (https://caniuse.com/mdn-javascript_builtins_arraybuffer)
- a slightly bigger bundle size (61.1 vs 59.9 KB)

Source: https://github.com/darrachequesne/socket.io-msgpack-parser
2020-10-25 22:47:31 +01:00
Damien Arrachequesne
f3cbe983a1 refactor: additional typings 2020-10-17 03:37:53 +02:00
Damien Arrachequesne
7ddad2c09d feat: add volatile events
A volatile packet will be dropped if:

- the socket is not connected
- the low-level transport is not ready (for example, a HTTP POST request is already pending)

Syntax:

```js
socket.volatile.emit("volatile event", "might or might not be sent");
```
2020-10-17 03:37:29 +02:00
Damien Arrachequesne
b600e78f71 chore(release): 3.0.0-rc2
Diff: https://github.com/socketio/socket.io-client/compare/3.0.0-rc1...3.0.0-rc2
2020-10-15 13:00:43 +02:00
Damien Arrachequesne
178909471a feat: move binary detection back to the parser
See 285e7cd0d8

Breaking change: the Socket#binary() method is removed, as this use
case is now covered by the ability to provide your own parser.
2020-10-15 10:37:06 +02:00
Damien Arrachequesne
c7998d5446 refactor: add Manager and Socket typings 2020-10-14 22:59:58 +02:00
Damien Arrachequesne
2c7c230153 chore: publish the wrapper.mjs file 2020-10-14 01:51:30 +02:00
Damien Arrachequesne
a66473f93a chore: use socketio GitHub organization 2020-10-14 01:49:06 +02:00
Damien Arrachequesne
946a9f008c chore: fix test script 2020-10-14 00:00:02 +02:00
Damien Arrachequesne
a838ff1fc8 chore(release): 3.0.0-rc1
Diff: https://github.com/socketio/socket.io-client/compare/2.3.1...3.0.0-rc1
2020-10-13 23:35:22 +02:00
Damien Arrachequesne
b68f816323 chore: bump debug 2020-10-13 23:24:41 +02:00
Damien Arrachequesne
cbabb0308e feat: add ES6 module export
- with `{ "type": "commonjs" }` in the package.json file

```js
const io = require("socket.io-client");

const socket = io("/");
```

- with `{ "type": "module" }`

```js
import io from "socket.io-client";

const socket = io("/");

// or
import { Manager } from "socket.io-client";

const manager = new Manager();
const socket = manager.socket("/");
```

Related: https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages
2020-10-13 22:53:53 +02:00
Damien Arrachequesne
e826992c8e refactor: remove the 'connect_timeout' event
The 'connect_timeout' event is now merged with the 'connect_error'
event, and will now emit an Error object instead of a plain string.
2020-10-12 15:03:09 +02:00
Damien Arrachequesne
b60e909039 refactor: remove the 'connecting' event
This event was added in 41956806a7

But it does not convey the information that the Socket is actually
sending a CONNECT packet to the server. It should maybe be moved to the
Socket#onopen() method, but let's remove it for now as it is not
documented anywhere.
2020-10-12 15:03:09 +02:00
Damien Arrachequesne
6494f61be0 feat: throw upon reserved event names
These events cannot be used by the end users, because they are part of
the Socket.IO public API, so using them will now throw an error
explicitly.

Related: f7ed81e5d2
2020-10-12 15:03:09 +02:00
Damien Arrachequesne
132f8ec918 feat: split the events of the Manager and Socket
Previously, most of the events emitted by the Manager were also emitted
by the Socket instances, but it was somehow misleading for the end
users because they don't have the same meaning:

- Manager: the state of the low-level connection (with connection and reconnection events)
- Socket: the state of the connection to the Namespace (only 'connect', 'disconnect' and 'error')

For example, the `reconnect` event:

```js
socket.on("reconnect", () => {
  console.log(socket.connected); // might be false, which is a bit surprising
});
```

Breaking change: the Socket instance will no longer forward the events
of its Manager

Those events can still be accessed on the Manager instance though:

```js
socket.io.on("reconnect", () => {
  // ...
});
```
2020-10-12 15:03:09 +02:00
Damien Arrachequesne
6cd2e4eab0 refactor: remove the packetBuffer array
The parser#encode() method is now synchronous, so the packetBuffer
array is useless.
2020-10-12 11:41:55 +02:00
Damien Arrachequesne
c07b91db96 chore: restore the source-map generation 2020-10-12 11:16:26 +02:00
Damien Arrachequesne
bbe94adb82 feat: do not reuse the Engine.IO id
Related: 3b0cb1158c
2020-10-08 03:04:49 +02:00
Damien Arrachequesne
249e0bef90 feat: remove the implicit connection to the default namespace
Related: 09b6f23339
2020-10-08 02:04:03 +02:00
Damien Arrachequesne
be8c3141bd chore: include Engine.IO client v4
The ping-pong mechanism has been reverted (server now sends a ping and
expects a pong from the client), so we cannot compute the latency like
we did in previous versions.

Release notes: https://github.com/socketio/engine.io-client/releases/tag/4.0.0
2020-10-06 22:50:52 +02:00
Damien Arrachequesne
f2f4a4c7c7 chore: point towards the develop branch of the server
The package-lock.json file is temporarily removed in order to include
the latest commits to the server and make the tests pass.
2020-10-06 22:41:17 +02:00
Damien Arrachequesne
429846b0a1 chore: bump socket.io-parser
Breaking change:

- the encode() method is now synchronous

Please note that the exchange [protocol][1] is left untouched and thus
stays in version 4.

Diff: https://github.com/socketio/socket.io-parser/compare/3.4.1...4.0.0

[1] https://github.com/socketio/socket.io-protocol
2020-10-06 01:20:12 +02:00
Damien Arrachequesne
cab895f477 refactor: use prettier to format tests 2020-10-06 00:21:14 +02:00
Damien Arrachequesne
697bea2d81 refactor: migrate to TypeScript 2020-10-06 00:21:14 +02:00
Damien Arrachequesne
003cb38cae test: add Node.js 12 and 14 in the build matrix
Node.js 8 is removed, as it is now EOL.
2020-10-06 00:20:25 +02:00
Damien Arrachequesne
3c11eb9d2e refactor: remove gulp from the build
Plain npm scripts should be sufficient for our use case.
2020-10-05 15:48:22 +02:00
Damien Arrachequesne
f08b933800 docs: remove reference to JSON3
The `json3` dependency, previously used for compatibility with IE6/7,
was removed in [1] and included in `socket.io-parser@3.0.0` and
`socket.io-client@2.0.0` ([2]).

The slim build now only removes the debug dependency (~3KB min+gzip).

[1] e39f5a8c6a (diff-b9cfc7f2cdf78a7f4b91a753d10865a2)
[2] ff4cb3eed0 (diff-b9cfc7f2cdf78a7f4b91a753d10865a2R28)
2020-10-05 11:08:15 +02:00
Damien Arrachequesne
4631ed6ab3 chore(release): 2.3.1
Diff: https://github.com/socketio/socket.io-client/compare/2.3.0...2.3.1
2020-09-30 18:32:33 +02:00
Damien Arrachequesne
7f73a289f5 test: fix tests in IE 2020-09-30 17:42:32 +02:00
Damien Arrachequesne
67c54b8344 chore: bump engine.io-parser and socket.io-parser
Diff:

- https://github.com/socketio/engine.io-parser/compare/2.2.0...2.2.1
- https://github.com/socketio/socket.io-parser/compare/3.3.0...3.3.1

Related:

- https://github.com/socketio/socket.io-client/pull/1376
- https://github.com/socketio/socket.io-client/issues/1234
2020-09-30 16:14:19 +02:00
Damien Arrachequesne
15a52ab721 test: remove arrow function (for now)
It was included by the previous commit, but the test code is not
currently transpiled to ES5 so it breaks IE in the CI.

Let's use a plain function for now.
2020-09-30 16:11:54 +02:00
Luke Olney
050108b228 fix: fix reconnection after opening socket asynchronously (#1253)
Closes https://github.com/socketio/socket.io/issues/3358
2020-09-30 16:01:15 +02:00
Damien Arrachequesne
b570025a79 chore: bump engine.io-client and downgrade debug
The newer versions need to be transpiled to ES5, so we'll rollback for
now as it breaks IE11.

We'll have to find a way to provide the users who bundle the Engine.IO
(or Socket.IO) client (with webpack for example) with a source code
which does not include debug (or document the usage of
webpack-remove-debug [1]).

[1] https://github.com/johngodley/webpack-remove-debug
2020-09-30 02:26:29 +02:00
Damien Arrachequesne
1fb1b78020 chore: remove unused dependencies
- base64-arraybuffer => dev
- has-cors => dev
- object-component => removed
2020-09-30 02:24:16 +02:00
devmi
0c39f145fa docs: add section about Debug / logging on the client side (#1278) 2020-09-30 02:09:10 +02:00
Mithilesh Pradhan
6ce02ee3b0 docs: add server port in the example (#1359) 2020-09-30 01:52:26 +02:00
Damien Arrachequesne
f4a4d89f15 chore: update package-lock.json file
Following previous commit, the lock file was not up-to-date.
2020-09-30 00:20:59 +02:00
rookieKing
3c1d860420 chore: bump component-emitter dependency (#1376)
Subscribing/unsubscribing for a lot of different event types could lead
to a memory leak.

See aa2e57acc7

Diff: https://github.com/component/emitter/compare/1.2.1...1.3.0
2020-09-30 00:13:12 +02:00
Damien Arrachequesne
b7dbbd28c8 test: fix race condition in the tests
Even with a timeout of 0, the 'open' event was emitted before the
timeout was reached, so the tests would randomly fail in the CI.
2020-09-30 00:07:29 +02:00
Damien Arrachequesne
661f1e7fac [chore] Release 2.3.0
Diff: https://github.com/socketio/socket.io-client/compare/2.2.0...2.3.0
2019-09-20 12:22:41 +02:00
Damien Arrachequesne
71d7b79965 [chore] Bump engine.io-client to version 3.4.0
Also includes the bump of the debug dependency.

Diff: https://github.com/socketio/engine.io-client/compare/3.3.1...3.4.0
2019-09-20 12:02:21 +02:00
Lukas Drgon
8b4a539e7a [docs] Add CDN link (#1318) 2019-09-20 12:01:51 +02:00
Damien Arrachequesne
40cf185574 [ci] use Node.js 10 for compatibility with Gulp v3
It seems Node.js 12 (which is now 'latest') does not work with Gulp v3. In the future, we will
either have to migrate to Gulp v4, or remove Gulp from the build system.
2019-09-20 11:25:13 +02:00
Damien Arrachequesne
3020e455ab [chore] Release 2.2.0 2018-11-29 00:15:03 +01:00
Damien Arrachequesne
06e9a4ca26 [chore] Bump dependencies
- engine.io-client: https://github.com/socketio/engine.io-client/compare/3.2.0...3.3.1
- socket.io-parser: https://github.com/socketio/socket.io-parser/compare/3.2.0..3.3.0
2018-11-28 22:51:53 +01:00