Comparing version 6.1.2 to 6.1.3
@@ -7,3 +7,3 @@ 'use strict'; | ||
const bufferUtil = require('./buffer-util'); | ||
const constants = require('./constants'); | ||
const { kStatusCode, NOOP } = require('./constants'); | ||
@@ -14,4 +14,2 @@ const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]); | ||
const kPerMessageDeflate = Symbol('permessage-deflate'); | ||
const kWriteInProgress = Symbol('write-in-progress'); | ||
const kPendingClose = Symbol('pending-close'); | ||
const kTotalLength = Symbol('total-length'); | ||
@@ -135,16 +133,9 @@ const kCallback = Symbol('callback'); | ||
if (this._inflate) { | ||
if (this._inflate[kWriteInProgress]) { | ||
this._inflate[kPendingClose] = true; | ||
} else { | ||
this._inflate.close(); | ||
this._inflate = null; | ||
} | ||
this._inflate.close(); | ||
this._inflate = null; | ||
} | ||
if (this._deflate) { | ||
if (this._deflate[kWriteInProgress]) { | ||
this._deflate[kPendingClose] = true; | ||
} else { | ||
this._deflate.close(); | ||
this._deflate = null; | ||
} | ||
this._deflate.close(); | ||
this._deflate = null; | ||
} | ||
@@ -361,3 +352,2 @@ } | ||
this._inflate[kCallback] = callback; | ||
this._inflate[kWriteInProgress] = true; | ||
@@ -382,10 +372,6 @@ this._inflate.write(data); | ||
if ( | ||
(fin && this.params[`${endpoint}_no_context_takeover`]) || | ||
this._inflate[kPendingClose] | ||
) { | ||
if (fin && this.params[`${endpoint}_no_context_takeover`]) { | ||
this._inflate.close(); | ||
this._inflate = null; | ||
} else { | ||
this._inflate[kWriteInProgress] = false; | ||
this._inflate[kTotalLength] = 0; | ||
@@ -430,13 +416,23 @@ this._inflate[kBuffers] = []; | ||
// | ||
// `zlib.DeflateRaw` emits an `'error'` event only when an attempt to use | ||
// it is made after it has already been closed. This cannot happen here, | ||
// so we only add a listener for the `'data'` event. | ||
// An `'error'` event is emitted, only on Node.js < 10.0.0, if the | ||
// `zlib.DeflateRaw` instance is closed while data is being processed. | ||
// This can happen if `PerMessageDeflate#cleanup()` is called at the wrong | ||
// time due to an abnormal WebSocket closure. | ||
// | ||
this._deflate.on('error', NOOP); | ||
this._deflate.on('data', deflateOnData); | ||
} | ||
this._deflate[kWriteInProgress] = true; | ||
this._deflate.write(data); | ||
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => { | ||
if (!this._deflate) { | ||
// | ||
// This `if` statement is only needed for Node.js < 10.0.0 because as of | ||
// commit https://github.com/nodejs/node/commit/5e3f5164, the flush | ||
// callback is no longer called if the deflate stream is closed while | ||
// data is being processed. | ||
// | ||
return; | ||
} | ||
var data = bufferUtil.concat( | ||
@@ -449,10 +445,6 @@ this._deflate[kBuffers], | ||
if ( | ||
(fin && this.params[`${endpoint}_no_context_takeover`]) || | ||
this._deflate[kPendingClose] | ||
) { | ||
if (fin && this.params[`${endpoint}_no_context_takeover`]) { | ||
this._deflate.close(); | ||
this._deflate = null; | ||
} else { | ||
this._deflate[kWriteInProgress] = false; | ||
this._deflate[kTotalLength] = 0; | ||
@@ -498,3 +490,3 @@ this._deflate[kBuffers] = []; | ||
this[kError] = new RangeError('Max payload size exceeded'); | ||
this[kError][constants.kStatusCode] = 1009; | ||
this[kError][kStatusCode] = 1009; | ||
this.removeListener('data', inflateOnData); | ||
@@ -516,4 +508,4 @@ this.reset(); | ||
this[kPerMessageDeflate]._inflate = null; | ||
err[constants.kStatusCode] = 1007; | ||
err[kStatusCode] = 1007; | ||
this[kCallback](err); | ||
} |
@@ -65,3 +65,3 @@ 'use strict'; | ||
_write(chunk, encoding, cb) { | ||
if (this._opcode === 0x08) return cb(); | ||
if (this._opcode === 0x08 && this._state == GET_INFO) return cb(); | ||
@@ -457,9 +457,8 @@ this._bufferedBytes += chunk.length; | ||
} | ||
return; | ||
} else if (this._opcode === 0x09) { | ||
this.emit('ping', data); | ||
} else { | ||
this.emit('pong', data); | ||
} | ||
if (this._opcode === 0x09) this.emit('ping', data); | ||
else this.emit('pong', data); | ||
this._state = GET_INFO; | ||
@@ -509,7 +508,7 @@ } | ||
* | ||
* @param {Buffer} The buffer to convert | ||
* @param {Buffer} buf The buffer to convert | ||
* @return {ArrayBuffer} Converted buffer | ||
*/ | ||
function toArrayBuffer(buf) { | ||
if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) { | ||
if (buf.byteLength === buf.buffer.byteLength) { | ||
return buf.buffer; | ||
@@ -516,0 +515,0 @@ } |
@@ -351,12 +351,2 @@ 'use strict'; | ||
this._deflating = false; | ||
if (!this._socket.readable && !this._socket.writable) { | ||
// | ||
// The socket is closed. Clear the queue and bail out. | ||
// | ||
this._bufferedBytes = 0; | ||
this._queue.length = 0; | ||
return; | ||
} | ||
options.readOnly = false; | ||
@@ -363,0 +353,0 @@ this.sendFrame(Sender.frame(buf, options), cb); |
@@ -90,3 +90,3 @@ 'use strict'; | ||
set binaryType(type) { | ||
if (constants.BINARY_TYPES.indexOf(type) < 0) return; | ||
if (!constants.BINARY_TYPES.includes(type)) return; | ||
@@ -371,3 +371,3 @@ this._binaryType = type; | ||
readyStates.forEach((readyState, i) => { | ||
WebSocket[readyStates[i]] = i; | ||
WebSocket[readyState] = i; | ||
}); | ||
@@ -454,3 +454,3 @@ | ||
if (protocolVersions.indexOf(options.protocolVersion) === -1) { | ||
if (!protocolVersions.includes(options.protocolVersion)) { | ||
throw new RangeError( | ||
@@ -507,2 +507,3 @@ `Unsupported protocol version: ${options.protocolVersion} ` + | ||
options.path = path; | ||
options.timeout = options.handshakeTimeout; | ||
@@ -545,5 +546,5 @@ if (options.perMessageDeflate) { | ||
if (options.handshakeTimeout) { | ||
req.setTimeout(options.handshakeTimeout, () => | ||
abortHandshake(this, req, 'Opening handshake has timed out') | ||
); | ||
req.on('timeout', () => { | ||
abortHandshake(this, req, 'Opening handshake has timed out'); | ||
}); | ||
} | ||
@@ -595,3 +596,3 @@ | ||
protError = 'Server sent no subprotocol'; | ||
} else if (serverProt && protList.indexOf(serverProt) === -1) { | ||
} else if (serverProt && !protList.includes(serverProt)) { | ||
protError = 'Server sent an invalid subprotocol'; | ||
@@ -598,0 +599,0 @@ } |
{ | ||
"name": "ws", | ||
"version": "6.1.2", | ||
"version": "6.1.3", | ||
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js", | ||
@@ -36,8 +36,8 @@ "keywords": [ | ||
"bufferutil": "~4.0.0", | ||
"eslint": "~5.9.0", | ||
"eslint-config-prettier": "~3.3.0", | ||
"eslint": "~5.12.0", | ||
"eslint-config-prettier": "~3.6.0", | ||
"eslint-plugin-prettier": "~3.0.0", | ||
"mocha": "~5.2.0", | ||
"nyc": "~13.1.0", | ||
"prettier": "~1.15.2", | ||
"prettier": "~1.16.1", | ||
"prettylint": "~1.0.0", | ||
@@ -44,0 +44,0 @@ "utf-8-validate": "~5.0.0" |
@@ -55,3 +55,3 @@ # ws: a Node.js WebSocket library | ||
``` | ||
npm install --save ws | ||
npm install ws | ||
``` | ||
@@ -58,0 +58,0 @@ |
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
100829
2787