Comparing version 3.0.0 to 3.1.0
@@ -58,6 +58,4 @@ 'use strict'; | ||
this.wasClean = code === undefined || code === 1000; | ||
this.wasClean = code === undefined || code === 1000 || (code >= 3000 && code <= 4999); | ||
this.reason = reason; | ||
this.target = target; | ||
this.type = 'close'; | ||
this.code = code; | ||
@@ -64,0 +62,0 @@ } |
@@ -10,7 +10,4 @@ 'use strict'; | ||
const AVAILABLE_WINDOW_BITS = [8, 9, 10, 11, 12, 13, 14, 15]; | ||
const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]); | ||
const EMPTY_BLOCK = Buffer.from([0x00]); | ||
const DEFAULT_WINDOW_BITS = 15; | ||
const DEFAULT_MEM_LEVEL = 8; | ||
@@ -120,16 +117,13 @@ /** | ||
const result = paramsList.some((params) => { | ||
if (( | ||
this._options.serverNoContextTakeover === false && | ||
params.server_no_context_takeover | ||
) || ( | ||
this._options.serverMaxWindowBits === false && | ||
params.server_max_window_bits | ||
) || ( | ||
typeof this._options.serverMaxWindowBits === 'number' && | ||
typeof params.server_max_window_bits === 'number' && | ||
this._options.serverMaxWindowBits > params.server_max_window_bits | ||
) || ( | ||
typeof this._options.clientMaxWindowBits === 'number' && | ||
!params.client_max_window_bits | ||
)) { | ||
if ( | ||
(this._options.serverNoContextTakeover === false && | ||
params.server_no_context_takeover) || | ||
(this._options.serverMaxWindowBits === false && | ||
params.server_max_window_bits) || | ||
(typeof this._options.serverMaxWindowBits === 'number' && | ||
typeof params.server_max_window_bits === 'number' && | ||
this._options.serverMaxWindowBits > params.server_max_window_bits) || | ||
(typeof this._options.clientMaxWindowBits === 'number' && | ||
!params.client_max_window_bits) | ||
) { | ||
return; | ||
@@ -144,8 +138,6 @@ } | ||
} | ||
if (this._options.clientNoContextTakeover) { | ||
accepted.client_no_context_takeover = true; | ||
} | ||
if ( | ||
this._options.clientNoContextTakeover !== false && | ||
params.client_no_context_takeover | ||
this._options.clientNoContextTakeover || | ||
(this._options.clientNoContextTakeover !== false && | ||
params.client_no_context_takeover) | ||
) { | ||
@@ -170,3 +162,3 @@ accepted.client_no_context_takeover = true; | ||
if (!result) throw new Error(`Doesn't support the offered configuration`); | ||
if (!result) throw new Error("Doesn't support the offered configuration"); | ||
@@ -202,6 +194,6 @@ return accepted; | ||
if ( | ||
typeof this._options.clientMaxWindowBits === 'number' && ( | ||
!params.client_max_window_bits || | ||
params.client_max_window_bits > this._options.clientMaxWindowBits | ||
)) { | ||
typeof this._options.clientMaxWindowBits === 'number' && | ||
(!params.client_max_window_bits || | ||
params.client_max_window_bits > this._options.clientMaxWindowBits) | ||
) { | ||
throw new Error('Invalid value for "client_max_window_bits"'); | ||
@@ -243,3 +235,7 @@ } | ||
value = parseInt(value, 10); | ||
if (!~AVAILABLE_WINDOW_BITS.indexOf(value)) { | ||
if ( | ||
Number.isNaN(value) || | ||
value < zlib.Z_MIN_WINDOWBITS || | ||
value > zlib.Z_MAX_WINDOWBITS | ||
) { | ||
throw new Error(`invalid extension parameter value for ${key} (${value})`); | ||
@@ -273,6 +269,8 @@ } | ||
if (!this._inflate) { | ||
const maxWindowBits = this.params[`${endpoint}_max_window_bits`]; | ||
this._inflate = zlib.createInflateRaw({ | ||
windowBits: typeof maxWindowBits === 'number' ? maxWindowBits : DEFAULT_WINDOW_BITS | ||
}); | ||
const key = `${endpoint}_max_window_bits`; | ||
const windowBits = typeof this.params[key] !== 'number' | ||
? zlib.Z_DEFAULT_WINDOWBITS | ||
: this.params[key]; | ||
this._inflate = zlib.createInflateRaw({ windowBits }); | ||
} | ||
@@ -345,7 +343,11 @@ this._inflate.writeInProgress = true; | ||
if (!this._deflate) { | ||
const maxWindowBits = this.params[`${endpoint}_max_window_bits`]; | ||
const key = `${endpoint}_max_window_bits`; | ||
const windowBits = typeof this.params[key] !== 'number' | ||
? zlib.Z_DEFAULT_WINDOWBITS | ||
: this.params[key]; | ||
this._deflate = zlib.createDeflateRaw({ | ||
memLevel: this._options.memLevel, | ||
flush: zlib.Z_SYNC_FLUSH, | ||
windowBits: typeof maxWindowBits === 'number' ? maxWindowBits : DEFAULT_WINDOW_BITS, | ||
memLevel: this._options.memLevel || DEFAULT_MEM_LEVEL | ||
windowBits | ||
}); | ||
@@ -352,0 +354,0 @@ } |
@@ -13,3 +13,3 @@ /*! | ||
module.exports = typeof isValidUTF8 === 'object' | ||
? isValidUTF8.Validation.isValidUTF8 // utf-8-validate@<3.0.0 | ||
? isValidUTF8.Validation.isValidUTF8 // utf-8-validate@<3.0.0 | ||
: isValidUTF8; | ||
@@ -16,0 +16,0 @@ } catch (e) /* istanbul ignore next */ { |
@@ -134,6 +134,3 @@ /*! | ||
// ensure that the head is added to the receiver | ||
if (head && head.length > 0) { | ||
socket.unshift(head); | ||
head = null; | ||
} | ||
if (head.length > 0) socket.unshift(head); | ||
@@ -478,2 +475,3 @@ // subsequent packets are pushed to the receiver | ||
* @param {(Boolean|Object)} options.perMessageDeflate Enable/disable permessage-deflate | ||
* @param {Number} options.handshakeTimeout Timeout in milliseconds for the handshake request | ||
* @param {String} options.localAddress Local interface to bind for network connections | ||
@@ -501,2 +499,3 @@ * @param {Number} options.protocolVersion Value of the `Sec-WebSocket-Version` header | ||
perMessageDeflate: true, | ||
handshakeTimeout: null, | ||
localAddress: null, | ||
@@ -641,2 +640,10 @@ headers: null, | ||
if (options.handshakeTimeout) { | ||
this._req.setTimeout(options.handshakeTimeout, () => { | ||
this._req.abort(); | ||
this.emit('error', new Error('opening handshake has timed out')); | ||
this.finalize(true); | ||
}); | ||
} | ||
this._req.on('error', (error) => { | ||
@@ -643,0 +650,0 @@ if (this._req.aborted) return; |
{ | ||
"name": "ws", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
"dependencies": { | ||
"safe-buffer": "~5.0.1", | ||
"safe-buffer": "~5.1.0", | ||
"ultron": "~1.1.0" | ||
@@ -36,12 +36,12 @@ }, | ||
"bufferutil": "~3.0.0", | ||
"eslint": "~3.19.0", | ||
"eslint": "~4.3.0", | ||
"eslint-config-standard": "~10.2.0", | ||
"eslint-plugin-import": "~2.2.0", | ||
"eslint-plugin-node": "~4.2.0", | ||
"eslint-plugin-import": "~2.7.0", | ||
"eslint-plugin-node": "~5.1.0", | ||
"eslint-plugin-promise": "~3.5.0", | ||
"eslint-plugin-standard": "~3.0.0", | ||
"mocha": "~3.4.1", | ||
"nyc": "~10.3.0", | ||
"nyc": "~11.0.1", | ||
"utf-8-validate": "~3.0.0" | ||
} | ||
} |
@@ -8,3 +8,3 @@ # ws: a Node.js WebSocket library | ||
`ws` is a simple to use, blazing fast, and thoroughly tested WebSocket client | ||
ws is a simple to use, blazing fast, and thoroughly tested WebSocket client | ||
and server implementation. | ||
@@ -39,2 +39,3 @@ | ||
+ [How to detect and close broken connections?](#how-to-detect-and-close-broken-connections) | ||
+ [How to connect via a proxy?](#how-to-connect-via-a-proxy) | ||
* [Changelog](#changelog) | ||
@@ -56,3 +57,3 @@ * [License](#license) | ||
There are 2 optional modules that can be installed along side with the `ws` | ||
There are 2 optional modules that can be installed along side with the ws | ||
module. These modules are binary addons which improve certain operations. | ||
@@ -74,3 +75,3 @@ Prebuilt binaries are available for the most popular platforms so you don't | ||
`ws` supports the [permessage-deflate extension][permessage-deflate] which | ||
ws supports the [permessage-deflate extension][permessage-deflate] which | ||
enables the client and server to negotiate a compression algorithm and its | ||
@@ -82,3 +83,3 @@ parameters, and then selectively apply it to the data payloads of each | ||
the client. It adds a significant overhead in terms of performance and memory | ||
comsumption so we suggest to enable it only if it is really needed. | ||
consumption so we suggest to enable it only if it is really needed. | ||
@@ -282,3 +283,3 @@ The client will only use the extension if it is supported and enabled on the | ||
When the server runs behing a proxy like NGINX, the de-facto standard is to use | ||
When the server runs behind a proxy like NGINX, the de-facto standard is to use | ||
the `X-Forwarded-For` header. | ||
@@ -295,3 +296,3 @@ | ||
Sometimes the link between the server and the client can be interrupted in a | ||
way that keeps both the server and the client unware of the broken state of the | ||
way that keeps both the server and the client unaware of the broken state of the | ||
connection (e.g. when pulling the cord). | ||
@@ -326,5 +327,10 @@ | ||
Pong messages are automatically sent in reponse to ping messages as required | ||
Pong messages are automatically sent in response to ping messages as required | ||
by the spec. | ||
### How to connect via a proxy? | ||
Use a custom `http.Agent` implementation like [https-proxy-agent][] or | ||
[socks-proxy-agent][]. | ||
## Changelog | ||
@@ -338,3 +344,5 @@ | ||
[https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent | ||
[socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent | ||
[permessage-deflate]: https://tools.ietf.org/html/rfc7692 | ||
[changelog]: https://github.com/websockets/ws/releases |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85686
2375
340
+ Addedsafe-buffer@5.1.2(transitive)
- Removedsafe-buffer@5.0.1(transitive)
Updatedsafe-buffer@~5.1.0