Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: socketio/socket.io
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.4.1
Choose a base ref
...
head repository: socketio/socket.io
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.0.0
Choose a head ref
Loading
Showing with 37,264 additions and 5,164 deletions.
  1. +2 −2 .gitignore
  2. +2 −4 .travis.yml
  3. +262 −0 CHANGELOG.md
  4. +17 −2 Readme.md
  5. +6,161 −0 client-dist/socket.io.js
  6. +1 −0 client-dist/socket.io.js.map
  7. +7 −0 client-dist/socket.io.min.js
  8. +1 −0 client-dist/socket.io.min.js.map
  9. +7 −0 client-dist/socket.io.msgpack.min.js
  10. +1 −0 client-dist/socket.io.msgpack.min.js.map
  11. +0 −880 docs/API.md
  12. +1 −14 docs/README.md
  13. +0 −64 docs/emit.md
  14. +1 −4 examples/chat/README.md
  15. +1 −1 examples/chat/index.js
  16. +706 −0 examples/chat/package-lock.json
  17. +2 −1 examples/chat/package.json
  18. +23 −0 examples/create-react-app-example/.gitignore
  19. +72 −0 examples/create-react-app-example/README.md
  20. +37 −0 examples/create-react-app-example/package.json
  21. BIN examples/create-react-app-example/public/favicon.ico
  22. +43 −0 examples/create-react-app-example/public/index.html
  23. BIN examples/create-react-app-example/public/logo192.png
  24. BIN examples/create-react-app-example/public/logo512.png
  25. +25 −0 examples/create-react-app-example/public/manifest.json
  26. +3 −0 examples/create-react-app-example/public/robots.txt
  27. +19 −0 examples/create-react-app-example/server.js
  28. +38 −0 examples/create-react-app-example/src/App.css
  29. +43 −0 examples/create-react-app-example/src/App.js
  30. +9 −0 examples/create-react-app-example/src/App.test.js
  31. +13 −0 examples/create-react-app-example/src/index.css
  32. +17 −0 examples/create-react-app-example/src/index.js
  33. +7 −0 examples/create-react-app-example/src/logo.svg
  34. +141 −0 examples/create-react-app-example/src/serviceWorker.js
  35. +5 −0 examples/create-react-app-example/src/setupTests.js
  36. +11,106 −0 examples/create-react-app-example/yarn.lock
  37. +17 −0 examples/es-modules/README.md
  38. +18 −0 examples/es-modules/client.js
  39. +238 −0 examples/es-modules/package-lock.json
  40. +15 −0 examples/es-modules/package.json
  41. +16 −0 examples/es-modules/server.js
  42. +14 −0 examples/passport-example/README.md
  43. BIN examples/passport-example/assets/passport_example.gif
  44. +31 −0 examples/passport-example/index.html
  45. +104 −0 examples/passport-example/index.js
  46. +24 −0 examples/passport-example/login.html
  47. +783 −0 examples/passport-example/package-lock.json
  48. +16 −0 examples/passport-example/package.json
  49. +4 −0 examples/react-native/.expo-shared/assets.json
  50. +14 −0 examples/react-native/.gitignore
  51. +71 −0 examples/react-native/App.js
  52. +16 −0 examples/react-native/README.md
  53. +28 −0 examples/react-native/app.json
  54. BIN examples/react-native/assets/icon.png
  55. BIN examples/react-native/assets/react-native-demo.gif
  56. BIN examples/react-native/assets/react-native.png
  57. BIN examples/react-native/assets/splash.png
  58. +6 −0 examples/react-native/babel.config.js
  59. +6,775 −0 examples/react-native/package-lock.json
  60. +24 −0 examples/react-native/package.json
  61. +15 −0 examples/react-native/server.js
  62. +30 −0 examples/tweet-stream/index.js
  63. +705 −0 examples/tweet-stream/package-lock.json
  64. +20 −0 examples/tweet-stream/package.json
  65. +19 −0 examples/typescript/client.ts
  66. +268 −0 examples/typescript/package-lock.json
  67. +17 −0 examples/typescript/package.json
  68. +16 −0 examples/typescript/server.ts
  69. +4,137 −0 examples/webpack-build-server/package-lock.json
  70. +3 −2 examples/webpack-build-server/package.json
  71. +1 −1 examples/whiteboard/README.md
  72. +706 −0 examples/whiteboard/package-lock.json
  73. +2 −2 examples/whiteboard/package.json
  74. +0 −273 lib/client.js
  75. +278 −0 lib/client.ts
  76. +0 −523 lib/index.js
  77. +715 −0 lib/index.ts
  78. +0 −299 lib/namespace.js
  79. +291 −0 lib/namespace.ts
  80. +0 −39 lib/parent-namespace.js
  81. +40 −0 lib/parent-namespace.ts
  82. +0 −572 lib/socket.js
  83. +595 −0 lib/socket.ts
  84. +36 −11 package.json
  85. +0 −11 test/fixtures/server-close.js
  86. +11 −0 test/fixtures/server-close.ts
  87. +0 −2,459 test/socket.io.js
  88. +2,334 −0 test/socket.io.ts
  89. +22 −0 test/support/util.ts
  90. +13 −0 tsconfig.json
  91. +3 −0 wrapper.mjs
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -10,5 +10,5 @@ benchmarks/*.png
node_modules
coverage
.idea
dist
.nyc_output
.nyc_output
dist/
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: node_js
sudo: false
node_js:
- '8'
- '10'
- '12'
- '14'
notifications:
irc: "irc.freenode.org#socket.io"
git:
depth: 1
cache:
directories:
- node_modules
262 changes: 262 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
# [3.0.0](https://github.com/socketio/socket.io/compare/2.3.0...3.0.0) (2020-11-05)

### Bug Fixes

* close clients with no namespace ([91cd255](https://github.com/socketio/socket.io/commit/91cd255ba76ff6a780c62740f9f5cd3a76f5d7c7))

### Features

* emit an Error object upon middleware error ([54bf4a4](https://github.com/socketio/socket.io/commit/54bf4a44e9e896dfb64764ee7bd4e8823eb7dc7b))
* serve msgpack bundle ([aa7574f](https://github.com/socketio/socket.io/commit/aa7574f88471aa30ae472a5cddf1000a8baa70fd))
* add support for catch-all listeners ([5c73733](https://github.com/socketio/socket.io/commit/5c737339858d59eab4b5ee2dd6feff0e82c4fe5a))
* make Socket#join() and Socket#leave() synchronous ([129c641](https://github.com/socketio/socket.io/commit/129c6417bd818bc8b4e1b831644323876e627c13))
* remove prod dependency to socket.io-client ([7603da7](https://github.com/socketio/socket.io/commit/7603da71a535481e3fc60e38b013abf78516d322))
* move binary detection back to the parser ([669592d](https://github.com/socketio/socket.io/commit/669592d120409a5cf00f128070dee6d22259ba4f))
* add ES6 module export ([8b6b100](https://github.com/socketio/socket.io/commit/8b6b100c284ccce7d85e55659e3397f533916847))
* do not reuse the Engine.IO id ([2875d2c](https://github.com/socketio/socket.io/commit/2875d2cfdfa463e64cb520099749f543bbc4eb15))
* remove Server#set() method ([029f478](https://github.com/socketio/socket.io/commit/029f478992f59b1eb5226453db46363a570eea46))
* remove Socket#rooms object ([1507b41](https://github.com/socketio/socket.io/commit/1507b416d584381554d1ed23c9aaf3b650540071))
* remove the 'origins' option ([a8c0600](https://github.com/socketio/socket.io/commit/a8c06006098b512ba1b8b8df82777349db486f41))
* remove the implicit connection to the default namespace ([3289f7e](https://github.com/socketio/socket.io/commit/3289f7ec376e9ec88c2f90e2735c8ca8d01c0e97))
* throw upon reserved event names ([4bd5b23](https://github.com/socketio/socket.io/commit/4bd5b2339a66a5a675e20f689fff2e70ff12d236))

### BREAKING CHANGES

* the Socket#use() method is removed (see [5c73733](https://github.com/socketio/socket.io/commit/5c737339858d59eab4b5ee2dd6feff0e82c4fe5a))

* Socket#join() and Socket#leave() do not accept a callback argument anymore.

Before:

```js
socket.join("room1", () => {
io.to("room1").emit("hello");
});
```

After:

```js
socket.join("room1");
io.to("room1").emit("hello");
// or await socket.join("room1"); for custom adapters
```

* the "connected" map is renamed to "sockets"
* the Socket#binary() method is removed, as this use case is now covered by the ability to provide your own parser.
* 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"));
}
});
```

* Socket#rooms is now a Set instead of an object

* Namespace#connected is now a Map instead of an object

* there is no more implicit connection to the default namespace:

```js
// client-side
const socket = io("/admin");

// server-side
io.on("connect", socket => {
// not triggered anymore
})

io.use((socket, next) => {
// not triggered anymore
});

io.of("/admin").use((socket, next) => {
// triggered
});
```

* the Server#set() method was removed

This method was kept for backward-compatibility with pre-1.0 versions.


# [3.0.0-rc4](https://github.com/socketio/socket.io/compare/3.0.0-rc3...3.0.0-rc4) (2020-10-30)


### Features

* emit an Error object upon middleware error ([54bf4a4](https://github.com/socketio/socket.io/commit/54bf4a44e9e896dfb64764ee7bd4e8823eb7dc7b))
* serve msgpack bundle ([aa7574f](https://github.com/socketio/socket.io/commit/aa7574f88471aa30ae472a5cddf1000a8baa70fd))



# [3.0.0-rc3](https://github.com/socketio/socket.io/compare/3.0.0-rc2...3.0.0-rc3) (2020-10-26)


### Features

* add support for catch-all listeners ([5c73733](https://github.com/socketio/socket.io/commit/5c737339858d59eab4b5ee2dd6feff0e82c4fe5a))
* make Socket#join() and Socket#leave() synchronous ([129c641](https://github.com/socketio/socket.io/commit/129c6417bd818bc8b4e1b831644323876e627c13))
* remove prod dependency to socket.io-client ([7603da7](https://github.com/socketio/socket.io/commit/7603da71a535481e3fc60e38b013abf78516d322))


### BREAKING CHANGES

* the Socket#use() method is removed (see [5c73733](https://github.com/socketio/socket.io/commit/5c737339858d59eab4b5ee2dd6feff0e82c4fe5a))

* Socket#join() and Socket#leave() do not accept a callback argument anymore.

Before:

```js
socket.join("room1", () => {
io.to("room1").emit("hello");
});
```

After:

```js
socket.join("room1");
io.to("room1").emit("hello");
// or await socket.join("room1"); for custom adapters
```



# [3.0.0-rc2](https://github.com/socketio/socket.io/compare/3.0.0-rc1...3.0.0-rc2) (2020-10-15)


### Bug Fixes

* close clients with no namespace ([91cd255](https://github.com/socketio/socket.io/commit/91cd255ba76ff6a780c62740f9f5cd3a76f5d7c7))


### Code Refactoring

* remove duplicate _sockets map ([8a5db7f](https://github.com/socketio/socket.io/commit/8a5db7fa36a075da75cde43cd4fb6382b7659953))


### Features

* move binary detection back to the parser ([669592d](https://github.com/socketio/socket.io/commit/669592d120409a5cf00f128070dee6d22259ba4f))


### BREAKING CHANGES

* the "connected" map is renamed to "sockets"
* the Socket#binary() method is removed, as this use case is now covered by the ability to provide your own parser.



# [3.0.0-rc1](https://github.com/socketio/socket.io/compare/2.3.0...3.0.0-rc1) (2020-10-13)


### Features

* add ES6 module export ([8b6b100](https://github.com/socketio/socket.io/commit/8b6b100c284ccce7d85e55659e3397f533916847))
* do not reuse the Engine.IO id ([2875d2c](https://github.com/socketio/socket.io/commit/2875d2cfdfa463e64cb520099749f543bbc4eb15))
* remove Server#set() method ([029f478](https://github.com/socketio/socket.io/commit/029f478992f59b1eb5226453db46363a570eea46))
* remove Socket#rooms object ([1507b41](https://github.com/socketio/socket.io/commit/1507b416d584381554d1ed23c9aaf3b650540071))
* remove the 'origins' option ([a8c0600](https://github.com/socketio/socket.io/commit/a8c06006098b512ba1b8b8df82777349db486f41))
* remove the implicit connection to the default namespace ([3289f7e](https://github.com/socketio/socket.io/commit/3289f7ec376e9ec88c2f90e2735c8ca8d01c0e97))
* throw upon reserved event names ([4bd5b23](https://github.com/socketio/socket.io/commit/4bd5b2339a66a5a675e20f689fff2e70ff12d236))


### BREAKING CHANGES

* 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"));
}
});
```

* Socket#rooms is now a Set instead of an object

* Namespace#connected is now a Map instead of an object

* there is no more implicit connection to the default namespace:

```js
// client-side
const socket = io("/admin");

// server-side
io.on("connect", socket => {
// not triggered anymore
})

io.use((socket, next) => {
// not triggered anymore
});

io.of("/admin").use((socket, next) => {
// triggered
});
```

* the Server#set() method was removed

This method was kept for backward-compatibility with pre-1.0 versions.

19 changes: 17 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ io.on('connection', socket => {

#### Cross-browser

Browser support is tested in Saucelabs:
Browser support is tested in Sauce Labs:

[![Sauce Test Status](https://saucelabs.com/browser-matrix/socket.svg)](https://saucelabs.com/u/socket)

@@ -138,9 +138,24 @@ io.on('connection', () => { /* … */ });
server.listen(3000);
```

### In conjunction with Fastify

To integrate Socket.io in your Fastify application you just need to
register `fastify-socket.io` plugin. It will create a `decorator`
called `io`.

```js
const app = require('fastify')();
app.register(require('fastify-socket.io'));
app.io.on('connection', () => { /**/ });
app.listen(3000);
```

## Documentation

Please see the documentation [here](/docs/README.md). Contributions are welcome!
Please see the documentation [here](https://socket.io/docs/).

The source code of the website can be found [here](https://github.com/socketio/socket.io-website). Contributions are welcome!

## Debug / logging

Loading