Registry / devops / websocket-extensions

websocket-extensions

JSON →
library0.1.4jsnpmunverified

Minimal framework for implementing WebSocket extensions decoupled from the protocol. Version 0.1.4 (stable, low release cadence). Key differentiator: it provides abstract frame/message representations and negotiation of Sec-WebSocket-Extensions headers, allowing any WebSocket library built on this framework to use extensions like permessage-deflate. It is a foundational library used by faye-websocket and other WebSocket implementations.

npm install websocket-extensions
INSTALL
IMPORT
SIG · WEBSOCKET-EXTENSIO
W
websocket-extensions
devopsjavascriptv0.1.4
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.

Extensions
import { Extensions } from 'websocket-extensions'
const Extensions = require('websocket-extensions').Extensions
CJS users can use require() which returns module.exports directly.
default export
import Extensions from 'websocket-extensions'
const Extension = require('websocket-extensions').default
CJS require returns the Extensions constructor directly; no .default needed.
require
const Extensions = require('websocket-extensions')
const extensions = require('websocket-extensions')()
require returns the class, not an instance.

Show how to create an Extensions container, add a deflate extension, negotiate extensions, and use the pipeline to process frames.

const Extensions = require('websocket-extensions'); const deflate = require('permessage-deflate'); const exts = new Extensions(); exts.add(deflate); // Example: offer extensions const offer = exts.offer(); // 'permessage-deflate; client_max_window_bits' // Example: process response headers from server const clientExts = new Extensions(); clientExts.add(deflate); clientExts.activate(offer); // On server side: const serverExts = new Extensions(); serverExts.add(deflate); // parse client offer header const clientOffer = 'permessage-deflate; client_max_window_bits'; const response = serverExts.processRequest(clientOffer); // returns a set of accepted parameters // Then activate with the client's response serverExts.activate(response); // After negotiation, wrap frames via pipeline const pipeline = exts.pipeline(); // pipeline.write(frame) ... pipeline.read()
Debug
Known issues
breakingPrior to 0.1.0, the API was unstable. Ensure you use >=0.1.0.
fix
Update to >=0.1.0
affects: <0.1.0
deprecatedThe 'exts.pipeline()' method returns a pipeline object that is internal; direct manipulation of frames may lead to errors.
fix
Use the pipeline's read/write methods as documented.
affects: >=0.1.0
gotchaExtensions must implement the correct interface: processIncomingMessage, processOutgoingMessage, etc. Missing methods will cause silent failures.
fix
Ensure your extension implements all required methods.
affects: >=0.1.0
gotchaThe container does not validate that added extensions are compatible; incorrect extensions may cause runtime errors.
fix
Test extensions thoroughly before use.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: exts.add is not a function
Forgot to instantiate Extensions: using 'const exts = require('websocket-extensions')' instead of 'const Extensions = require(...); const exts = new Extensions()'.
fix
const Extensions = require('websocket-extensions'); const exts = new Extensions(); exts.add(...);
Error: Cannot find module 'websocket-extensions'
Package not installed or not in node_modules.
fix
npm install websocket-extensions
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
websocket-extensions — npm install websocket-extensions · libregistry