Socket
Socket
Sign inDemoInstall

ws

Package Overview
Dependencies
3
Maintainers
4
Versions
168
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.3.1 to 7.4.0

29

lib/event-target.js

@@ -13,3 +13,4 @@ 'use strict';

* @param {String} type The name of the event
* @param {Object} target A reference to the target to which the event was dispatched
* @param {Object} target A reference to the target to which the event was
* dispatched
*/

@@ -33,3 +34,4 @@ constructor(type, target) {

* @param {(String|Buffer|ArrayBuffer|Buffer[])} data The received data
* @param {WebSocket} target A reference to the target to which the event was dispatched
* @param {WebSocket} target A reference to the target to which the event was
* dispatched
*/

@@ -53,5 +55,8 @@ constructor(data, target) {

*
* @param {Number} code The status code explaining why the connection is being closed
* @param {String} reason A human-readable string explaining why the connection is closing
* @param {WebSocket} target A reference to the target to which the event was dispatched
* @param {Number} code The status code explaining why the connection is being
* closed
* @param {String} reason A human-readable string explaining why the
* connection is closing
* @param {WebSocket} target A reference to the target to which the event was
* dispatched
*/

@@ -77,3 +82,4 @@ constructor(code, reason, target) {

*
* @param {WebSocket} target A reference to the target to which the event was dispatched
* @param {WebSocket} target A reference to the target to which the event was
* dispatched
*/

@@ -96,3 +102,4 @@ constructor(target) {

* @param {Object} error The error that generated this event
* @param {WebSocket} target A reference to the target to which the event was dispatched
* @param {WebSocket} target A reference to the target to which the event was
* dispatched
*/

@@ -119,7 +126,7 @@ constructor(error, target) {

* @param {Function} listener The listener to add
* @param {Object} options An options object specifies characteristics about
* @param {Object} [options] An options object specifies characteristics about
* the event listener
* @param {Boolean} options.once A `Boolean`` indicating that the listener
* should be invoked at most once after being added. If `true`, the
* listener would be automatically removed when invoked.
* @param {Boolean} [options.once=false] A `Boolean`` indicating that the
* listener should be invoked at most once after being added. If `true`,
* the listener would be automatically removed when invoked.
* @public

@@ -126,0 +133,0 @@ */

@@ -14,4 +14,4 @@ 'use strict';

*
* @param {Number} concurrency The maximum number of jobs allowed to run
* concurrently
* @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
* to run concurrently
*/

@@ -31,2 +31,3 @@ constructor(concurrency) {

*
* @param {Function} job The job to run
* @public

@@ -33,0 +34,0 @@ */

@@ -32,20 +32,22 @@ 'use strict';

*
* @param {Object} options Configuration options
* @param {Boolean} options.serverNoContextTakeover Request/accept disabling
* of server context takeover
* @param {Boolean} options.clientNoContextTakeover Advertise/acknowledge
* disabling of client context takeover
* @param {(Boolean|Number)} options.serverMaxWindowBits Request/confirm the
* @param {Object} [options] Configuration options
* @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
* disabling of server context takeover
* @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
* acknowledge disabling of client context takeover
* @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
* use of a custom server window size
* @param {(Boolean|Number)} options.clientMaxWindowBits Advertise support
* @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
* for, or request, a custom client window size
* @param {Object} options.zlibDeflateOptions Options to pass to zlib on deflate
* @param {Object} options.zlibInflateOptions Options to pass to zlib on inflate
* @param {Number} options.threshold Size (in bytes) below which messages
* should not be compressed
* @param {Number} options.concurrencyLimit The number of concurrent calls to
* zlib
* @param {Boolean} isServer Create the instance in either server or client
* mode
* @param {Number} maxPayload The maximum allowed message length
* @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
* deflate
* @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
* inflate
* @param {Number} [options.threshold=1024] Size (in bytes) below which
* messages should not be compressed
* @param {Number} [options.concurrencyLimit=10] The number of concurrent
* calls to zlib
* @param {Boolean} [isServer=false] Create the instance in either server or
* client mode
* @param {Number} [maxPayload=0] The maximum allowed message length
*/

@@ -52,0 +54,0 @@ constructor(options, isServer, maxPayload) {

@@ -31,7 +31,7 @@ 'use strict';

*
* @param {String} binaryType The type for binary data
* @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
* @param {String} [binaryType=nodebuffer] The type for binary data
* @param {Object} [extensions] An object containing the negotiated extensions
* @param {Boolean} [isServer=false] Specifies whether to operate in client or
* server mode
* @param {Number} [maxPayload=0] The maximum allowed message length
*/

@@ -38,0 +38,0 @@ constructor(binaryType, extensions, isServer, maxPayload) {

@@ -20,3 +20,3 @@ 'use strict';

* @param {net.Socket} socket The connection socket
* @param {Object} extensions An object containing the negotiated extensions
* @param {Object} [extensions] An object containing the negotiated extensions
*/

@@ -41,6 +41,10 @@ constructor(socket, extensions) {

* @param {Number} options.opcode The opcode
* @param {Boolean} options.readOnly Specifies whether `data` can be modified
* @param {Boolean} options.fin Specifies whether or not to set the FIN bit
* @param {Boolean} options.mask Specifies whether or not to mask `data`
* @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
* modified
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
* FIN bit
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
* `data`
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
* RSV1 bit
* @return {Buffer[]} The framed data as a list of `Buffer` instances

@@ -98,6 +102,6 @@ * @public

*
* @param {(Number|undefined)} code The status code component of the body
* @param {String} data The message component of the body
* @param {Boolean} mask Specifies whether or not to mask the message
* @param {Function} cb Callback
* @param {Number} [code] The status code component of the body
* @param {String} [data] The message component of the body
* @param {Boolean} [mask=false] Specifies whether or not to mask the message
* @param {Function} [cb] Callback
* @public

@@ -138,4 +142,4 @@ */

* @param {Buffer} data The message to send
* @param {Boolean} mask Specifies whether or not to mask `data`
* @param {Function} cb Callback
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
* @param {Function} [cb] Callback
* @private

@@ -160,4 +164,4 @@ */

* @param {*} data The message to send
* @param {Boolean} mask Specifies whether or not to mask `data`
* @param {Function} cb Callback
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
* @param {Function} [cb] Callback
* @public

@@ -183,5 +187,5 @@ */

* @param {Buffer} data The message to send
* @param {Boolean} mask Specifies whether or not to mask `data`
* @param {Boolean} readOnly Specifies whether `data` can be modified
* @param {Function} cb Callback
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
* @param {Boolean} [readOnly=false] Specifies whether `data` can be modified
* @param {Function} [cb] Callback
* @private

@@ -206,4 +210,4 @@ */

* @param {*} data The message to send
* @param {Boolean} mask Specifies whether or not to mask `data`
* @param {Function} cb Callback
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
* @param {Function} [cb] Callback
* @public

@@ -229,5 +233,5 @@ */

* @param {Buffer} data The message to send
* @param {Boolean} mask Specifies whether or not to mask `data`
* @param {Boolean} readOnly Specifies whether `data` can be modified
* @param {Function} cb Callback
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
* @param {Boolean} [readOnly=false] Specifies whether `data` can be modified
* @param {Function} [cb] Callback
* @private

@@ -253,7 +257,11 @@ */

* @param {Object} options Options object
* @param {Boolean} options.compress Specifies whether or not to compress `data`
* @param {Boolean} options.binary Specifies whether `data` is binary or text
* @param {Boolean} options.fin Specifies whether the fragment is the last one
* @param {Boolean} options.mask Specifies whether or not to mask `data`
* @param {Function} cb Callback
* @param {Boolean} [options.compress=false] Specifies whether or not to
* compress `data`
* @param {Boolean} [options.binary=false] Specifies whether `data` is binary
* or text
* @param {Boolean} [options.fin=false] Specifies whether the fragment is the
* last one
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
* `data`
* @param {Function} [cb] Callback
* @public

@@ -312,10 +320,15 @@ */

* @param {Buffer} data The message to send
* @param {Boolean} compress Specifies whether or not to compress `data`
* @param {Boolean} [compress=false] Specifies whether or not to compress
* `data`
* @param {Object} options Options object
* @param {Number} options.opcode The opcode
* @param {Boolean} options.readOnly Specifies whether `data` can be modified
* @param {Boolean} options.fin Specifies whether or not to set the FIN bit
* @param {Boolean} options.mask Specifies whether or not to mask `data`
* @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit
* @param {Function} cb Callback
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
* modified
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
* FIN bit
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
* `data`
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
* RSV1 bit
* @param {Function} [cb] Callback
* @private

@@ -387,3 +400,3 @@ */

* @param {Buffer[]} list The frame to send
* @param {Function} cb Callback
* @param {Function} [cb] Callback
* @private

@@ -390,0 +403,0 @@ */

@@ -29,2 +29,3 @@ 'use strict';

*
* @param {Error} err The error
* @private

@@ -45,3 +46,3 @@ */

* @param {WebSocket} ws The `WebSocket` to wrap
* @param {Object} options The options for the `Duplex` constructor
* @param {Object} [options] The options for the `Duplex` constructor
* @return {stream.Duplex} The duplex stream

@@ -48,0 +49,0 @@ * @public

@@ -24,17 +24,18 @@ 'use strict';

* @param {Object} options Configuration options
* @param {Number} options.backlog The maximum length of the queue of pending
* connections
* @param {Boolean} options.clientTracking Specifies whether or not to track
* clients
* @param {Function} options.handleProtocols A hook to handle protocols
* @param {String} options.host The hostname where to bind the server
* @param {Number} options.maxPayload The maximum allowed message size
* @param {Boolean} options.noServer Enable no server mode
* @param {String} options.path Accept only connections matching this path
* @param {(Boolean|Object)} options.perMessageDeflate Enable/disable
* @param {Number} [options.backlog=511] The maximum length of the queue of
* pending connections
* @param {Boolean} [options.clientTracking=true] Specifies whether or not to
* track clients
* @param {Function} [options.handleProtocols] A hook to handle protocols
* @param {String} [options.host] The hostname where to bind the server
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
* size
* @param {Boolean} [options.noServer=false] Enable no server mode
* @param {String} [options.path] Accept only connections matching this path
* @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
* permessage-deflate
* @param {Number} options.port The port where to bind the server
* @param {http.Server} options.server A pre-created HTTP/S server to use
* @param {Function} options.verifyClient A hook to reject connections
* @param {Function} callback A listener for the `listening` event
* @param {Number} [options.port] The port where to bind the server
* @param {http.Server} [options.server] A pre-created HTTP/S server to use
* @param {Function} [options.verifyClient] A hook to reject connections
* @param {Function} [callback] A listener for the `listening` event
*/

@@ -86,2 +87,4 @@ constructor(options, callback) {

if (this._server) {
const emitConnection = this.emit.bind(this, 'connection');
this._removeListeners = addListeners(this._server, {

@@ -91,5 +94,3 @@ listening: this.emit.bind(this, 'listening'),

upgrade: (req, socket, head) => {
this.handleUpgrade(req, socket, head, (ws) => {
this.emit('connection', ws, req);
});
this.handleUpgrade(req, socket, head, emitConnection);
}

@@ -125,3 +126,3 @@ });

*
* @param {Function} cb Callback
* @param {Function} [cb] Callback
* @public

@@ -305,3 +306,3 @@ */

headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
ws.protocol = protocol;
ws._protocol = protocol;
}

@@ -334,3 +335,3 @@ }

cb(ws);
cb(ws, req);
}

@@ -347,3 +348,4 @@ }

* @param {Object.<String, Function>} map The listeners to add
* @return {Function} A function that will remove the added listeners when called
* @return {Function} A function that will remove the added listeners when
* called
* @private

@@ -350,0 +352,0 @@ */

@@ -40,4 +40,4 @@ 'use strict';

* @param {(String|url.URL)} address The URL to which to connect
* @param {(String|String[])} protocols The subprotocols
* @param {Object} options Connection options
* @param {(String|String[])} [protocols] The subprotocols
* @param {Object} [options] Connection options
*/

@@ -47,6 +47,4 @@ constructor(address, protocols, options) {

this.readyState = WebSocket.CONNECTING;
this.protocol = '';
this._binaryType = BINARY_TYPES[0];
this._closeCode = 1006;
this._closeFrameReceived = false;

@@ -56,4 +54,5 @@ this._closeFrameSent = false;

this._closeTimer = null;
this._closeCode = 1006;
this._extensions = {};
this._protocol = '';
this._readyState = WebSocket.CONNECTING;
this._receiver = null;

@@ -81,15 +80,2 @@ this._sender = null;

get CONNECTING() {
return WebSocket.CONNECTING;
}
get CLOSING() {
return WebSocket.CLOSING;
}
get CLOSED() {
return WebSocket.CLOSED;
}
get OPEN() {
return WebSocket.OPEN;
}
/**

@@ -134,2 +120,23 @@ * This deviates from the WHATWG interface since ws doesn't support the

/**
* @type {String}
*/
get protocol() {
return this._protocol;
}
/**
* @type {Number}
*/
get readyState() {
return this._readyState;
}
/**
* @type {String}
*/
get url() {
return this._url;
}
/**
* Set up the socket and the internal resources.

@@ -139,3 +146,3 @@ *

* @param {Buffer} head The first packet of the upgraded stream
* @param {Number} maxPayload The maximum allowed message size
* @param {Number} [maxPayload=0] The maximum allowed message size
* @private

@@ -145,3 +152,3 @@ */

const receiver = new Receiver(
this._binaryType,
this.binaryType,
this._extensions,

@@ -176,3 +183,3 @@ this._isServer,

this.readyState = WebSocket.OPEN;
this._readyState = WebSocket.OPEN;
this.emit('open');

@@ -188,3 +195,3 @@ }

if (!this._socket) {
this.readyState = WebSocket.CLOSED;
this._readyState = WebSocket.CLOSED;
this.emit('close', this._closeCode, this._closeMessage);

@@ -199,3 +206,3 @@ return;

this._receiver.removeAllListeners();
this.readyState = WebSocket.CLOSED;
this._readyState = WebSocket.CLOSED;
this.emit('close', this._closeCode, this._closeMessage);

@@ -219,4 +226,4 @@ }

*
* @param {Number} code Status code explaining why the connection is closing
* @param {String} data A string explaining why the connection is closing
* @param {Number} [code] Status code explaining why the connection is closing
* @param {String} [data] A string explaining why the connection is closing
* @public

@@ -236,3 +243,3 @@ */

this.readyState = WebSocket.CLOSING;
this._readyState = WebSocket.CLOSING;
this._sender.close(code, data, !this._isServer, (err) => {

@@ -261,5 +268,5 @@ //

*
* @param {*} data The data to send
* @param {Boolean} mask Indicates whether or not to mask `data`
* @param {Function} cb Callback which is executed when the ping is sent
* @param {*} [data] The data to send
* @param {Boolean} [mask] Indicates whether or not to mask `data`
* @param {Function} [cb] Callback which is executed when the ping is sent
* @public

@@ -294,5 +301,5 @@ */

*
* @param {*} data The data to send
* @param {Boolean} mask Indicates whether or not to mask `data`
* @param {Function} cb Callback which is executed when the pong is sent
* @param {*} [data] The data to send
* @param {Boolean} [mask] Indicates whether or not to mask `data`
* @param {Function} [cb] Callback which is executed when the pong is sent
* @public

@@ -328,9 +335,11 @@ */

* @param {*} data The message to send
* @param {Object} options Options object
* @param {Boolean} options.compress Specifies whether or not to compress
* @param {Object} [options] Options object
* @param {Boolean} [options.compress] Specifies whether or not to compress
* `data`
* @param {Boolean} options.binary Specifies whether `data` is binary or text
* @param {Boolean} options.fin Specifies whether the fragment is the last one
* @param {Boolean} options.mask Specifies whether or not to mask `data`
* @param {Function} cb Callback which is executed when data is written out
* @param {Boolean} [options.binary] Specifies whether `data` is binary or
* text
* @param {Boolean} [options.fin=true] Specifies whether the fragment is the
* last one
* @param {Boolean} [options.mask] Specifies whether or not to mask `data`
* @param {Function} [cb] Callback which is executed when data is written out
* @public

@@ -383,3 +392,3 @@ */

if (this._socket) {
this.readyState = WebSocket.CLOSING;
this._readyState = WebSocket.CLOSING;
this._socket.destroy();

@@ -391,5 +400,19 @@ }

readyStates.forEach((readyState, i) => {
WebSocket[readyState] = i;
const descriptor = { enumerable: true, value: i };
Object.defineProperty(WebSocket.prototype, readyState, descriptor);
Object.defineProperty(WebSocket, readyState, descriptor);
});
[
'binaryType',
'bufferedAmount',
'extensions',
'protocol',
'readyState',
'url'
].forEach((property) => {
Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
});
//

@@ -401,2 +424,4 @@ // Add the `onopen`, `onerror`, `onclose`, and `onmessage` attributes.

Object.defineProperty(WebSocket.prototype, `on${method}`, {
configurable: true,
enumerable: true,
/**

@@ -445,15 +470,18 @@ * Return the listener of the event.

* @param {(String|url.URL)} address The URL to which to connect
* @param {String} protocols The subprotocols
* @param {Object} options Connection options
* @param {(Boolean|Object)} options.perMessageDeflate Enable/disable
* @param {String} [protocols] The subprotocols
* @param {Object} [options] Connection options
* @param {(Boolean|Object)} [options.perMessageDeflate=true] Enable/disable
* permessage-deflate
* @param {Number} options.handshakeTimeout Timeout in milliseconds for the
* @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
* handshake request
* @param {Number} options.protocolVersion Value of the `Sec-WebSocket-Version`
* header
* @param {String} options.origin Value of the `Origin` or
* @param {Number} [options.protocolVersion=13] Value of the
* `Sec-WebSocket-Version` header
* @param {String} [options.origin] Value of the `Origin` or
* `Sec-WebSocket-Origin` header
* @param {Number} options.maxPayload The maximum allowed message size
* @param {Boolean} options.followRedirects Whether or not to follow redirects
* @param {Number} options.maxRedirects The maximum number of redirects allowed
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
* size
* @param {Boolean} [options.followRedirects=false] Whether or not to follow
* redirects
* @param {Number} [options.maxRedirects=10] The maximum number of redirects
* allowed
* @private

@@ -491,6 +519,6 @@ */

parsedUrl = address;
websocket.url = address.href;
websocket._url = address.href;
} else {
parsedUrl = new URL(address);
websocket.url = address;
websocket._url = address;
}

@@ -570,3 +598,3 @@

req = websocket._req = null;
websocket.readyState = WebSocket.CLOSING;
websocket._readyState = WebSocket.CLOSING;
websocket.emit('error', err);

@@ -642,3 +670,3 @@ websocket.emitClose();

if (serverProt) websocket.protocol = serverProt;
if (serverProt) websocket._protocol = serverProt;

@@ -708,3 +736,3 @@ if (perMessageDeflate) {

function abortHandshake(websocket, stream, message) {
websocket.readyState = WebSocket.CLOSING;
websocket._readyState = WebSocket.CLOSING;

@@ -730,4 +758,4 @@ const err = new Error(message);

* @param {WebSocket} websocket The WebSocket instance
* @param {*} data The data to send
* @param {Function} cb Callback
* @param {*} [data] The data to send
* @param {Function} [cb] Callback
* @private

@@ -799,3 +827,3 @@ */

websocket.readyState = WebSocket.CLOSING;
websocket._readyState = WebSocket.CLOSING;
websocket._closeCode = err[kStatusCode];

@@ -859,3 +887,3 @@ websocket.emit('error', err);

websocket.readyState = WebSocket.CLOSING;
websocket._readyState = WebSocket.CLOSING;

@@ -911,3 +939,3 @@ //

websocket.readyState = WebSocket.CLOSING;
websocket._readyState = WebSocket.CLOSING;
websocket._receiver.end();

@@ -929,5 +957,5 @@ this.end();

if (websocket) {
websocket.readyState = WebSocket.CLOSING;
websocket._readyState = WebSocket.CLOSING;
this.destroy();
}
}
{
"name": "ws",
"version": "7.3.1",
"version": "7.4.0",
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc