Comparing version 7.2.1 to 7.2.2
@@ -134,8 +134,14 @@ 'use strict'; | ||
if (this._deflate) { | ||
if (this._deflate[kCallback]) { | ||
this._deflate[kCallback](); | ||
} | ||
const callback = this._deflate[kCallback]; | ||
this._deflate.close(); | ||
this._deflate = null; | ||
if (callback) { | ||
callback( | ||
new Error( | ||
'The deflate stream was closed while data was being processed' | ||
) | ||
); | ||
} | ||
} | ||
@@ -318,5 +324,3 @@ } | ||
done(); | ||
if (err || result) { | ||
callback(err, result); | ||
} | ||
callback(err, result); | ||
}); | ||
@@ -429,6 +433,3 @@ }); | ||
// | ||
// 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. | ||
// The deflate stream was closed while data was being processed. | ||
// | ||
@@ -435,0 +436,0 @@ return; |
@@ -33,5 +33,7 @@ 'use strict'; | ||
* @param {Object} extensions An object containing the negotiated extensions | ||
* @param {Boolean} isServer Specifies whether to operate in client or server | ||
* mode | ||
* @param {Number} maxPayload The maximum allowed message length | ||
*/ | ||
constructor(binaryType, extensions, maxPayload) { | ||
constructor(binaryType, extensions, isServer, maxPayload) { | ||
super(); | ||
@@ -42,2 +44,3 @@ | ||
this._extensions = extensions || {}; | ||
this._isServer = !!isServer; | ||
this._maxPayload = maxPayload | 0; | ||
@@ -230,2 +233,12 @@ | ||
if (this._isServer) { | ||
if (!this._masked) { | ||
this._loop = false; | ||
return error(RangeError, 'MASK must be set', true, 1002); | ||
} | ||
} else if (this._masked) { | ||
this._loop = false; | ||
return error(RangeError, 'MASK must be clear', true, 1002); | ||
} | ||
if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16; | ||
@@ -232,0 +245,0 @@ else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64; |
@@ -309,2 +309,18 @@ 'use strict'; | ||
perMessageDeflate.compress(data, options.fin, (_, buf) => { | ||
if (this._socket.destroyed) { | ||
const err = new Error( | ||
'The socket was closed while data was being compressed' | ||
); | ||
if (typeof cb === 'function') cb(err); | ||
for (let i = 0; i < this._queue.length; i++) { | ||
const callback = this._queue[i][4]; | ||
if (typeof callback === 'function') callback(err); | ||
} | ||
return; | ||
} | ||
this._deflating = false; | ||
@@ -311,0 +327,0 @@ options.readOnly = false; |
@@ -81,2 +81,4 @@ 'use strict'; | ||
ws.once('error', function error(err) { | ||
if (duplex.destroyed) return; | ||
duplex.destroy(err); | ||
@@ -98,4 +100,11 @@ }); | ||
let called = false; | ||
ws.once('error', function error(err) { | ||
called = true; | ||
callback(err); | ||
}); | ||
ws.once('close', function close() { | ||
callback(err); | ||
if (!called) callback(err); | ||
process.nextTick(emitClose, duplex); | ||
@@ -114,2 +123,8 @@ }); | ||
// If the value of the `_socket` property is `null` it means that `ws` is a | ||
// client websocket and the handshake failed. In fact, when this happens, a | ||
// socket is never assigned to the websocket. Wait for the `'error'` event | ||
// that will be emitted by the websocket. | ||
if (ws._socket === null) return; | ||
if (ws._socket._writableState.finished) { | ||
@@ -122,3 +137,3 @@ if (duplex._readableState.endEmitted) duplex.destroy(); | ||
// emitted on `duplex` after this `'finish'` event. The EOF signaling | ||
// `null` chunk is, in fact, pushed when the WebSocket emits `'close'`. | ||
// `null` chunk is, in fact, pushed when the websocket emits `'close'`. | ||
callback(); | ||
@@ -125,0 +140,0 @@ }); |
@@ -24,3 +24,3 @@ 'use strict'; | ||
(code >= 1000 && | ||
code <= 1013 && | ||
code <= 1014 && | ||
code !== 1004 && | ||
@@ -27,0 +27,0 @@ code !== 1005 && |
@@ -144,2 +144,3 @@ 'use strict'; | ||
this._extensions, | ||
this._isServer, | ||
maxPayload | ||
@@ -182,5 +183,4 @@ ); | ||
emitClose() { | ||
this.readyState = WebSocket.CLOSED; | ||
if (!this._socket) { | ||
this.readyState = WebSocket.CLOSED; | ||
this.emit('close', this._closeCode, this._closeMessage); | ||
@@ -195,2 +195,3 @@ return; | ||
this._receiver.removeAllListeners(); | ||
this.readyState = WebSocket.CLOSED; | ||
this.emit('close', this._closeCode, this._closeMessage); | ||
@@ -197,0 +198,0 @@ } |
{ | ||
"name": "ws", | ||
"version": "7.2.1", | ||
"version": "7.2.2", | ||
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js", | ||
@@ -52,4 +52,4 @@ "keywords": [ | ||
"eslint-plugin-prettier": "^3.0.1", | ||
"mocha": "^6.1.3", | ||
"nyc": "^14.0.0", | ||
"mocha": "^7.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.17.0", | ||
@@ -56,0 +56,0 @@ "utf-8-validate": "^5.0.2" |
@@ -433,2 +433,6 @@ # ws: a Node.js WebSocket library | ||
}, 30000); | ||
wss.on('close', function close() { | ||
clearInterval(interval); | ||
}); | ||
``` | ||
@@ -435,0 +439,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
109439
3063
495