Registry / messaging / websocket-pull-stream

websocket-pull-stream

JSON →
library2.0.12jsnpmunverified

WebSocket Pull Stream (v2.0.12) wraps WebSocket connections with pull-stream semantics for lightweight, efficient real-time communication. Unlike websocket-stream, it is much leaner (browserified+uglified size ~8KB vs ~79KB) and adds object mode streams, duplex (two-way) communication, and a multiplexer API for multiple streams over one WebSocket. It is isomorphic (same API for browser and Node.js) and supports both pull and flow modes. The package is in maintenance mode as of 2025, with no recent updates since 2019, but remains a minimalist alternative for pull-stream ecosystems.

npm install websocket-pull-stream
INSTALL
IMPORT
SIG · WEBSOCKET-PULL-STR
W
websocket-pull-stream
messagingjavascriptv2.0.12
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

wsps
import wsps from 'websocket-pull-stream'
const wsps = require('websocket-pull-stream')
ESM-only since v2. CommonJS require is not supported; use ES modules.
duplex
const stream = wsps(websocket)()
const stream = wsps(websocket)
wsps returns a factory function that must be called (with optional object constructor) to get a duplex pull-stream.
Source
import pull from 'pull-stream'
import { Source } from 'pull-stream'
pull-stream uses a single default export 'pull' which contains source, sink, through, etc.

Shows how to create a duplex pull-stream from a WebSocket using websocket-pull-stream, and pipe data through it.

import WebSocket from 'ws'; import wsps from 'websocket-pull-stream'; import pull from 'pull-stream'; const ws = new WebSocket('ws://localhost:8081'); ws.on('open', () => { // Create duplex stream const duplex = wsps(ws)(); // Source: push some data const source = pull.values(['hello', 'world']); // Sink: log received data const sink = pull.collect((err, results) => { console.log(results); }); // Connect pull( source, duplex, sink ); });
Debug
Known issues
breakingVersion 2 rewrote the API: wsps now returns a factory function instead of a stream directly.
fix
Call the returned function: const duplex = wsps(websocket)()
affects: >=2.0.0
deprecatedThe package appears unmaintained; last release was 2019. No security patches are expected.
fix
Consider alternatives like ws or uWebSockets.js for active support.
affects: *
breakingESM-only export in v2. CommonJS require will throw at runtime.
fix
Use import or dynamic import() instead of require().
affects: >=2.0.0
gotchaThe duplex stream is not a Node stream; it's a pull-stream. Piping with .pipe() will not work.
fix
Use pull-stream's pull() function to connect streams.
affects: *
gotchaOptions like 'mode' and 'View' must be passed as second argument to wsps, not to the factory call.
fix
const duplex = wsps(websocket, { mode: 'flow' })()
affects: *
gotchaObject mode is enabled by passing a constructor function (e.g., Object) to the factory call, not as an option.
fix
const duplex = wsps(websocket)(Object)
affects: *
Errors
Common errors & fixes
TypeError: wsps is not a function
Using require() instead of import, or importing default incorrectly.
fix
Use 'import wsps from 'websocket-pull-stream'' instead of require.
Uncaught TypeError: Cannot read properties of undefined (reading 'pipe')
Trying to call .pipe() on a pull-stream duplex, which is not a Node stream.
fix
Use pull(source, duplex, sink) from pull-stream package.
Error: stream is not a function
Calling wsps without invoking the returned factory.
fix
const stream = wsps(websocket)()
Upgrade
Version history
2.0.12latest on npm
Audit
Dependencies
pull-streamrequiredRequired for pull-stream duplex, source, sink, and through stream primitives used by this package.
Agent activity
21 hits · last 30 days
node
20
OpenAI (training)
1
Resources
websocket-pull-stream — npm install websocket-pull-stream · libregistry