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: websockets/ws
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8.4.0
Choose a base ref
...
head repository: websockets/ws
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8.4.1
Choose a head ref
  • 8 commits
  • 8 files changed
  • 3 contributors

Commits on Dec 30, 2021

  1. [doc] Clarify interpretation of verifyClient (#1994)

    Prior to this commit, the documentation for the `verifyClient` option
    was somewhat confusing due to its use of the passive voice and an
    uncommon interpretation of the term "arguments".
    
    Explain the way `ws` interprets the value of `verifyClient` using an
    active voice and more traditional meanings of "parameters" and
    "arguments".
    jugglinmike authored and lpinca committed Dec 30, 2021
    Copy the full SHA
    5edf1f4 View commit details

Commits on Jan 4, 2022

  1. Copy the full SHA
    d2c935a View commit details

Commits on Jan 6, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4081a36 View commit details
  2. [test] Improve test title

    lpinca committed Jan 6, 2022
    Copy the full SHA
    ad3fe6d View commit details

Commits on Jan 9, 2022

  1. [minor] Replace echo.websocket.org with websocket-echo.com

    The echo.websocket.org service is no longer available.
    lpinca committed Jan 9, 2022
    Copy the full SHA
    91f3c07 View commit details
  2. [test] Fix failing tests

    Refs: e173423c
    lpinca committed Jan 9, 2022
    Copy the full SHA
    8de448f View commit details

Commits on Jan 13, 2022

  1. [perf] Reduce buffer allocations (#2000)

    Do not convert strings to `Buffer`s if data does not need to be masked.
    
    Refs: #1998
    lpinca authored Jan 13, 2022
    Copy the full SHA
    5b7fbb0 View commit details
  2. [dist] 8.4.1

    lpinca committed Jan 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6ebfeb8 View commit details
Showing with 202 additions and 155 deletions.
  1. +6 −10 README.md
  2. +4 −3 doc/ws.md
  3. +2 −2 lib/permessage-deflate.js
  4. +122 −110 lib/sender.js
  5. +1 −1 package.json
  6. +47 −15 test/sender.test.js
  7. +18 −12 test/websocket.integration.js
  8. +2 −2 test/websocket.test.js
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ can use one of the many wrappers available on npm, like
- [Multiple servers sharing a single HTTP/S server](#multiple-servers-sharing-a-single-https-server)
- [Client authentication](#client-authentication)
- [Server broadcast](#server-broadcast)
- [echo.websocket.org demo](#echowebsocketorg-demo)
- [Round-trip time](#round-trip-time)
- [Use the Node.js streams API](#use-the-nodejs-streams-api)
- [Other examples](#other-examples)
- [FAQ](#faq)
@@ -324,14 +324,12 @@ wss.on('connection', function connection(ws) {
});
```

### echo.websocket.org demo
### Round-trip time

```js
import WebSocket from 'ws';

const ws = new WebSocket('wss://echo.websocket.org/', {
origin: 'https://websocket.org'
});
const ws = new WebSocket('wss://websocket-echo.com/');

ws.on('open', function open() {
console.log('connected');
@@ -343,7 +341,7 @@ ws.on('close', function close() {
});

ws.on('message', function message(data) {
console.log(`Roundtrip time: ${Date.now() - data} ms`);
console.log(`Round-trip time: ${Date.now() - data} ms`);

setTimeout(function timeout() {
ws.send(Date.now());
@@ -356,9 +354,7 @@ ws.on('message', function message(data) {
```js
import WebSocket, { createWebSocketStream } from 'ws';

const ws = new WebSocket('wss://echo.websocket.org/', {
origin: 'https://websocket.org'
});
const ws = new WebSocket('wss://websocket-echo.com/');

const duplex = createWebSocketStream(ws, { encoding: 'utf8' });

@@ -457,7 +453,7 @@ function heartbeat() {
}, 30000 + 1000);
}

const client = new WebSocket('wss://echo.websocket.org/');
const client = new WebSocket('wss://websocket-echo.com/');

client.on('open', heartbeat);
client.on('ping', heartbeat);
7 changes: 4 additions & 3 deletions doc/ws.md
Original file line number Diff line number Diff line change
@@ -91,15 +91,15 @@ must be provided or an error is thrown. An HTTP server is automatically created,
started, and used if `port` is set. To use an external HTTP/S server instead,
specify only `server` or `noServer`. In this case the HTTP/S server must be
started manually. The "noServer" mode allows the WebSocket server to be
completly detached from the HTTP/S server. This makes it possible, for example,
completely detached from the HTTP/S server. This makes it possible, for example,
to share a single HTTP/S server between multiple WebSocket servers.

> **NOTE:** Use of `verifyClient` is discouraged. Rather handle client
> authentication in the `upgrade` event of the HTTP server. See examples for
> more details.
If `verifyClient` is not set then the handshake is automatically accepted. If it
is provided with a single argument then that is:
has a single parameter then `ws` will invoke it with the following argument:

- `info` {Object}
- `origin` {String} The value in the Origin header indicated by the client.
@@ -110,7 +110,8 @@ is provided with a single argument then that is:
The return value (`Boolean`) of the function determines whether or not to accept
the handshake.

if `verifyClient` is provided with two arguments then those are:
If `verifyClient` has two parameters then `ws` will invoke it with the following
arguments:

- `info` {Object} Same as above.
- `cb` {Function} A callback that must be called by the user upon inspection of
4 changes: 2 additions & 2 deletions lib/permessage-deflate.js
Original file line number Diff line number Diff line change
@@ -313,7 +313,7 @@ class PerMessageDeflate {
/**
* Compress data. Concurrency limited.
*
* @param {Buffer} data Data to compress
* @param {(Buffer|String)} data Data to compress
* @param {Boolean} fin Specifies whether or not this is the last fragment
* @param {Function} callback Callback
* @public
@@ -395,7 +395,7 @@ class PerMessageDeflate {
/**
* Compress data.
*
* @param {Buffer} data Data to compress
* @param {(Buffer|String)} data Data to compress
* @param {Boolean} fin Specifies whether or not this is the last fragment
* @param {Function} callback Callback
* @private
Loading