Registry / messaging / websocket-framed

websocket-framed

JSON →
library1.2.9jsnpmunverified

Framed WebSocket Communication library for Node.js and browser (version 1.2.9, last updated 2023). It wraps WebSocket messages in a frame data structure (fid, rid, type, data) and supports three serialization codecs: JSON, CBOR, and MsgPack. This enables complex data serialization, type annotation, and request/response correlation. The library is lightweight (<5KB), has zero runtime dependencies, and works with standard WebSocket API. It is available as CommonJS only, with no ESM or TypeScript type definitions. Release cadence is low; the last release was in 2023.

npm install websocket-framed
INSTALL
IMPORT
SIG · WEBSOCKET-FRAMED
W
websocket-framed
messagingjavascriptv1.2.9
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.

WebSocketFramed
const WebSocketFramed = require('websocket-framed')
import WebSocketFramed from 'websocket-framed'
Package is CommonJS-only; no ESM exports. Using import will fail. For TypeScript, use `const WebSocketFramed = require('websocket-framed')` or `// @ts-ignore`.
WebSocketFramed
const { WebSocketFramed } = require('websocket-framed')
The module exports a single constructor as default; named destructuring yields undefined.

Shows how to create a WebSocketFramed instance, attach message handler, and send/receive frames.

const WebSocket = require('ws'); const WebSocketFramed = require('websocket-framed'); // Create a WebSocket connection (Node.js example) const ws = new WebSocket('wss://echo.websocket.org'); const wsf = new WebSocketFramed(ws, 'json'); ws.on('open', () => { console.log('Connected'); // Send a request frame const request = { type: 'greeting', data: 'Hello' }; wsf.send(request); }); wsf.on('message', (event) => { console.log('Received frame:', event.frame); // event.frame has { fid, rid, type, data } }); ws.on('error', console.error);
Debug
Known issues
gotchaPackage does not ship TypeScript type definitions. Users must declare module manually.
fix
Add a declaration file: declare module 'websocket-framed'; or use @ts-ignore.
affects: >=1.0.0
gotchaThe 'send' method returns an object but does not wait for actual WebSocket send completion; it returns immediately after encoding.
fix
Do not rely on the return value for delivery guarantees. Use WebSocket bufferedAmount or wait for 'drain' event if needed.
affects: >=1.0.0
gotchaThe 'message' event is emitted synchronously inside the WebSocket 'message' event; if you attach the listener after open, you may miss early messages.
fix
Attach the wsf 'message' listener before calling wsf.send() or before the WebSocket 'open' event fires.
affects: >=1.0.0
gotchaCodec 'cbor' and 'msgpack' require additional peer dependencies: cbor and msgpack5 respectively (not included automatically).
fix
Install the package manually: npm install cbor msgpack5
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: WebSocketFramed is not a constructor
Using ES module import syntax on a CommonJS package.
fix
Use `const WebSocketFramed = require('websocket-framed');` instead of `import`.
Error: Cannot find module 'cbor'
Codec set to 'cbor' but cbor npm package not installed.
fix
npm install cbor
Error: Cannot find module 'msgpack5'
Codec set to 'msgpack' but msgpack5 npm package not installed.
fix
npm install msgpack5
Upgrade
Version history
1.2.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
websocket-framed — npm install websocket-framed · libregistry