Gathering detailed insights and metrics for @httptoolkit/websocket-stream
Gathering detailed insights and metrics for @httptoolkit/websocket-stream
Gathering detailed insights and metrics for @httptoolkit/websocket-stream
Gathering detailed insights and metrics for @httptoolkit/websocket-stream
@httptoolkit/subscriptions-transport-ws
A websocket transport for GraphQL subscriptions
websocket-driver
WebSocket protocol handler with pluggable I/O
websocket-stream
Use websockets with the node streams API. Works in browser and node
@httptoolkit/httpolyglot
Serve http and https connections over the same port with node.js
websockets with the node stream API
npm install @httptoolkit/websocket-stream
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3 Stars
234 Commits
3 Forks
3 Watching
2 Branches
29 Contributors
Updated on 09 May 2023
Minified
Minified + Gzipped
JavaScript (91.21%)
TypeScript (8.79%)
Cumulative downloads
Total Downloads
Last day
4.3%
105,296
Compared to previous day
Last week
9.4%
555,191
Compared to previous week
Last month
12.5%
2,195,323
Compared to previous month
Last year
30%
21,444,663
Compared to previous year
Part of HTTP Toolkit: powerful tools for building, testing & debugging HTTP(S)
Use HTML5 websockets using the Node Streams API.
This is a fork of the original websocket-stream (now unmaintained), for use in HTTP Toolkit. This fork:
This module works in Node or in Browsers that support WebSockets. You can use browserify to package this module for browser use.
1var websocket = require('@httptoolkit/websocket-stream') 2var ws = websocket('ws://echo.websocket.org') 3process.stdin.pipe(ws) 4ws.pipe(process.stdout)
In the example above ws
is a duplex stream. That means you can pipe output to anything that accepts streams. You can also pipe data into streams (such as a webcam feed or audio data).
The underlying WebSocket
instance is available as ws.socket
.
The available options differs depending on if you use this module in the browser or with node.js. Options can be passed in as the third or second argument - WebSocket(address, [protocols], [options])
.
options.browserBufferSize
How much to allow the socket.bufferedAmount to grow before starting to throttle writes. This option has no effect in node.js.
Default: 1024 * 512
(512KiB)
options.browserBufferTimeout
How long to wait before checking if the socket buffer has drained sufficently for another write. This option has no effect in node.js.
Default: 1000
(1 second)
options.objectMode
Send each chunk on its own, and do not try to pack them in a single websocket frame.
Default: false
options.binary
Always convert to Buffer
in Node.js before sending.
Forces options.objectMode
to false
.
Default: true
options.perMessageDeflate
We recommend disabling the per message deflate extension to achieve the best throughput.
Default: true
on the client, false
on the server.
Example:
1var websocket = require('@httptoolkit/websocket-stream') 2var ws = websocket('ws://realtimecats.com', { 3 perMessageDeflate: false 4})
Beware that this option is ignored by browser clients. To make sure that permessage-deflate is never used, disable it on the server.
When used in node.js see the ws.WebSocket documentation
Using the ws
module you can make a websocket server and use this module to get websocket streams on the server:
1var websocket = require('@httptoolkit/websocket-stream') 2var wss = websocket.createServer({server: someHTTPServer}, handle) 3 4function handle(stream, request) { 5 // `request` is the upgrade request sent by the client. 6 fs.createReadStream('bigdata.json').pipe(stream) 7}
We recommend disabling the per message deflate extension to achieve the best throughput:
1var websocket = require('@httptoolkit/websocket-stream') 2var wss = websocket.createServer({ 3 perMessageDeflate: false, 4 server: someHTTPServer 5}, handle) 6 7function handle(stream) { 8 fs.createReadStream('bigdata.json').pipe(stream) 9}
You can even use it on express.js with the express-ws library:
1const express = require('express'); 2const expressWebSocket = require('express-ws'); 3const websocketStream = require('websocket-stream/stream'); 4const app = express(); 5 6// extend express app with app.ws() 7expressWebSocket(app, null, { 8 // ws options here 9 perMessageDeflate: false, 10}); 11 12app.ws('/bigdata.json', function(ws, req) { 13 // convert ws instance to stream 14 const stream = websocketStream(ws, { 15 // websocket-stream options here 16 binary: true, 17 }); 18 19 fs.createReadStream('bigdata.json').pipe(stream); 20}); 21 22app.listen(3000);
npm test
First start the echo server by running node test-server.js
Then run npm start
and open localhost:9966
in your browser and open the Dev Tools console to see test output.
BSD LICENSE
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More