{"_id":"@moq/web-socket-stream","_rev":"2-5371ee7d1de6343a4a735c2447befadc","name":"@moq/web-socket-stream","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@moq/web-socket-stream","version":"0.1.0","keywords":["websocketstream","websocket","polyfill","ponyfill","streams","backpressure"],"author":{"name":"Luke Curley","email":"kixelated@gmail.com"},"license":"(MIT OR Apache-2.0)","_id":"@moq/web-socket-stream@0.1.0","maintainers":[{"name":"kixelated","email":"kixelated@gmail.com"}],"homepage":"https://github.com/moq-dev/web-transport#readme","bugs":{"url":"https://github.com/moq-dev/web-transport/issues"},"dist":{"shasum":"8103363f233fa4341a7bcad5e114eac6bdfa0edf","tarball":"https://registry.npmjs.org/@moq/web-socket-stream/-/web-socket-stream-0.1.0.tgz","fileCount":6,"integrity":"sha512-VxPaJZvZ8qgFmTjG9XhTH0bQoQE9pExvlS/R0fH1aNcpqCnZdbYS2kvB2ypO5SyFTf6oH+4eWvgElDzW6yiqFQ==","signatures":[{"sig":"MEYCIQDPusIPkYwOHFdg4COzD26jjHT0RAMUlmrvQ0+8/opgAgIhAJ3uLlZp9HKPU2eaIx+bmUVceQ24BBtWjxt16GvUyDhj","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22601},"type":"module","types":"./index.d.ts","exports":{".":{"types":"./index.d.ts","default":"./index.js"}},"gitHead":"a7f279ab46d896f77d4798aeff2d76b68c7c89e5","_npmUser":{"name":"kixelated","email":"kixelated@gmail.com"},"repository":{"url":"git+https://github.com/moq-dev/web-transport.git","type":"git"},"_npmVersion":"11.6.2","description":"A WebSocketStream polyfill: a plain WebSocket wrapped as { readable, writable } streams with backpressure","directories":{},"_nodeVersion":"24.13.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/web-socket-stream_0.1.0_1782835749785_0.37342297285512616","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@moq/web-socket-stream","author":{"name":"Luke Curley","email":"kixelated@gmail.com"},"version":"0.1.1","description":"A WebSocketStream polyfill: a plain WebSocket wrapped as { readable, writable } streams with backpressure","type":"module","license":"(MIT OR Apache-2.0)","repository":{"type":"git","url":"git+https://github.com/moq-dev/web-transport.git"},"exports":{".":{"types":"./index.d.ts","default":"./index.js"}},"types":"./index.d.ts","keywords":["websocketstream","websocket","polyfill","ponyfill","streams","backpressure"],"gitHead":"9c1fa09d0d93cfdfeb7f43f1d44ab671945bb86a","_id":"@moq/web-socket-stream@0.1.1","bugs":{"url":"https://github.com/moq-dev/web-transport/issues"},"homepage":"https://github.com/moq-dev/web-transport#readme","_nodeVersion":"24.13.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-VKi/GE/CLqmbEZlgNbBLbAFk2pQTxT+KUD2DjCSoxqZxbS3KBe5BBZ0m3fila4fEGyll2JT5MmgEyVr4zkZEVA==","shasum":"77f84fd7a3b7c0647de088287497aa627c908f9e","tarball":"https://registry.npmjs.org/@moq/web-socket-stream/-/web-socket-stream-0.1.1.tgz","fileCount":6,"unpackedSize":30125,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@moq%2fweb-socket-stream@0.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBJeGsxtKubcxhCeiYrYjEpR3FWHsapRAg1bV5bnF69QAiBnZA7OYbuN+qLQN/Vkvwxqt+yMvGh3lSZ3Lq+MJ3ohRQ=="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:21f45156-738a-4542-b917-edd8e91efca1"}},"directories":{},"maintainers":[{"name":"kixelated","email":"kixelated@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/web-socket-stream_0.1.1_1784607231413_0.14373467862760148"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-30T16:09:09.647Z","modified":"2026-07-21T04:13:51.928Z","0.1.0":"2026-06-30T16:09:09.938Z","0.1.1":"2026-07-21T04:13:51.553Z"},"bugs":{"url":"https://github.com/moq-dev/web-transport/issues"},"author":{"name":"Luke Curley","email":"kixelated@gmail.com"},"license":"(MIT OR Apache-2.0)","homepage":"https://github.com/moq-dev/web-transport#readme","keywords":["websocketstream","websocket","polyfill","ponyfill","streams","backpressure"],"repository":{"type":"git","url":"git+https://github.com/moq-dev/web-transport.git"},"description":"A WebSocketStream polyfill: a plain WebSocket wrapped as { readable, writable } streams with backpressure","maintainers":[{"name":"kixelated","email":"kixelated@gmail.com"}],"readme":"# @moq/web-socket-stream\n\nA polyfill for the [`WebSocketStream`](https://github.com/ricea/websocketstream-explainer) API, which exposes a WebSocket as a `{ readable, writable }` pair of streams with backpressure on the writable.\n\n`WebSocketStream` currently ships only in Chromium. This package wraps a plain `WebSocket` to present the same surface (`opened`, `closed`, `close()`) on every platform — browsers, Node, and Bun.\n\n> **Note:** a ponyfill can only *approximate* write backpressure by polling `WebSocket.bufferedAmount` against a high-water mark; only the native API observes the real send buffer. Use [`openWebSocketStream`](#prefer-native) to get the native implementation when it's available.\n\n## Install\n\n```bash\nnpm install @moq/web-socket-stream\n```\n\n## Usage\n\n### Prefer native\n\n`openWebSocketStream` returns the native `WebSocketStream` when present and falls back to this ponyfill otherwise:\n\n```ts\nimport { openWebSocketStream } from \"@moq/web-socket-stream\"\n\nconst wss = openWebSocketStream(\"wss://example.com\", { protocols: [\"my-proto\"] })\nconst { readable, writable, protocol } = await wss.opened\n\nconst reader = readable.getReader()\nconst writer = writable.getWriter()\nawait writer.ready          // backpressure\nawait writer.write(new Uint8Array([1, 2, 3]))\n```\n\n### Global polyfill\n\nInstall as a global `WebSocketStream` if the platform doesn't ship one:\n\n```ts\nimport { install } from \"@moq/web-socket-stream\"\n\n// Only installs if native WebSocketStream is unavailable\ninstall()\n\nconst wss = new WebSocketStream(\"wss://example.com\")\n```\n\n### Node / Bun\n\nModern Node and Bun expose a global `WebSocket`, which is used automatically. To use a specific implementation (e.g. the [`ws`](https://www.npmjs.com/package/ws) package), inject it — this forces the ponyfill:\n\n```ts\nimport WebSocket from \"ws\"\nimport { WebSocketStream } from \"@moq/web-socket-stream\"\n\nconst wss = new WebSocketStream(\"wss://example.com\", { webSocket: WebSocket, highWaterMark: 32 * 1024 })\n```\n\n### Adopting an existing socket\n\nA server has no URL to dial: the socket arrives from an HTTP upgrade, already open and with its\nsubprotocol negotiated. `adopt` wraps one in place, resolving `opened` without waiting for an\n`onopen` that has already fired:\n\n```ts\nimport { WebSocketStream } from \"@moq/web-socket-stream\"\n\nconst { socket, response } = Deno.upgradeWebSocket(req)\nconst wss = WebSocketStream.adopt(socket)\nconst { readable, writable } = await wss.opened\n```\n\nAdoption takes ownership of the socket's event handlers, so adopt it before anything else reads from\nit — messages delivered beforehand are dropped by the platform rather than buffered.\n\n## License\n\nLicensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or [MIT license](LICENSE-MIT) at your option.\n","readmeFilename":"README.md"}