diff --git a/.eslintrc.json b/.eslintrc.json index 6d3c020b6..082c0cb59 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,4 @@ { - "extends": "standard", - "parser": "babel-eslint", - "rules": { - "yoda": 0, - "semi": [2, "always"], - "no-extra-semi": 2, - "semi-spacing": [2, { "before": false, "after": true }] - } + "extends": "prettier", + "parser": "babel-eslint" } diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 196c48004..000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,25 +0,0 @@ - -*Note*: for support questions, please use one of these channels: [stackoverflow](http://stackoverflow.com/questions/tagged/engine.io) or [slack](https://socketio.slack.com) - -### You want to: - -* [x] report a *bug* -* [ ] request a *feature* - -### Current behaviour - - -### Steps to reproduce (if the current behaviour is a bug) - - -### Expected behaviour - - -### Setup -- OS: -- browser: -- engine.io version: - -### Other information (e.g. stacktraces, related issues, suggestions how to fix) - - diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..7deb7968f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,66 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: 'bug' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** + +Please fill the following code example: + +Engine.IO server version: `x.y.z` + +*Server* + +```js +const engine = require("engine.io"); +const server = engine.listen(3000, {}); + +server.on("connection", (socket) => { + console.log("connection"); + + socket.on("message", (data) => { + console.log("data", data); + }); + + socket.on("close", () => { + console.log("close"); + }); +}); +``` + +Engine.IO client version: `x.y.z` + +*Client* + +```js +const socket = require("engine.io-client")("ws://localhost:3000"); + +socket.on("open", () => { + console.log("open"); + + socket.on("message", (data) => { + console.log("data", data); + }); + + socket.on("close", () => { + console.log("close"); + }); +}); +``` + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Platform:** + - Device: [e.g. Samsung S8] + - OS: [e.g. Android 9.2] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000..fe32cb299 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: Ask a Question + url: https://github.com/socketio/socket.io/discussions/new?category=q-a + about: Ask the community for help diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..36014cde5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: 'enhancement' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..62ebbbf17 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI + +on: + push: + pull_request: + schedule: + - cron: '0 0 * * 0' + +permissions: + contents: read + +jobs: + test-node: + runs-on: ubuntu-latest + timeout-minutes: 10 + + strategy: + matrix: + node-version: + - 10 + - 18 + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test + + - name: Run tests with µWebSockets.js + run: npm run test:uws + if: ${{ matrix.node-version == '18' }} diff --git a/.gitignore b/.gitignore index cb265cefb..fef838544 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ node_modules npm-debug.log -coverage.html -lib-cov/ -dist +build/ diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..935d77928 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +lib/parser-v3/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d1110b8b3..000000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -sudo: false -language: node_js -node_js: - - "0.10" - - "0.12" - - "4" - - "6" - - "7" -git: - depth: 1 -env: - - CXX=g++-4.8 -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-4.8 - -notifications: - irc: "irc.freenode.org#socket.io" diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..3ec49ec4b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,475 @@ +# History + +## 2022 + +- [6.2.1](#621-2022-11-20) (Nov 2022) +- [3.6.0](#360-2022-06-06) (Jun 2022) (from the [3.x](https://github.com/socketio/engine.io/tree/3.x) branch) +- [6.2.0](#620-2022-04-17) (Apr 2022) +- [6.1.3](#613-2022-02-23) (Feb 2022) +- [6.1.2](#612-2022-01-18) (Jan 2022) +- [6.1.1](#611-2022-01-11) (Jan 2022) + +## 2021 + +- [6.1.0](#610-2021-11-08) (Nov 2021) +- [6.0.1](#601-2021-11-06) (Nov 2021) +- [**6.0.0**](#600-2021-10-08) (Oct 2021) +- [5.2.0](#520-2021-08-29) (Aug 2021) +- [5.1.1](#511-2021-05-16) (May 2021) +- [5.1.0](#510-2021-05-04) (May 2021) +- [**5.0.0**](#500-2021-03-10) (Mar 2021) +- [4.1.1](#411-2021-02-02) (Feb 2021) +- [4.1.0](#410-2021-01-14) (Jan 2021) +- [4.0.6](#406-2021-01-04) (Jan 2021) + +## 2020 + +- [3.5.0](#350-2020-12-30) (Dec 2020) (from the [3.x](https://github.com/socketio/engine.io/tree/3.x) branch) +- [4.0.5](#405-2020-12-07) (Dec 2020) +- [4.0.4](#404-2020-11-17) (Nov 2020) +- [4.0.3](#403-2020-11-17) (Nov 2020) +- [4.0.2](#402-2020-11-09) (Nov 2020) +- [4.0.1](#401-2020-10-21) (Oct 2020) +- [**4.0.0**](#400-2020-09-10) (Sep 2020) +- [3.4.2](#342-2020-06-04) (Jun 2020) +- [3.4.1](#341-2020-04-17) (Apr 2020) + + + +# Release notes + +## [6.2.1](https://github.com/socketio/engine.io/compare/6.2.0...6.2.1) (2022-11-20) + +:warning: This release contains an important security fix :warning: + +A malicious client could send a specially crafted HTTP request, triggering an uncaught exception and killing the Node.js process: + +``` +Error: read ECONNRESET + at TCP.onStreamRead (internal/stream_base_commons.js:209:20) +Emitted 'error' event on Socket instance at: + at emitErrorNT (internal/streams/destroy.js:106:8) + at emitErrorCloseNT (internal/streams/destroy.js:74:3) + at processTicksAndRejections (internal/process/task_queues.js:80:21) { + errno: -104, + code: 'ECONNRESET', + syscall: 'read' +} +``` + +Please upgrade as soon as possible. + +### Bug Fixes + +* catch errors when destroying invalid upgrades ([#658](https://github.com/socketio/engine.io/issues/658)) ([425e833](https://github.com/socketio/engine.io/commit/425e833ab13373edf1dd5a0706f07100db14e3c6)) + + + +# [3.6.0](https://github.com/socketio/engine.io/compare/3.5.0...3.6.0) (2022-06-06) + + +### Bug Fixes + +* add extension in the package.json main entry ([#608](https://github.com/socketio/engine.io/issues/608)) ([3ad0567](https://github.com/socketio/engine.io/commit/3ad0567dbd57cfb7c2ff4e8b7488d80f37022b4a)) +* do not reset the ping timer after upgrade ([1f5d469](https://github.com/socketio/engine.io/commit/1f5d4699862afee1e410fcb0e1f5e751ebcd2f9f)), closes [/github.com/socketio/socket.io-client-swift/pull/1309#issuecomment-768475704](https://github.com//github.com/socketio/socket.io-client-swift/pull/1309/issues/issuecomment-768475704) + + +### Features + +* decrease the default value of maxHttpBufferSize ([58e274c](https://github.com/socketio/engine.io/commit/58e274c437e9cbcf69fd913c813aad8fbd253703)) + +This change reduces the default value from 100 mb to a more sane 1 mb. + +This helps protect the server against denial of service attacks by malicious clients sending huge amounts of data. + +See also: https://github.com/advisories/GHSA-j4f2-536g-r55m + +* increase the default value of pingTimeout ([f55a79a](https://github.com/socketio/engine.io/commit/f55a79a28a5fbc6c9edae876dd11308b89cc979e)) + + + +# [6.2.0](https://github.com/socketio/engine.io/compare/6.1.3...6.2.0) (2022-04-17) + + +### Features + +* add the "maxPayload" field in the handshake details ([088dcb4](https://github.com/socketio/engine.io/commit/088dcb4dff60df39785df13d0a33d3ceaa1dff38)) + +So that clients in HTTP long-polling can decide how many packets they have to send to stay under the maxHttpBufferSize +value. + +This is a backward compatible change which should not mandate a new major revision of the protocol (we stay in v4), as +we only add a field in the JSON-encoded handshake data: + +``` +0{"sid":"lv_VI97HAXpY6yYWAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000,"maxPayload":1000000} +``` + + + +## [6.1.3](https://github.com/socketio/engine.io/compare/6.1.2...6.1.3) (2022-02-23) + + +### Bug Fixes + +* **typings:** allow CorsOptionsDelegate as cors options ([#641](https://github.com/socketio/engine.io/issues/641)) ([a463d26](https://github.com/socketio/engine.io/commit/a463d268ed90064e7863679bda423951de108c36)) +* **uws:** properly handle chunked content ([#642](https://github.com/socketio/engine.io/issues/642)) ([3367440](https://github.com/socketio/engine.io/commit/33674403084c329dc6ad026c4122333a6f8a9992)) + + + +## [6.1.2](https://github.com/socketio/engine.io/compare/6.1.1...6.1.2) (2022-01-18) + + +### Bug Fixes + +* **uws:** expose additional uWebSockets.js options ([#634](https://github.com/socketio/engine.io/issues/634)) ([49bb7cf](https://github.com/socketio/engine.io/commit/49bb7cf66518d4b49baf883a16ee1fe1ed8aed28)) +* **uws:** fix HTTP long-polling with CORS ([45112a3](https://github.com/socketio/engine.io/commit/45112a30d1af4cc25b21a5d658a748583cb64ed4)) +* **uws:** handle invalid websocket upgrades ([8b4d6a8](https://github.com/socketio/engine.io/commit/8b4d6a8176db72f5c2420c5a45f0d97d33af049b)) + + + +## [6.1.1](https://github.com/socketio/engine.io/compare/6.1.0...6.1.1) (2022-01-11) + +:warning: This release contains an important security fix :warning: + +A malicious client could send a specially crafted HTTP request, triggering an uncaught exception and killing the Node.js process: + +> RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear +> at Receiver.getInfo (/.../node_modules/ws/lib/receiver.js:176:14) +> at Receiver.startLoop (/.../node_modules/ws/lib/receiver.js:136:22) +> at Receiver._write (/.../node_modules/ws/lib/receiver.js:83:10) +> at writeOrBuffer (internal/streams/writable.js:358:12) + +This bug was introduced by [this commit](https://github.com/socketio/engine.io/commit/f3c291fa613a9d50c924d74293035737fdace4f2), included in `engine.io@4.0.0`, so previous releases are not impacted. + +Thanks to Marcus Wejderot from Mevisio for the responsible disclosure. + +### Bug Fixes + +* properly handle invalid data sent by a malicious websocket client ([c0e194d](https://github.com/socketio/engine.io/commit/c0e194d44933bd83bf9a4b126fca68ba7bf5098c)) + + + +# [6.1.0](https://github.com/socketio/engine.io/compare/6.0.0...6.1.0) (2021-11-08) + + +### Bug Fixes + +* fix payload encoding for v3 clients ([ed50fc3](https://github.com/socketio/engine.io/commit/ed50fc346b9c58459bf4e6fe5c45e8d34faac8da)) + + +### Features + +* add an implementation based on uWebSockets.js ([271e2df](https://github.com/socketio/engine.io/commit/271e2df94d39bbd13c33cab98cdd5915f9d28536)) + + +### Performance Improvements + +* refresh ping timer ([#628](https://github.com/socketio/engine.io/issues/628)) ([37474c7](https://github.com/socketio/engine.io/commit/37474c7e67be7c5f25f9ca2d4ea99f3a256bd2de)) + + + +## [6.0.1](https://github.com/socketio/engine.io/compare/6.0.0...6.0.1) (2021-11-06) + + +### Bug Fixes + +* fix payload encoding for v3 clients ([3f42262](https://github.com/socketio/engine.io/commit/3f42262fd27a77a7383cdbb44ede7c6211a9782b)) + + + +# [6.0.0](https://github.com/socketio/engine.io/compare/5.2.0...6.0.0) (2021-10-08) + +The codebase was migrated to TypeScript ([c0d6eaa](https://github.com/socketio/engine.io/commit/c0d6eaa1ba1291946dc8425d5f533d5f721862dd)) + +An ES module wrapper was also added ([401f4b6](https://github.com/socketio/engine.io/commit/401f4b60693fb6702c942692ce42e5bb701d81d7)). + +Please note that the communication protocol was not updated, so a v5 client will be able to reach a v6 server (and vice-versa). + +Reference: https://github.com/socketio/engine.io-protocol + +### BREAKING CHANGES + +- the default export was removed, so the following code won't work anymore: + +```js +const eioServer = require("engine.io")(httpServer); +``` + +Please use this instead: + +```js +const { Server } = require("engine.io"); +const eioServer = new Server(httpServer); +``` + +### Dependencies + +`ws` version: `~8.2.3` (bumped from `~7.4.2`) + +# [5.2.0](https://github.com/socketio/engine.io/compare/5.1.1...5.2.0) (2021-08-29) + +No change on the server-side, this matches the client release. + + +## [5.1.1](https://github.com/socketio/engine.io/compare/5.1.0...5.1.1) (2021-05-16) + + +### Bug Fixes + +* properly close the websocket connection upon handshake error ([4360686](https://github.com/socketio/engine.io/commit/43606865e5299747cbb31f3ed9baf4567502a879)) + + +# [5.1.0](https://github.com/socketio/engine.io/compare/5.0.0...5.1.0) (2021-05-04) + + +### Features + +* add a "connection_error" event ([7096e98](https://github.com/socketio/engine.io/commit/7096e98a02295a62c8ea2aa56461d4875887092d)) +* add the "initial_headers" and "headers" events ([2527543](https://github.com/socketio/engine.io/commit/252754353a0e88eb036ebb3082e9d6a9a5f497db)) + + +### Performance Improvements + +* **websocket:** add a "wsPreEncoded" writing option ([7706b12](https://github.com/socketio/engine.io/commit/7706b123df914777d19c8179b45ab6932f82916c)) +* **websocket:** fix write back-pressure ([#618](https://github.com/socketio/engine.io/issues/618)) ([ad5306a](https://github.com/socketio/engine.io/commit/ad5306aeaedf06ac7a49f791e1b76e55c35a564e)) + + +# [5.0.0](https://github.com/socketio/engine.io/compare/4.1.1...5.0.0) (2021-03-10) + + +### Bug Fixes + +* set default protocol version to 3 ([#616](https://github.com/socketio/engine.io/issues/616)) ([868d891](https://github.com/socketio/engine.io/commit/868d89111de0ab5bd0e147ecaff7983afbf5d087)) + + +### Features + +* increase the default value of pingTimeout ([5a7fa13](https://github.com/socketio/engine.io/commit/5a7fa132c442bc1e7eefa1cf38168ee951575ded)) +* remove dynamic require() with wsEngine ([edb7343](https://github.com/socketio/engine.io/commit/edb734316f143bf0f1bbc344e966d18e2676b934)) + + +### BREAKING CHANGES + +* the syntax of the "wsEngine" option is updated + +Before: + +```js +const eioServer = require("engine.io")(httpServer, { + wsEngine: "eiows" +}); +``` + +After: + +```js +const eioServer = require("engine.io")(httpServer, { + wsEngine: require("eiows").Server +}); +``` + + +## [4.1.1](https://github.com/socketio/engine.io/compare/4.1.0...4.1.1) (2021-02-02) + + +### Bug Fixes + +* do not reset the ping timer after upgrade ([ff2b8ab](https://github.com/socketio/engine.io/commit/ff2b8aba48ebcb0de5626d3b76fddc94c398395f)), closes [/github.com/socketio/socket.io-client-swift/pull/1309#issuecomment-768475704](https://github.com//github.com/socketio/socket.io-client-swift/pull/1309/issues/issuecomment-768475704) + + +# [4.1.0](https://github.com/socketio/engine.io/compare/4.0.6...4.1.0) (2021-01-14) + + +### Features + +* add support for v3.x clients ([663d326](https://github.com/socketio/engine.io/commit/663d326d18de598318bd2120b2b70cd51adf8955)) + + +## [4.0.6](https://github.com/socketio/engine.io/compare/4.0.5...4.0.6) (2021-01-04) + + +### Bug Fixes + +* correctly pass the options when using the Server constructor ([#610](https://github.com/socketio/engine.io/issues/610)) ([cec2750](https://github.com/socketio/engine.io/commit/cec27502f5b55c8a2ff289db34019629bf6a97ca)) + + + +# [3.5.0](https://github.com/socketio/engine.io/compare/3.4.2...3.5.0) (2020-12-30) + + +### Features + +* add support for all cookie options ([19cc582](https://github.com/socketio/engine.io/commit/19cc58264a06dca47ed401fbaca32dcdb80a903b)), closes [/github.com/jshttp/cookie#options-1](https://github.com//github.com/jshttp/cookie/issues/options-1) +* disable perMessageDeflate by default ([5ad2736](https://github.com/socketio/engine.io/commit/5ad273601eb66c7b318542f87026837bf9dddd21)) + + + +## [4.0.5](https://github.com/socketio/engine.io/compare/4.0.4...4.0.5) (2020-12-07) + +No change on the server-side, this matches the client release. + +## [4.0.4](https://github.com/socketio/engine.io/compare/4.0.3...4.0.4) (2020-11-17) + +No change on the server-side, this matches the client release. + +## [4.0.3](https://github.com/socketio/engine.io/compare/4.0.2...4.0.3) (2020-11-17) + +No change on the server-side, this matches the client release. + +## [4.0.2](https://github.com/socketio/engine.io/compare/4.0.1...4.0.2) (2020-11-09) + + +### Bug Fixes + +* add extension in the package.json main entry ([#608](https://github.com/socketio/engine.io/issues/608)) ([17b8c2f](https://github.com/socketio/engine.io/commit/17b8c2f199e7a307b6d6294b8599abacb3ec56e7)) + + +## [4.0.1](https://github.com/socketio/engine.io/compare/4.0.0...4.0.1) (2020-10-21) + + +### Bug Fixes + +* do not overwrite CORS headers upon error ([fe093ba](https://github.com/socketio/engine.io/commit/fe093bae1adce99e01dfdd3ce7542957785098b5)) + + + +# [4.0.0](https://github.com/socketio/engine.io/compare/v4.0.0-alpha.1...4.0.0) (2020-09-10) + +More details about this release in the blog post: https://socket.io/blog/engine-io-4-release/ + +### Bug Fixes + +* ignore errors when forcefully closing the socket ([#601](https://github.com/socketio/engine.io/issues/601)) ([dcdbccb](https://github.com/socketio/engine.io/commit/dcdbccb3dd8a7b7db057d23925356034fcd35d48)) +* remove implicit require of uws ([82cdca2](https://github.com/socketio/engine.io/commit/82cdca23bab0ed69b61b60961900d456a3065e6a)) + + +### Features + +* disable perMessageDeflate by default ([078527a](https://github.com/socketio/engine.io/commit/078527a384b70dc46d99083fa218be5d45213e51)) + +#### Links + +- Diff: [v4.0.0-alpha.1...4.0.0](https://github.com/socketio/engine.io/compare/v4.0.0-alpha.1...4.0.0) +- Full diff: [3.4.0...4.0.0](https://github.com/socketio/engine.io/compare/3.4.0...4.0.0) +- Client release: [4.0.0](https://github.com/socketio/engine.io-client/releases/tag/4.0.0) +- ws version: [^7.1.2](https://github.com/websockets/ws/releases/tag/7.1.2) + + +## [3.4.2](https://github.com/socketio/engine.io/compare/3.4.1...3.4.2) (2020-06-04) + + +### Bug Fixes + +* remove explicit require of uws ([85e544a](https://github.com/socketio/engine.io/commit/85e544afd95a5890761a613263a5eba0c9a18a93)) + +#### Links + +- Diff: [3.4.1...3.4.2](https://github.com/socketio/engine.io/compare/3.4.1...3.4.2) +- Client release: - +- ws version: [^7.1.2](https://github.com/websockets/ws/releases/tag/7.1.2) + + + +## [3.4.1](https://github.com/socketio/engine.io/compare/3.4.0...3.4.1) (2020-04-17) + + +### Bug Fixes + +* ignore errors when forcefully closing the socket ([da851ec](https://github.com/socketio/engine.io/commit/da851ec4ec89d96df2ee5c711f328b5d795423e9)) +* use SameSite=Strict by default ([001ca62](https://github.com/socketio/engine.io/commit/001ca62cc4a8f511f3b2fbd9e4493ad274a6a0e5)) + +#### Links + +- Diff: [3.4.0...3.4.1](https://github.com/socketio/engine.io/compare/3.4.0...3.4.1) +- Client release: [3.4.1](https://github.com/socketio/engine.io-client/releases/tag/3.4.1) +- ws version: [^7.1.2](https://github.com/websockets/ws/releases/tag/7.1.2) + + + +# [4.0.0-alpha.1](https://github.com/socketio/engine.io/compare/v4.0.0-alpha.0...v4.0.0-alpha.1) (2020-02-12) + +#### Links + +- Diff: [v4.0.0-alpha.0...v4.0.0-alpha.1](https://github.com/socketio/engine.io-client/compare/v4.0.0-alpha.0...v4.0.0-alpha.1) +- Client release: [v4.0.0-alpha.1](https://github.com/socketio/engine.io-client/releases/tag/v4.0.0-alpha.1) +- ws version: [^7.1.2](https://github.com/websockets/ws/releases/tag/7.1.2) + + + +# [4.0.0-alpha.0](https://github.com/socketio/engine.io/compare/3.4.0...v4.0.0-alpha.0) (2020-02-12) + + +### Features + +* decrease the default value of maxHttpBufferSize ([734f9d1](https://github.com/socketio/engine.io/commit/734f9d1268840722c41219e69eb58318e0b2ac6b)) +* disable cookie by default and add sameSite attribute ([a374471](https://github.com/socketio/engine.io/commit/a374471d06e3681a769766a1d068898182f9305f)), closes [/github.com/jshttp/cookie#options-1](https://github.com//github.com/jshttp/cookie/issues/options-1) +* generateId method can now return a Promise ([f3c291f](https://github.com/socketio/engine.io/commit/f3c291fa613a9d50c924d74293035737fdace4f2)) +* reverse the ping-pong mechanism ([31ff875](https://github.com/socketio/engine.io/commit/31ff87593f231b86dc47ec5761936439ebd53c20)) +* use the cors module to handle cross-origin requests ([61b9492](https://github.com/socketio/engine.io/commit/61b949259ed966ef6fc8bfd61f14d1a2ef06d319)) + + +### BREAKING CHANGES + +* the handlePreflightRequest option is removed by the change. + +Before: + +``` +new Server({ + handlePreflightRequest: (req, res) => { + res.writeHead(200, { + "Access-Control-Allow-Origin": 'https://example.com', + "Access-Control-Allow-Methods": 'GET', + "Access-Control-Allow-Headers": 'Authorization', + "Access-Control-Allow-Credentials": true + }); + res.end(); + } +}) +``` + +After: + +``` +new Server({ + cors: { + origin: "https://example.com", + methods: ["GET"], + allowedHeaders: ["Authorization"], + credentials: true + } +}) +``` +* the syntax has changed from + +``` +new Server({ + cookieName: "test", + cookieHttpOnly: false, + cookiePath: "/custom" +}) +``` + +to + +``` +new Server({ + cookie: { + name: "test", + httpOnly: false, + path: "/custom" + } +}) +``` + +All other options (domain, maxAge, sameSite, ...) are now supported. + +* v3.x clients will not be able to connect anymore (they will send a ping packet and timeout while waiting for a pong packet). + +#### Links + +- Diff: [3.4.0...v4.0.0-alpha.0](https://github.com/socketio/engine.io-client/compare/3.4.0...v4.0.0-alpha.0) +- Client release: [v4.0.0-alpha.0](https://github.com/socketio/engine.io-client/releases/tag/v4.0.0-alpha.0) +- ws version: [^7.1.2](https://github.com/websockets/ws/releases/tag/7.1.2) + diff --git a/History.md b/History.md deleted file mode 100644 index b2c978d4f..000000000 --- a/History.md +++ /dev/null @@ -1,554 +0,0 @@ - -1.8.2 / 2016-12-11 -=================== - - * [fix] Add proper response when handleUpgrade fails (#458) - * [test] Use explicit versions for travis tests (#457) - * [refactor] Remove deprecated code used for nodejs v0.8 (#456) - * [chore] Bump engine.io-parser to version 1.3.2 (#455) - * [perf] websocket optimisation (#453) - * [docs] Rename ServerRequest to IncomingMessage (#448) - * [chore] Bump base64id to version 1.0.0 (#451) - -1.8.1 / 2016-11-27 -=================== - - * [fix] Only add defined callbacks to the stack (#447) - -1.8.0 / 2016-11-20 -=================== - - * [style] Fix some typos (#439) - * [style] Add ESlint (#385) - * [test] fix tests for NodeJS v7 (#441) - * [feature] Fix cookiePath empty bug and add cookieHttpOnly option (#423) - * [fix] Don't delete ws when closing the server (#444) - * [chore] Bump debug to version 2.3.3 (#445) - -1.7.2 / 2016-10-24 -=================== - - * [docs] Add missing `upgradeTimeout` option in the docs (#437) - * [chore] Add Github issue and PR templates (#436) - -1.7.1 / 2016-10-20 -=================== - - * [fix] Close and free webSocketServer (#393) - * [chore] Bump engine.io-client to 1.7.0 (#429) - * [chore] Bump engine.io-parser to 1.3.1 (#433) - * [chore] Add latest nodejs release in travis settings (#434) - -1.7.0 / 2016-10-05 -=================== - - * [feature] Give the ability to dynamically choose ws implementation (#390) - * [chore] Add gulp & babel in the build process (#384) - * [chore] Ignore dist not to release for now (#387) - * [chore] Upgrade accepts to 1.3.3 - * [chore] Bumping ws to 1.1.1 to address https://nodesecurity.io/advisories/120 (#411) - * [chore] Restoring require('ws') as separate expression for browserify. (#418) - * [chore] Bump engine.io-parser to 1.3.0 (#425) - * [chore] Make the build status badge point towards master (#426) - * [chore] Restrict files included in npm package (#427) - -1.6.11 / 2016-06-23 -=================== - - * package: bump `ws` to support `maxPayload` - -1.6.10 / 2016-06-23 -=================== - - * set a default ws `maxPayload` [security fix] - * bump `accepts` [security fix] - -1.6.9 / 2016-05-03 -================== - - * bump client - -1.6.8 / 2016-01-25 -================== - - * fix graceful close [nkzawa] - * polling: don't set the `closeTimeoutTimer` if the transport is upgraded - -1.6.7 / 2016-01-10 -================== - - * bump version - -1.6.6 / 2016-01-07 -================== - - * bump version - -1.6.5 / 2016-01-05 -================== - - * package: upgrade ws for sec advisory - * server: catch websocket errors before upgrade - -1.6.4 / 2015-12-04 -================== - - * package: bump parser for arraybuffer base64 fix - -1.6.3 / 2015-12-01 -================== - - * restore testing on 0.8 - * improve X-XSS-Protection header definition [nkzawa] - * add threshold for permessage-deflate [nkzawa] - -1.6.2 / 2015-11-30 -================== - - * don't compress control packets - -1.6.1 / 2015-11-28 -================== - - * package: bump `engine.io-client` for `ws` options fix - * fix `latency` example - -1.6.0 / 2015-11-28 -================== - - * add support for environments that extend `Object.prototype` - * remove listeners upon `clearTransport` - * support for all versions of node - * fix lingering sockets that can stay open when upgrade failed - * ensure sockets are closed on error - * bump `ws` for several improvements - * fix for a rare race condition on some error scenarios - * support custom socket id - * use container-based infrastructure for faster build - * fix package.json wrongly referrering to self - * allow overriding the `cookiePath` - * fix potential encoding errors under certain conditions - * support compression - -1.5.4 / 2015-09-09 -================== - - * package: bump `engine.io-parser` - -1.5.3 / 2015-09-09 -================== - - * package: bump `ws` to fix node 4.0.0 - -1.5.2 / 2015-07-09 -================== - - * package: bump `ws` to fix build issues - -1.5.1 / 2015-01-19 -================== - - * no change on this release - * package: bump `engine.io-client` - -1.5.0 / 2015-01-18 -================== - - * package: bump `engine.io-parser` - * polling: correctly abort the ongoing data request when closing [lpinca] - * add cert-related client tests [rase-] - -1.4.3 / 2014-11-21 -================== - - * package: bump `ws` to fix fd leaks - * socket: flush the write buffer before closing the socket [lpinca] - * polling: close the pending poll request when closing transport [lpinca] - -1.4.2 / 2014-10-08 -================== - - * add iframe onload handling to jsonp tests [rase-] - -1.4.1 / 2014-10-03 -================== - - * socket: allow upgrades if the socket is still in closing state - * README: fix typo - -1.4.0 / 2014-09-03 -================== - - * readme: fix formatting for goals numbering - * server: ref fix by @nicokaiser - * server: fix ws memory leak (fixes #268) - * cache remote address in handshake since it might be lost later. - * correct git ref - * update client to commit with bumped parser - * package: bump parser - * npmignore: ignore `.gitignore` - * package: bump `debug` - * package: bump `engine.io-parser` for memleak fix - -1.3.1 / 2014-06-19 -================== - - * package: bump `engine.io-client` - -1.3.0 / 2014-06-13 -================== - - * update example to use v1.2.2 - * fixed newline parsing in jsonp - * make require('engine.io')() return a new Server instance [defunctzombie] - * add Server.attach method [defunctzombie] - * fix GH-211, set CORS headers when sending error message [mokesmokes] - -1.2.2 / 2014-05-30 -================== - - * package: bump `engine.io-parser` for binary utf8 fix - -1.2.1 / 2014-05-22 -================== - - * package: bump engine.io-client - -1.2.0 / 2014-05-18 -================== - - * removed flashsocket, moving to userland - -1.1.1 / 2014-05-14 -================== - - * test: reduce packet size - * package: bump parser - -1.1.0 / 2014-04-27 -================== - - * socket: removed unneeded `clearTimeout` (fixes #250) - * made the request verification process async - * package: bump `engine.io-parser` - * use _query instead of query, fixes compat with restify - * added a maximum buffer size to received data from polling - * fixing looping array via for in to normal loop - -1.0.5 / 2014-03-18 -================== - - * package: bump `engine.io-parser` and `engine.io-client` - -1.0.4 / 2014-03-14 -================== - - * package: bump `engine.io-client` - -1.0.3 / 2014-03-12 -================== - - * package: bump `engine.io-client` - -1.0.2 / 2014-03-12 -================== - - * bump engine.io-client - -1.0.1 / 2014-03-06 -================== - - * package: bump `engine.io-parser` - * transports: fix jshint warnings and style - -1.0.0 / 2014-03-06 -================== - - * polling-xhr: added `OPTIONS` support, fixes CORS - * close() properly when triggered in connection handler - * fix DDOS vector by setting up too many intervals - * binary support - -0.9.0 / 2014-02-09 -================== - - * Prevent errors with connections behind proxies without WS support - like Squid [nicklagrow, samaanghani, davidhcummings] - * Socket#request a simple property [mokesmokes] - * Changed `Socket`'s `upgrade` event to happen after upgrade [mokesmokes] - * Document `Socket#id` [mokesmokes] - -0.8.2 / 2014-01-18 -================== - - * package: bump `engine.io-client` - -0.8.1 / 2014-01-17 -================== - - * package: bump `engine.io-client` - * package: pin dev deps - * examples: fix port output - * fix latency example - -0.8.0 / 2014-01-05 -================== - - * package: bump `engine.io-client` to `0.8.0` - * test: fix syntax, remove globals - -0.7.14 / 2014-01-01 -=================== - - * package: bump `engine.io-client` to `0.7.14` - -0.7.13 / 2013-12-20 -=================== - - * package: bump `engine.io-client` - * transports: added support for XSS filters on IE [guille, 3rd-eden] - -0.7.12 / 2013-11-11 -=================== - - * package: bump `engine.io-client` - -0.7.11 / 2013-11-06 -=================== - - * package: bump engine.io-client - * fix GH-198 - -0.7.10 / 2013-10-28 -=================== - - * package: bump `engine.io-client` - * package: update "ws" to v0.4.31 - -0.7.9 / 2013-08-30 -================== - - * package: bump `engine.io-client` - -0.7.8 / 2013-08-30 -================== - - * package: bump `engine.io-client` - * package: bump ws - -0.7.7 / 2013-08-30 -================== - - * package: bump `engine.io-client` - -0.7.6 / 2013-08-30 -================== - - * package: bump engine.io-client - -0.7.5 / 2013-08-30 -================== - - * package: bump engine.io-client - -0.7.4 / 2013-08-25 -================== - - * package: bump `engine.io-client` - -0.7.3 / 2013-08-23 -================== - - * package: bump engine.io-client (noop) - * package: fix regresison in upgrade cause by ws update - -0.7.2 / 2013-08-23 -================== - - * package: bump `engine.io-client` for `WebSocket` browser fix - -0.7.1 / 2013-08-23 -================== - - * package: bump engine.io-client for ws fix - -0.7.0 / 2013-08-23 -================== - - * package: bump engine.io-client - * updated example - * inline merge - * added support node version 0.10 to .travis.yml - * fixed respond to flash policy request test. Closes #184 - * fixed upgrade with timeout test. Closes #185 - * engine.io: don't use __proto__, closes #170 - -0.6.3 / 2013-06-21 -================== - - * package: bumped `engine.io-client` to `0.6.3` - -0.6.2 / 2013-06-15 -================== - - * fix upgrade stalling edge case introduced with #174 fix - * remove unneeded client code related to iOS - * added test for `engine.io-client` `0.6.1` - -0.6.1 / 2013-06-06 -================== - - * package: bumped `engine.io-client` to `0.6.1` - -0.6.0 / 2013-05-31 -================== - - * socket: clear timer after sending one noop packet (fixes #174) - * clear all timers on socket close - * sending error on transport creation upon a bad request - * added test for client-side buffer cleanup - * changed flushComplete to flush - * ended support for node 0.6 - -0.5.0 / 2013-03-16 -================== - - * polling: implemented new parser - * test writeBuffer isn't cleared onError, removed 'closing' check in .flush() - * fixed bug89 and added tests: writeBuffer not flushed until nextTick - -0.4.3 / 2013-02-08 -================== - - * package: bumped `engine.io-client` to `0.4.3` - -0.4.2 / 2013-02-08 -================== - - * Only end upgrade socket connections if unhandled - * Fix websocket dependency - * Close socket if upgrade is received and socket.readyState != open - -0.4.1 / 2013-01-18 -================== - - * package: bumped versions - * Fixed bugs in previous send callback fix and updated test cases - * Added a test case which makes the code before the send callback fix fail - * socket: emit `data` event (synonym with `message`) - * socket: added `Socket#write` - * engine.io: cleanup - * engine.io: deprecated `resource` - * `npm docs engine.io` works now - -0.3.10 / 2012-12-03 -=================== - - * package: bumped `engine.io-client` with `close` fixes - * add packetCreate event [jxck] - * add packet event to socket [jxck] - * transport: remove `Connection` headers and let node handle it - * server: send validation failure reason to clients - * engine: invoking as a function causes attach - * socket: reset `writeBuffer` before send - -0.3.9 / 2012-10-23 -================== - - * package: bumped `engine.io-client` - -0.3.8 / 2012-10-23 -================== - - * package: bumped engine.io-client - * examples: added first example - -0.3.7 / 2012-10-21 -================== - - * package: bumped `engine.io-client` - -0.3.6 / 2012-10-21 -================== - - [skipped] - -0.3.5 / 2012-10-14 -================== - - * package: reverted last commit - we use the parser from the client - -0.3.4 / 2012-10-14 -================== - - * package: `engine.io-client` moved to `devDependencies` - * socket: added missing jsdoc - -0.3.3 / 2012-10-10 -================== - - * socket: fixed check interval clearing [joewalnes] - * transports: improved instrumentation - -0.3.2 / 2012-10-08 -================== - - * socket: improve check interval for upgrade - -0.3.1 / 2012-10-08 -================== - - * socket: faster upgrades (we perform a check immediately) - * server: don't assume sid is numeric - -0.3.0 / 2012-10-04 -================== - - * socket: `writeBuffer` now gets sliced, and is recoverable after `close` [afshinm] - * server: expect ping from client and send interval with handshake [cadorn] - * polling-jsonp: prevent client breakage with utf8 whitespace - * socket: fix `flush` and `drain` events - * socket: add `send` callback [afshinm] - * transport: avoid unhandled error events for stale transports - * README: documentation improvements [EugenDueck] - -0.2.2 / 2012-08-26 -================== - - * server: remove buffering for flash policy requests - * transport: avoid unhandled error events for stale transports (fixes #69) - * readme: documented `toString` behavior on `send` [EugenDueck] - -0.2.1 / 2012-08-13 -================== - - * polling-xhr: skip Keep-Alive when it's implied [EugenDueck] - * polling-jsonp: skip Keep-Alive when it's implied [EugenDueck] - * README: added plugins list with engine.io-conflation - * socket: added flush/drain events (fixes #56) - * server: avoid passing websocket to non-websocket transports (fixes #24) - -0.2.0 / 2012-08-06 -================== - - * Bumped client - * test: added closing connection test - * server: implemented stronger id generator with collision detection - -0.1.2 / 2012-08-02 -================== - - * Fixed a jsonp bug in Nokia mobile phones and potentially other UAs. - -0.1.1 / 2012-08-01 -================== - - * Fixed errors when a socket is closed while upgrade probe is happening. - * Improved WS error handling - * Replaced websocket.io with ws, now that it supports older drafts - * README fixes - -0.1.0 / 2012-07-03 -================== - - * Initial release. diff --git a/Makefile b/Makefile deleted file mode 100644 index da335f66d..000000000 --- a/Makefile +++ /dev/null @@ -1,16 +0,0 @@ - -BENCHMARKS = $(shell find bench -type f ! -name 'runner.js') - -test: - @./node_modules/.bin/gulp test - -test-cov: lib-cov - EIO_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html - -lib-cov: - jscoverage --no-highlight lib lib-cov - -bench: - @node $(PROFILEFLAGS) bench/runner.js $(BENCHMARKS) - -.PHONY: test test-cov bench diff --git a/README.md b/README.md index c744f395e..da038e19a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Engine.IO: the realtime engine -[](http://travis-ci.org/socketio/engine.io) +[](https://github.com/socketio/engine.io/actions) [](http://badge.fury.io/js/engine.io) `Engine.IO` is the implementation of transport-based @@ -15,43 +15,44 @@ cross-browser/cross-device bi-directional communication layer for #### (A) Listening on a port ```js -var engine = require('engine.io'); -var server = engine.listen(80); +const engine = require('engine.io'); +const server = engine.listen(80); -server.on('connection', function(socket){ +server.on('connection', socket => { socket.send('utf 8 string'); - socket.send(new Buffer([0, 1, 2, 3, 4, 5])); // binary data + socket.send(Buffer.from([0, 1, 2, 3, 4, 5])); // binary data }); ``` #### (B) Intercepting requests for a http.Server ```js -var engine = require('engine.io'); -var http = require('http').createServer().listen(3000); -var server = engine.attach(http); +const engine = require('engine.io'); +const http = require('http').createServer().listen(3000); +const server = engine.attach(http); -server.on('connection', function (socket) { - socket.on('message', function(data){ }); - socket.on('close', function(){ }); +server.on('connection', socket => { + socket.on('message', data => { }); + socket.on('close', () => { }); }); ``` #### (C) Passing in requests ```js -var engine = require('engine.io'); -var server = new engine.Server(); +const engine = require('engine.io'); +const server = new engine.Server(); -server.on('connection', function(socket){ +server.on('connection', socket => { socket.send('hi'); }); // … -httpServer.on('upgrade', function(req, socket, head){ +httpServer.on('upgrade', (req, socket, head) => { server.handleUpgrade(req, socket, head); }); -httpServer.on('request', function(req, res){ + +httpServer.on('request', (req, res) => { server.handleRequest(req, res); }); ``` @@ -61,16 +62,16 @@ httpServer.on('request', function(req, res){ ```html ``` For more information on the client refer to the -[engine-client](http://github.com/learnboost/engine.io-client) repository. +[engine-client](http://github.com/socketio/engine.io-client) repository. ## What features does it have? @@ -86,7 +87,6 @@ For more information on the client refer to the - **Future proof** - **100% Node.JS core style** - No API sugar (left for higher level projects) - - Written in readable vanilla JavaScript ## API @@ -129,20 +129,26 @@ These are exposed by `require('engine.io')`: - `Object`: optional, options object (see `Server#constructor` api docs below) The following are identical ways to instantiate a server and then attach it. - ```js - var httpServer; // previously created with `http.createServer();` from node.js api. - // create a server first, and then attach - var eioServer = require('engine.io').Server(); - eioServer.attach(httpServer); +```js +const httpServer; // previously created with `http.createServer();` from node.js api. + +// create a server first, and then attach +const eioServer = require('engine.io').Server(); +eioServer.attach(httpServer); - // or call the module as a function to get `Server` - var eioServer = require('engine.io')(); - eioServer.attach(httpServer); +// or call the module as a function to get `Server` +const eioServer = require('engine.io')(); +eioServer.attach(httpServer); - // immediately attach - var eioServer = require('engine.io')(httpServer); - ``` +// immediately attach +const eioServer = require('engine.io')(httpServer); + +// with custom options +const eioServer = require('engine.io')(httpServer, { + maxHttpBufferSize: 1e3 +}); +``` - `listen` - Creates an `http.Server` which listens on the given port and attaches WS @@ -155,6 +161,17 @@ These are exposed by `require('engine.io')`: - All options from `Server.attach` method, documented below. - **Additionally** See Server `constructor` below for options you can pass for creating the new Server - **Returns** `Server` + +```js +const engine = require('engine.io'); +const server = engine.listen(3000, { + pingTimeout: 2000, + pingInterval: 10000 +}); + +server.on('connection', /* ... */); +``` + - `attach` - Captures `upgrade` requests for a `http.Server`. In other words, makes a regular http.Server WebSocket-compatible. @@ -166,7 +183,15 @@ These are exposed by `require('engine.io')`: - **Additionally** See Server `constructor` below for options you can pass for creating the new Server - **Returns** `Server` a new Server instance. -