Commit Graph

7697 Commits

Author SHA1 Message Date
Damien Arrachequesne
b68f816323 chore: bump debug 2020-10-13 23:24:41 +02:00
Damien Arrachequesne
c0d171f728 test: use the reconnect event of the Manager
Following 132f8ec918
2020-10-13 23:02:09 +02:00
Damien Arrachequesne
9c7a48d866 test: use the complete export name
Following fa7d41f55d

Ref: https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_subpath_exports
2020-10-13 23:02:09 +02:00
Damien Arrachequesne
4bd5b2339a 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.
2020-10-13 23:02:09 +02:00
Damien Arrachequesne
a8c0600609 feat: remove the 'origins' option
The underlying Engine.IO server now supports a 'cors' option, which
will be forwarded to the cors module.

Breaking change: the 'origins' option is removed

Before:

```js
new Server(3000, {
  origins: ["https://example.com"]
});
```

The 'origins' option was used in the allowRequest method, in order to
determine whether the request should pass or not. And the Engine.IO
server would implicitly add the necessary Access-Control-Allow-xxx
headers.

After:

```js
new Server(3000, {
  cors: {
    origin: "https://example.com",
    methods: ["GET", "POST"],
    allowedHeaders: ["content-type"]
  }
});
```

The already existing 'allowRequest' option can be used for validation:

```js
new Server(3000, {
  allowRequest: (req, callback) => {
    callback(null, req.headers.referer.startsWith("https://example.com"));
  }
});
```
2020-10-13 23:02:08 +02:00
Damien Arrachequesne
8b6b100c28 feat: add ES6 module export
Both CommonJS and ES6 import are now supported:

- with `{ "type": "commonjs" }` in the package.json file

```js
const io = require("socket.io")(8080);
// or
const { Server } = require("socket.io");
const io = new Server(8080);
```

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

```js
import { Server } from "socket.io";

const io = new Server(8080);
```

Related: https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages
2020-10-13 23:02:08 +02:00
Damien Arrachequesne
83a2356648 refactor: properly delegate to the main namespace 2020-10-13 23:02:08 +02:00
Damien Arrachequesne
2875d2cfdf feat: do not reuse the Engine.IO id
In previous versions, the Socket#id attribute was equal (or derived,
for a non-default namespace) to the underlying Engine.IO id, which is
used as a mean to authenticate the user throughout the Engine.IO
session and thus is sensitive information that should be kept secret.

The problem with reusing the Engine.IO id is that users could be
tempted to transmit this id to other clients, in order to implement
private messaging for example.

So we'll now generate a new random id for each new socket.

Please note that this id will now be different from the one found in
the query parameters of the HTTP requests.
2020-10-13 23:02:07 +02:00
Damien Arrachequesne
3289f7ec37 feat: remove the implicit connection to the default namespace
In previous versions, a client was always connected to the default
namespace, even if it requested access to another namespace.

This meant that the middlewares registered for the default namespace
were triggered in any case, which is a surprising behavior for end
users.

This also meant that the query option of the Socket on the client-side
was not sent in the Socket.IO CONNECT packet for the default namespace:

```js
// default namespace: query sent in the query params
const socket = io({
  query: {
    abc: "def"
  }
});

// another namespace: query sent in the query params + the CONNECT packet
const socket = io("/admin", {
  query: {
    abc: "def"
  }
});
```

The client will now send a CONNECT packet in any case, and the query
option of the Socket is renamed to "auth", in order to make a clear
distinction with the query option of the Manager (included in the query
parameters of the HTTP requests).

```js
// server-side
io.use((socket, next) => {
  // not triggered anymore
});

io.of("/admin").use((socket, next => {
  // triggered
  console.log(socket.handshake.query.abc); // "def"
  console.log(socket.handshake.auth.abc); // "123"
});

// client-side
const socket = io("/admin", {
  query: {
    abc: "def"
  },
  auth: {
    abc: "123"
  }
});
```
2020-10-13 23:02:07 +02:00
Damien Arrachequesne
7a51c76413 refactor: migrate tests to TypeScript 2020-10-13 23:02:06 +02:00
Damien Arrachequesne
64bd9fb01a chore: include Engine.IO v4
Release notes: https://github.com/socketio/engine.io/releases/tag/4.0.0
2020-10-13 23:02:06 +02:00
Damien Arrachequesne
4396bd0b3d chore: point towards the develop branch of the client
The package-lock.json file is temporarily removed in order to include
the latest commits to the client and make the tests pass.
2020-10-13 23:02:06 +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
7fc3c42234 chore(release): 4.0.1-rc1
Diff: https://github.com/socketio/socket.io-parser/compare/4.0.0...4.0.1-rc1
2020-10-12 15:21:44 +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
78f9fc2999 feat: add support for a payload in a CONNECT packet 2020-10-08 02:00:09 +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
9eb8561cbc refactor: use require for debug dependency
So that the lines can be properly excluded by the webpack-remove-debug
loader ([1]).

[1] https://github.com/johngodley/webpack-remove-debug
2020-10-06 01:17:31 +02:00
Damien Arrachequesne
091d25edf1 chore: add dist 2020-10-06 01:15:30 +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
8df2120a6f docs: add a sample session with HTTP requests and WebSocket frames 2020-10-05 01:43:53 +02:00
Damien Arrachequesne
f9c0e74b14 chore: bump eiows to 3.3.2
The CI was failing with Node.js 14.13.0.
2020-10-05 01:04:17 +02:00
Alessandro Magionami
bb43ff2988 docs: add example with fastify (#3654)
See https://github.com/alemagio/fastify-socket.io
2020-10-04 23:20:05 +02:00
Damien Arrachequesne
ba55991ba0 style: minor edits 2020-10-02 12:38:18 +02:00
Damien Arrachequesne
621aeba569 docs: add a history of revisions
Backported from master.
2020-10-02 12:32:42 +02:00
Damien Arrachequesne
4b9e14a951 docs: add a history of revisions 2020-10-02 12:28:40 +02:00
Damien Arrachequesne
d389bb93e4 docs: rework of the protocol documentation 2020-10-02 12:06:26 +02:00
Damien Arrachequesne
bce66e8296 docs: rework of the protocol documentation 2020-10-02 00:11:24 +02:00
Damien Arrachequesne
27a0ab5d38 docs: restore the 'upgrades' param in the handshake
Related: 660263fae2
2020-10-01 15:18:43 +02:00
Damien Arrachequesne
2f1abed2e2 docs: clarify the session examples 2020-10-01 15:09:24 +02:00
Damien Arrachequesne
bd2ba234d9 docs: clarify the session examples 2020-10-01 14:59:37 +02:00
dependabot[bot]
45670a14f0 chore: bump js-yaml from 3.4.5 to 3.14.0 (#640)
Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 3.4.5 to 3.14.0.
- [Release notes](https://github.com/nodeca/js-yaml/releases)
- [Changelog](https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nodeca/js-yaml/compare/3.4.5...3.14.0)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-09-30 23:41:37 +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