Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ws

Package Overview
Dependencies
Maintainers
4
Versions
169
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ws - npm Package Compare versions

Comparing version 7.0.1 to 7.1.0

lib/stream.js

1

index.js

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

WebSocket.createWebSocketStream = require('./lib/stream');
WebSocket.Server = require('./lib/websocket-server');

@@ -7,0 +8,0 @@ WebSocket.Receiver = require('./lib/receiver');

6

lib/websocket.js

@@ -904,4 +904,6 @@ 'use strict';

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

@@ -37,4 +37,4 @@ "keywords": [

"coveralls": "^3.0.3",
"eslint": "^5.16.0",
"eslint-config-prettier": "^5.0.0",
"eslint": "^6.0.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-prettier": "^3.0.1",

@@ -41,0 +41,0 @@ "mocha": "^6.1.3",

@@ -37,2 +37,3 @@ # ws: a Node.js WebSocket library

- [echo.websocket.org demo](#echowebsocketorg-demo)
- [Use the Node.js streams API](#use-the-nodejs-streams-api)
- [Other examples](#other-examples)

@@ -73,3 +74,4 @@ - [FAQ](#faq)

See [`/doc/ws.md`](./doc/ws.md) for Node.js-like docs for the ws classes.
See [`/doc/ws.md`](./doc/ws.md) for Node.js-like documentation of ws classes and
utility functions.

@@ -254,2 +256,5 @@ ## WebSocket compression

A client WebSocket broadcasting to all connected WebSocket clients, including
itself.
```js

@@ -260,14 +265,23 @@ const WebSocket = require('ws');

// Broadcast to all.
wss.broadcast = function broadcast(data) {
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(data);
}
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(data) {
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
});
};
});
```
A client WebSocket broadcasting to every other connected WebSocket clients,
excluding itself.
```js
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(data) {
// Broadcast to everyone else.
wss.clients.forEach(function each(client) {

@@ -309,2 +323,17 @@ if (client !== ws && client.readyState === WebSocket.OPEN) {

### Use the Node.js streams API
```js
const WebSocket = require('ws');
const ws = new WebSocket('wss://echo.websocket.org/', {
origin: 'https://websocket.org'
});
const duplex = WebSocket.createWebSocketStream(ws, { encoding: 'utf8' });
duplex.pipe(process.stdout);
process.stdin.pipe(duplex);
```
### Other examples

@@ -390,5 +419,6 @@

// Use `WebSocket#terminate()` and not `WebSocket#close()`. Delay should be
// equal to the interval at which your server sends out pings plus a
// conservative assumption of the latency.
// Use `WebSocket#terminate()`, which immediately destroys the connection,
// instead of `WebSocket#close()`, which waits for the close timer.
// Delay should be equal to the interval at which your server
// sends out pings plus a conservative assumption of the latency.
this.pingTimeout = setTimeout(() => {

@@ -395,0 +425,0 @@ this.terminate();

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc