Registry / messaging / openim-websocket

openim-websocket

JSON →
library1.0.41jsnpmunverified

OpenIM WebSocket client library (v1.0.41) for connecting to OpenIM WebSocket servers in browser and Node.js environments. Built with TypeScript, it provides automatic reconnection, authentication headers, and event-based messaging with subscribe/unsubscribe capabilities. Heavily tailored for OpenIM backend services (requires Appid, ClientId, etc.), not a generic WebSocket client. Release cadence appears active with frequent updates. Differentiator: dedicated OpenIM protocol support with built-in auth, logging, and reconnection logic.

npm install openim-websocket
INSTALL
IMPORT
SIG · OPENIM-WEBSOCKET
O
openim-websocket
messagingjavascriptv1.0.41
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.

OpenIMWebSocket
import { OpenIMWebSocket } from 'openim-websocket'
const OpenIMWebSocket = require('openim-websocket')
ESM-only; requires Node.js >= 12 or a bundler. Named export, not default.
Message
import type { Message } from 'openim-websocket'
import { Message } from 'openim-websocket'
Message is a TypeScript interface; use import type for type-only usage.
WebSocketConfig
import type { WebSocketConfig } from 'openim-websocket'
import { WebSocketConfig } from 'openim-websocket'
WebSocketConfig is a TypeScript interface; type-only import.

Initializes OpenIMWebSocket with auth headers, connects, subscribes to a topic, and sends a publish message. Secure via env variables.

import { OpenIMWebSocket } from 'openim-websocket'; const client = new OpenIMWebSocket({ url: process.env.WS_URL ?? 'ws://localhost:10001', enableLogging: true, headers: { 'client-type': 'EnterpriseCenterWEB', Appid: process.env.APP_ID ?? '', ClientId: process.env.CLIENT_ID ?? '', Timestamp: String(Date.now()), Authorization: `Bearer ${process.env.TOKEN ?? ''}`, }, reconnectInterval: 5000, maxReconnectAttempts: 10, }); client.on('open', () => console.log('Connected')); client.on('message', (data) => console.log('Received:', data)); client.connect() .then(() => { client.subscribe('test/#'); client.send({ type: 'publish', topic: 'test/123', payload: 'Hello World' }); }) .catch(err => console.error('Connection failed:', err));
Debug
Known issues
breakingHeaders must include 'client-type', 'Appid', 'ClientId', 'Timestamp', and 'Authorization' with correct values.
fix
Ensure the headers object has all five required fields. Missing any will cause connection to fail silently.
affects: >=1.0.0
gotchaLibrary is ESM-only; does not export a CommonJS build.
fix
Use import or set type: 'module' in package.json. If you need CJS, consider dynamic import().
affects: >=1.0.0
gotchaThe `connect()` method returns a Promise that never rejects on network errors?
fix
Error handling may require listening to the 'error' event. Check if connect() actually rejects; if not, wrap with timeout.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: client.connect is not a function
Importing incorrectly as CommonJS require().
fix
Use import { OpenIMWebSocket } from 'openim-websocket'.
WebSocket connection to 'ws://...' failed: Error during WebSocket handshake: Unexpected response code: 401
Missing or incorrect Authorization header or expiry.
fix
Verify headers contain valid Authorization: Bearer <token> and that Appid, ClientId, Timestamp are correct and current.
Cannot find module 'openim-websocket'
Package not installed or module resolution failure.
fix
Run npm install openim-websocket. For TypeScript projects, ensure tsconfig includes 'node_modules' or types.
Upgrade
Version history
1.0.41latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
openim-websocket — npm install openim-websocket · libregistry