{"_id":"@httptoolkit/websocket-stream","_rev":"3-8b16fb9381cbb388477d7cb0ba971148","name":"@httptoolkit/websocket-stream","dist-tags":{"latest":"6.0.1"},"versions":{"6.0.0":{"name":"@httptoolkit/websocket-stream","version":"6.0.0","license":"BSD-2-Clause","description":"Use websockets with the node streams API. Works in browser and node, with all current WS versions","scripts":{"test":"node test.js","start":"beefy test-client.js"},"repository":{"type":"git","url":"git+ssh://git@github.com/httptoolkit/websocket-stream.git"},"keywords":["websocket","websockets","stream","streams","realtime"],"dependencies":{"@types/ws":"*","duplexify":"^3.5.1","inherits":"^2.0.1","isomorphic-ws":"^4.0.1","readable-stream":"^2.3.3","safe-buffer":"^5.1.2","ws":"*","xtend":"^4.0.0"},"devDependencies":{"@types/node":"^11.13.4","beefy":"^2.1.8","browserify":"^16.2.3","concat-stream":"^1.6.2","tape":"^4.9.1","typescript":"^3.4.3"},"optionalDependencies":{},"browser":{"./echo-server.js":"./fake-server.js","./index.js":"./stream.js","ws":"./ws-fallback.js"},"bugs":{"url":"https://github.com/httptoolkit/websocket-stream/issues"},"homepage":"https://github.com/httptoolkit/websocket-stream#readme","main":"index.js","author":"","gitHead":"0522d75a0a45837e3b068c804aa69ed246d4816d","_id":"@httptoolkit/websocket-stream@6.0.0","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-EC8m9JbhpGX2okfvLakqrmy4Le0VyNKR7b3IdvFZR/BfFO4ruh/XceBvXhCFHkykchnFxuOSlRwFiqNSXlwcGA==","shasum":"72d00c06944057951d7ab8a8f8336033c7b52e90","tarball":"https://registry.npmjs.org/@httptoolkit/websocket-stream/-/websocket-stream-6.0.0.tgz","fileCount":15,"unpackedSize":29689,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2K4RCRA9TVsSAnZWagAA9gQP/ivYJFJJ3da584cz65CB\ndR8aItPmI5EAIknfRL86qQXbSI7FUqgI7i4DrOdouRB/Pan2AcZhdl+AORxi\no6kcOhRbX9Bhfhr0kcT4nTc4rKep07E8BZeNVilH4A0827LiE4eX4ZnAdGp6\nTGNDf8jb4ozgwpmidn2kLZkM3yNmCJxQQn038/WgqGnbV1UiRMPn2IB9xo2f\nQUC6YgR9khsd+dCnVnrSWczXa7jO/6ny6X5RgWAOa7D0nJvCIA5cbzHiThKA\nY9cAKTRads8kfs3KtgoaMtQpFMPPWZR2E9lXpgNBp2j5mR4X0o5wYG6x7HW4\nzjDo4Y7PSTSsYZgaYzOabFw1JQHGiAyXrhCsBA/XgTZppD2BOUYggpnzE2j6\nuX44ahbiV0ttE3IJ0fUJgv7D/s3bqFs9xLCVb5GG8FpMHaF7hOV+l8X9BOY9\nLbUaGG0h2ZqHirz2mJ5KCunjLCrVgJbMTRCNazYRmYEQ8+gLITVvM4lVTwOR\nyIM7v+TuNx3u2mBNBb59tNt9aa6m0FtJ/DMKF6g5TplePRH8cNF8TPTVxbso\npRNq7h4PJ8ppsiBqKfsN3ZKQGLUziBSfQ4PM4DBNQZuykngeeZv65FTSKBSQ\nxt172Yc4AhhvFM8S3miKZP0XW424XqtI7lEbM2ytdYcfJyWQ4raA1DE6coS6\n9k3L\r\n=9Uu+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDGwWj64jNU8S6/3HDPgMw7U17ED+xwrel6RCTVGa4NgAiEA9sSvTV1Zr2naxn65DlwVEsTcqZl6J42peHJNu/feggU="}]},"_npmUser":{"name":"pimterry","email":"pimterry@gmail.com"},"directories":{},"maintainers":[{"name":"pimterry","email":"pimterry@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/websocket-stream_6.0.0_1632989143686_0.40790165803307254"},"_hasShrinkwrap":false},"6.0.1":{"name":"@httptoolkit/websocket-stream","version":"6.0.1","license":"BSD-2-Clause","description":"Use websockets with the node streams API. Works in browser and node, with all current WS versions","scripts":{"test":"node test.js","start":"beefy test-client.js"},"repository":{"type":"git","url":"git+ssh://git@github.com/httptoolkit/websocket-stream.git"},"keywords":["websocket","websockets","stream","streams","realtime"],"dependencies":{"@types/ws":"*","duplexify":"^3.5.1","inherits":"^2.0.1","isomorphic-ws":"^4.0.1","readable-stream":"^2.3.3","safe-buffer":"^5.1.2","ws":"*","xtend":"^4.0.0"},"devDependencies":{"@types/node":"^11.13.4","beefy":"^2.1.8","browserify":"^16.2.3","concat-stream":"^1.6.2","tape":"^4.9.1","typescript":"^3.4.3"},"optionalDependencies":{},"browser":{"./echo-server.js":"./fake-server.js","./index.js":"./stream.js","ws":"./ws-fallback.js"},"bugs":{"url":"https://github.com/httptoolkit/websocket-stream/issues"},"homepage":"https://github.com/httptoolkit/websocket-stream#readme","main":"index.js","author":"","types":"./index.d.ts","gitHead":"9f15121fe33a82aba829f2e9275c82f815d4b201","_id":"@httptoolkit/websocket-stream@6.0.1","_nodeVersion":"14.18.3","_npmVersion":"8.5.2","dist":{"integrity":"sha512-A0NOZI+Glp3Xgcz6Na7i7o09+/+xm2m0UCU8gdtM2nIv6/cjLmhMZMqehSpTlgbx9omtLmV8LVqOskPEyWnmZQ==","shasum":"8d732f1509860236276f6b0759db4cc9859bbb62","tarball":"https://registry.npmjs.org/@httptoolkit/websocket-stream/-/websocket-stream-6.0.1.tgz","fileCount":15,"unpackedSize":29700,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDZBWsH5lcGqK6cKCcHtqGjfleQCFRn8pKkKF5Xyx1RyAiAptsDUbG14Ba1QuL8FFWaqOSCEVSzAmCl6P6d4QY0nPg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJirJ95ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo2NA//RSbx2A5UYeaF21EUaMWtykTLZkmCkQWrTk9mxICnA0eQOlhC\r\nsYoYBde+EPrjToCb+gczmAm+gID6RfUO8SJDQ9BfREbEVDJe5jl8kemkiQEq\r\njFliDPc1kdZ/PLUvQYiDYpk3tkkgUHLk2ZCuJ0FieULCt/Rg2dysWmK+Z3rg\r\nid1S8TJNCR/COxbniHt7E2Ka48gec1xkoP1ZSB0/JAXqVUA0nhCGz/ABlWQY\r\nZp0eAd6q6HedcXhu0Z8h5zU1g6bsN8N4IrnyMb4x/BGooG5zJWaVsWzqkERw\r\nBH0+EGuBuIfgOgLvoq9zOzW2WwNTqz1HolOGfW3rNY4jAY4gh7EmTtAHeLWX\r\nVRj79sgnLf0GGfiv9dMrsviJF6d5vbUuCAR56XHUbRz0TdXizr0ie/3v8OBC\r\n7/OVpf+BM83W2uKoiGGo0Mr+OLRvWD0OBD5ahG89TE10ujgTRwb97KuCvlsw\r\nbGrmjNTSXxZUQHjkMUsQchG7w92ChjlyOPSk5joLwvKpi739+S5bumkxlHPm\r\n2GwPZbRIewFt2i/7v6d6EmPAuiPo4ZkrkeKrAuQG+1IoDRJaReiLKhgSn7aH\r\nQwNHvT3a3NoyypMcSp4FQvj1oP2wJVpJJs2zLlJCIUWzpTPyIWsTNkli/iQM\r\nmXrMXJ1naKC3QIsCdHWG47UihrlFNbIJ6mI=\r\n=DBL8\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"pimterry","email":"pimterry@gmail.com"},"directories":{},"maintainers":[{"name":"pimterry","email":"pimterry@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/websocket-stream_6.0.1_1655480185106_0.37515002057582536"},"_hasShrinkwrap":false}},"time":{"created":"2021-09-30T08:05:43.639Z","6.0.0":"2021-09-30T08:05:43.840Z","modified":"2022-06-17T15:36:25.401Z","6.0.1":"2022-06-17T15:36:25.300Z"},"maintainers":[{"name":"pimterry","email":"pimterry@gmail.com"}],"description":"Use websockets with the node streams API. Works in browser and node, with all current WS versions","homepage":"https://github.com/httptoolkit/websocket-stream#readme","keywords":["websocket","websockets","stream","streams","realtime"],"repository":{"type":"git","url":"git+ssh://git@github.com/httptoolkit/websocket-stream.git"},"bugs":{"url":"https://github.com/httptoolkit/websocket-stream/issues"},"license":"BSD-2-Clause","readme":"# websocket-stream [![Build Status](https://github.com/httptoolkit/websocket-stream/workflows/CI/badge.svg)](https://github.com/httptoolkit/websocket-stream/actions) [![Get it on npm](https://img.shields.io/npm/v/@httptoolkit/websocket-stream.svg)](https://www.npmjs.com/package/@httptoolkit/websocket-stream)\n\n> _Part of [HTTP Toolkit](https://httptoolkit.tech): powerful tools for building, testing & debugging HTTP(S)_\n\nUse HTML5 [websockets](https://developer.mozilla.org/en-US/docs/WebSockets) using the Node Streams API.\n\nThis is a fork of the original [websocket-stream](https://www.npmjs.com/package/websocket-stream) (now unmaintained), for use in HTTP Toolkit. This fork:\n\n* Uses [isomorphic-ws](https://www.npmjs.com/package/isomorphic-ws) so that the 'ws' module is not loaded unnecessarily in browsers\n* Supports WS up to version 8 (note that isomorphic-ws uses * as its ws version, so this will always use the latest compatible release)\n* Fixes and extends the TypeScript types, and adds an explicit dependency on @types/ws\n* Has a CI build for automated testing\n* Adds a 'ws-close' event, which exposes the close event data when a websocket is closed by a close frame (before the stream 'close' event, which is different)\n\n### Usage\n\nThis module works in Node or in Browsers that support WebSockets. You can use [browserify](http://github.com/substack/node-browserify) to package this module for browser use.\n\n```javascript\nvar websocket = require('@httptoolkit/websocket-stream')\nvar ws = websocket('ws://echo.websocket.org')\nprocess.stdin.pipe(ws)\nws.pipe(process.stdout)\n```\n\nIn 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).\n\nThe underlying `WebSocket` instance is available as `ws.socket`.\n\n#### Options\n\nThe 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])`.\n\n##### `options.browserBufferSize`\n\nHow much to allow the [socket.bufferedAmount](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#Attributes) to grow before starting to throttle writes. This option has no effect in node.js.\n\nDefault: `1024 * 512` (512KiB)\n\n##### `options.browserBufferTimeout`\n\nHow long to wait before checking if the socket buffer has drained sufficently for another write. This option has no effect in node.js.\n\nDefault: `1000` (1 second)\n\n##### `options.objectMode`\n\nSend each chunk on its own, and do not try to pack them in a single\nwebsocket frame.\n\nDefault: `false`\n\n##### `options.binary`\n\nAlways convert to `Buffer` in Node.js before sending.\nForces `options.objectMode` to `false`.\n\nDefault: `true`\n\n##### `options.perMessageDeflate`\n\nWe recommend disabling the [per message deflate\nextension](https://tools.ietf.org/html/rfc7692) to achieve the best\nthroughput.\n\nDefault: `true` on the client, `false` on the server.\n\nExample:\n\n```js\nvar websocket = require('@httptoolkit/websocket-stream')\nvar ws = websocket('ws://realtimecats.com', {\n  perMessageDeflate: false\n})\n```\n\nBeware that this option is ignored by browser clients. To make sure that permessage-deflate is never used, disable it on the server.\n\n##### Other options\n\nWhen used in node.js see the [ws.WebSocket documentation](https://github.com/websockets/ws/blob/master/doc/ws.md#class-wswebsocket)\n\n### On the server\n\nUsing the [`ws`](http://npmjs.org/ws) module you can make a websocket server and use this module to get websocket streams on the server:\n\n```javascript\nvar websocket = require('@httptoolkit/websocket-stream')\nvar wss = websocket.createServer({server: someHTTPServer}, handle)\n\nfunction handle(stream, request) {\n  // `request` is the upgrade request sent by the client.\n  fs.createReadStream('bigdata.json').pipe(stream)\n}\n```\n\nWe recommend disabling the [per message deflate\nextension](https://tools.ietf.org/html/rfc7692) to achieve the best\nthroughput:\n\n```javascript\nvar websocket = require('@httptoolkit/websocket-stream')\nvar wss = websocket.createServer({\n  perMessageDeflate: false,\n  server: someHTTPServer\n}, handle)\n\nfunction handle(stream) {\n  fs.createReadStream('bigdata.json').pipe(stream)\n}\n```\n\nYou can even use it on express.js with the [express-ws](https://www.npmjs.com/package/express-ws) library:\n\n```js\nconst express = require('express');\nconst expressWebSocket = require('express-ws');\nconst websocketStream = require('websocket-stream/stream');\nconst app = express();\n\n// extend express app with app.ws()\nexpressWebSocket(app, null, {\n    // ws options here\n    perMessageDeflate: false,\n});\n\napp.ws('/bigdata.json', function(ws, req) {\n  // convert ws instance to stream\n  const stream = websocketStream(ws, {\n    // websocket-stream options here\n    binary: true,\n  });\n\n  fs.createReadStream('bigdata.json').pipe(stream);\n});\n\napp.listen(3000);\n```\n\n## Run the tests\n\n### Server-side tests\n\n```\nnpm test\n```\n\n### Client-side tests\n\nFirst start the echo server by running `node test-server.js`\n\nThen run `npm start` and open `localhost:9966` in your browser and open the Dev Tools console to see test output.\n\n## license\n\nBSD LICENSE\n","readmeFilename":"readme.md"}