Registry / messaging / kalm-websocket

kalm-websocket

JSON →
library3.3.0jsnpmunverified

A WebSocket transport for kalm.js, which is a real-time messaging framework for Node.js and the browser. Current version 3.3.0 supports Node >=6.0 and browser environments. It provides a seamless integration with kalm's pub/sub model, handling WebSocket connections under the hood. Compared to raw WebSocket or Socket.IO, it simplifies transport layer configuration and allows easy switching between transports. Release cadence is low, with occasional updates to align with kalm.js changes.

npm install kalm-websocket
INSTALL
IMPORT
SIG · KALM-WEBSOCKET
K
kalm-websocket
messagingjavascriptv3.3.0
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.

default
import ws from 'kalm-websocket'
const ws = require('kalm-websocket')
ESM import is the primary pattern for browser bundlers; in Node, require works with kalm's transport.
default
const ws = require('kalm-websocket')
CommonJS require works for Node.js environment.
default
import Kalm from 'kalm'; import ws from 'kalm-websocket'; Kalm.connect({ adapter: ws })
import { kalmWebsocket } from 'kalm-websocket'
Default export is a transport factory; must be passed as adapter or transport option.

Shows how to create a WebSocket server and client using kalm and kalm-websocket, including subscribing and writing to a channel.

const Kalm = require('kalm'); const ws = require('kalm-websocket'); const server = Kalm.listen({ port: 3000, transport: ws }); server.on('connection', (client) => { client.subscribe('/', (data) => { console.log(data); }); }); const client = Kalm.connect({ hostname: '127.0.0.1', port: 3000, adapter: ws }); client.on('connect', () => { client.write('/', 'Hello from Browser!'); });
Debug
Known issues
gotchaThe package uses 'adapter' in browser and 'transport' in Node.js for the same transport config. Mixing them up will cause silent failures.
fix
Use 'transport' in Kalm.listen() on server and 'adapter' in Kalm.connect() on client.
affects: *
breakingVersion 3.0.0 changed the default export from a class to a factory function. Passing the module directly as a transport no longer works as before.
fix
Use default import: const ws = require('kalm-websocket') or import ws from 'kalm-websocket'. Do not instantiate it.
affects: >=3.0.0
deprecatedNode.js >=6.0 is required. Older versions are not supported and may produce errors.
fix
Upgrade Node.js to version 6.0 or later.
affects: *
gotchaThe package depends on the 'ws' library for Node.js and native WebSocket in browsers. Ensure your bundler does not include both.
fix
Use a bundler like webpack with appropriate alias or conditional require to avoid double inclusion.
affects: *
Errors
Common errors & fixes
TypeError: ws is not a constructor
Importing the module incorrectly, e.g., using new ws() when it should be passed directly.
fix
Use: const ws = require('kalm-websocket'); Kalm.listen({ transport: ws });
Error: Cannot find module 'kalm'
Missing peer dependency kalm not installed.
fix
Run: npm install kalm kalm-websocket
ReferenceError: WebSocket is not defined
Trying to use the transport in a Node.js environment without the 'ws' library automatically detected (if bundler blocks it).
fix
Ensure your environment supports WebSocket or install 'ws' as a dependency.
Upgrade
Version history
3.3.0latest on npm
Audit
Dependencies
kalmrequiredPeer dependency; this package is only a transport for kalm.js and requires kalm to function.
Agent activity
8 hits · last 30 days
node
6
Amazon
1
OpenAI (training)
1
Resources
kalm-websocket — npm install kalm-websocket · libregistry