Socket
Socket
Sign inDemoInstall

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.1.1 to 7.1.2

16

lib/permessage-deflate.js

@@ -136,2 +136,6 @@ 'use strict';

if (this._deflate) {
if (this._deflate[kCallback]) {
this._deflate[kCallback]();
}
this._deflate.close();

@@ -316,3 +320,5 @@ this._deflate = null;

done();
callback(err, result);
if (err || result) {
callback(err, result);
}
});

@@ -424,2 +430,4 @@ });

this._deflate[kCallback] = callback;
this._deflate.write(data);

@@ -444,2 +452,8 @@ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {

//
// Ensure that the callback will not be called again in
// `PerMessageDeflate#cleanup()`.
//
this._deflate[kCallback] = null;
if (fin && this.params[`${endpoint}_no_context_takeover`]) {

@@ -446,0 +460,0 @@ this._deflate.close();

17

lib/websocket-server.js

@@ -82,14 +82,13 @@ 'use strict';

} else if (options.server) {
this._server = options.server;
}
if (this._server) {
if (this._server[kUsedByWebSocketServer]) {
if (options.server[kUsedByWebSocketServer]) {
throw new Error(
'The HTTP/S server is already being used by another WebSocket server'
);
} else {
this._server[kUsedByWebSocketServer] = true;
}
options.server[kUsedByWebSocketServer] = true;
this._server = options.server;
}
if (this._server) {
this._removeListeners = addListeners(this._server, {

@@ -148,4 +147,2 @@ listening: this.emit.bind(this, 'listening'),

if (server) {
server[kUsedByWebSocketServer] = false;
this._removeListeners();

@@ -161,2 +158,4 @@ this._removeListeners = this._server = null;

}
delete server[kUsedByWebSocketServer];
}

@@ -163,0 +162,0 @@

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

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

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

- [Multiple servers sharing a single HTTP/S server](#multiple-servers-sharing-a-single-https-server)
- [Client authentication](#client-authentication)
- [Server broadcast](#server-broadcast)

@@ -253,2 +254,35 @@ - [echo.websocket.org demo](#echowebsocketorg-demo)

### Client authentication
```js
const http = require('http');
const WebSocket = require('ws');
const server = http.createServer();
const wss = new WebSocket.Server({ noServer: true });
wss.on('connection', function connection(ws, request, client) {
ws.on('message', function message(msg) {
console.log(`Received message ${msg} from user ${client}`);
});
});
server.on('upgrade', function upgrade(request, socket, head) {
authenticate(request, (err, client) => {
if (err || !client) {
socket.destroy();
return;
}
wss.handleUpgrade(request, socket, head, function done(ws) {
wss.emit('connection', ws, request, client);
});
});
});
server.listen(8080);
```
Also see the provided [example][session-parse-example] using `express-session`.
### Server broadcast

@@ -447,12 +481,13 @@

[changelog]: https://github.com/websockets/ws/releases
[client-report]: http://websockets.github.io/ws/autobahn/clients/
[https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent
[socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent
[client-report]: http://websockets.github.io/ws/autobahn/clients/
[server-report]: http://websockets.github.io/ws/autobahn/servers/
[permessage-deflate]: https://tools.ietf.org/html/rfc7692
[changelog]: https://github.com/websockets/ws/releases
[node-zlib-bug]: https://github.com/nodejs/node/issues/8871
[node-zlib-deflaterawdocs]:
https://nodejs.org/api/zlib.html#zlib_zlib_createdeflateraw_options
[permessage-deflate]: https://tools.ietf.org/html/rfc7692
[server-report]: http://websockets.github.io/ws/autobahn/servers/
[session-parse-example]: ./examples/express-session-parse
[socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent
[ws-server-options]:
https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback
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