Socket
Socket
Sign inDemoInstall

ws

Package Overview
Dependencies
3
Maintainers
4
Versions
164
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.16.0 to 8.17.0

56

lib/receiver.js

@@ -16,10 +16,3 @@ 'use strict';

const FastBuffer = Buffer[Symbol.species];
const promise = Promise.resolve();
//
// `queueMicrotask()` is not available in Node.js < 11.
//
const queueTask =
typeof queueMicrotask === 'function' ? queueMicrotask : queueMicrotaskShim;
const GET_INFO = 0;

@@ -43,3 +36,3 @@ const GET_PAYLOAD_LENGTH_16 = 1;

* @param {Object} [options] Options object
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted

@@ -59,3 +52,6 @@ * multiple times in the same tick

this._allowSynchronousEvents = !!options.allowSynchronousEvents;
this._allowSynchronousEvents =
options.allowSynchronousEvents !== undefined
? options.allowSynchronousEvents
: true;
this._binaryType = options.binaryType || BINARY_TYPES[0];

@@ -573,8 +569,3 @@ this._extensions = options.extensions || {};

//
// If the state is `INFLATING`, it means that the frame data was
// decompressed asynchronously, so there is no need to defer the event
// as it will be emitted asynchronously anyway.
//
if (this._state === INFLATING || this._allowSynchronousEvents) {
if (this._allowSynchronousEvents) {
this.emit('message', data, true);

@@ -584,3 +575,3 @@ this._state = GET_INFO;

this._state = DEFER_EVENT;
queueTask(() => {
setImmediate(() => {
this.emit('message', data, true);

@@ -612,3 +603,3 @@ this._state = GET_INFO;

this._state = DEFER_EVENT;
queueTask(() => {
setImmediate(() => {
this.emit('message', buf, false);

@@ -684,3 +675,3 @@ this._state = GET_INFO;

this._state = DEFER_EVENT;
queueTask(() => {
setImmediate(() => {
this.emit(this._opcode === 0x09 ? 'ping' : 'pong', data);

@@ -721,30 +712,1 @@ this._state = GET_INFO;

module.exports = Receiver;
/**
* A shim for `queueMicrotask()`.
*
* @param {Function} cb Callback
*/
function queueMicrotaskShim(cb) {
promise.then(cb).catch(throwErrorNextTick);
}
/**
* Throws an error.
*
* @param {Error} err The error to throw
* @private
*/
function throwError(err) {
throw err;
}
/**
* Throws an error in the next tick.
*
* @param {Error} err The error to throw
* @private
*/
function throwErrorNextTick(err) {
process.nextTick(throwError, err);
}

6

lib/websocket-server.js

@@ -1,2 +0,2 @@

/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex$" }] */
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex$", "caughtErrors": "none" }] */

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

* @param {Object} options Configuration options
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted

@@ -64,3 +64,3 @@ * multiple times in the same tick

options = {
allowSynchronousEvents: false,
allowSynchronousEvents: true,
autoPong: true,

@@ -67,0 +67,0 @@ maxPayload: 100 * 1024 * 1024,

@@ -1,2 +0,2 @@

/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex|Readable$" }] */
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex|Readable$", "caughtErrors": "none" }] */

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

* @param {Object} [options] Connection options
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether any
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether any
* of the `'message'`, `'ping'`, and `'pong'` events can be emitted multiple

@@ -656,3 +656,3 @@ * times in the same tick

const opts = {
allowSynchronousEvents: false,
allowSynchronousEvents: true,
autoPong: true,

@@ -666,3 +666,2 @@ protocolVersion: protocolVersions[1],

...options,
createConnection: undefined,
socketPath: undefined,

@@ -738,3 +737,4 @@ hostname: undefined,

opts.createConnection = isSecure ? tlsConnect : netConnect;
opts.createConnection =
opts.createConnection || (isSecure ? tlsConnect : netConnect);
opts.defaultPort = opts.defaultPort || defaultPort;

@@ -741,0 +741,0 @@ opts.port = parsedUrl.port || defaultPort;

{
"name": "ws",
"version": "8.16.0",
"version": "8.17.0",
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js",

@@ -43,3 +43,3 @@ "keywords": [

"integration": "mocha --throw-deprecation test/*.integration.js",
"lint": "eslint --ignore-path .gitignore . && prettier --check --ignore-path .gitignore \"**/*.{json,md,yaml,yml}\""
"lint": "eslint . && prettier --check --ignore-path .gitignore \"**/*.{json,md,yaml,yml}\""
},

@@ -61,5 +61,6 @@ "peerDependencies": {

"bufferutil": "^4.0.1",
"eslint": "^8.0.0",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"globals": "^15.0.0",
"mocha": "^8.4.0",

@@ -66,0 +67,0 @@ "nyc": "^15.0.0",

@@ -14,4 +14,4 @@ # ws: a Node.js WebSocket library

**Note**: This module does not work in the browser. The client in the docs is a
reference to a back end with the role of a client in the WebSocket
communication. Browser clients must use the native
reference to a backend with the role of a client in the WebSocket communication.
Browser clients must use the native
[`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)

@@ -91,3 +91,3 @@ object. To make the same code work seamlessly on Node.js and the browser, you

To force ws to not use utf-8-validate, use the
To force ws not to use utf-8-validate, use the
[`WS_NO_UTF_8_VALIDATE`](./doc/ws.md#ws_no_utf_8_validate) environment variable.

@@ -151,3 +151,3 @@

The client will only use the extension if it is supported and enabled on the
server. To always disable the extension on the client set the
server. To always disable the extension on the client, set the
`perMessageDeflate` option to `false`.

@@ -251,3 +251,2 @@

import { createServer } from 'http';
import { parse } from 'url';
import { WebSocketServer } from 'ws';

@@ -272,3 +271,3 @@

server.on('upgrade', function upgrade(request, socket, head) {
const { pathname } = parse(request.url);
const { pathname } = new URL(request.url, 'wss://base.url');

@@ -460,7 +459,7 @@ if (pathname === '/foo') {

Sometimes the link between the server and the client can be interrupted in a way
that keeps both the server and the client unaware of the broken state of the
Sometimes, the link between the server and the client can be interrupted in a
way that keeps both the server and the client unaware of the broken state of the
connection (e.g. when pulling the cord).
In these cases ping messages can be used as a means to verify that the remote
In these cases, ping messages can be used as a means to verify that the remote
endpoint is still responsive.

@@ -500,3 +499,3 @@

Just like the server example above your clients might as well lose connection
Just like the server example above, your clients might as well lose connection
without knowing it. You might want to add a ping listener on your clients to

@@ -503,0 +502,0 @@ prevent that. A simple implementation would be:

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc