{"id":48858,"library":"openim-websocket","title":"OpenIM WebSocket Client","description":"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.","status":"active","version":"1.0.41","language":"javascript","source_language":"en","source_url":"https://github.com/Qiutianxiaxue/openim-websocket","tags":["javascript","websocket","openim","typescript","chat","messaging"],"install":[{"cmd":"npm install openim-websocket","lang":"bash","label":"npm"},{"cmd":"yarn add openim-websocket","lang":"bash","label":"yarn"},{"cmd":"pnpm add openim-websocket","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; requires Node.js >= 12 or a bundler. Named export, not default.","wrong":"const OpenIMWebSocket = require('openim-websocket')","symbol":"OpenIMWebSocket","correct":"import { OpenIMWebSocket } from 'openim-websocket'"},{"note":"Message is a TypeScript interface; use import type for type-only usage.","wrong":"import { Message } from 'openim-websocket'","symbol":"Message","correct":"import type { Message } from 'openim-websocket'"},{"note":"WebSocketConfig is a TypeScript interface; type-only import.","wrong":"import { WebSocketConfig } from 'openim-websocket'","symbol":"WebSocketConfig","correct":"import type { WebSocketConfig } from 'openim-websocket'"}],"quickstart":{"code":"import { OpenIMWebSocket } from 'openim-websocket';\n\nconst client = new OpenIMWebSocket({\n  url: process.env.WS_URL ?? 'ws://localhost:10001',\n  enableLogging: true,\n  headers: {\n    'client-type': 'EnterpriseCenterWEB',\n    Appid: process.env.APP_ID ?? '',\n    ClientId: process.env.CLIENT_ID ?? '',\n    Timestamp: String(Date.now()),\n    Authorization: `Bearer ${process.env.TOKEN ?? ''}`,\n  },\n  reconnectInterval: 5000,\n  maxReconnectAttempts: 10,\n});\n\nclient.on('open', () => console.log('Connected'));\nclient.on('message', (data) => console.log('Received:', data));\n\nclient.connect()\n  .then(() => {\n    client.subscribe('test/#');\n    client.send({ type: 'publish', topic: 'test/123', payload: 'Hello World' });\n  })\n  .catch(err => console.error('Connection failed:', err));","lang":"typescript","description":"Initializes OpenIMWebSocket with auth headers, connects, subscribes to a topic, and sends a publish message. Secure via env variables."},"warnings":[{"fix":"Ensure the headers object has all five required fields. Missing any will cause connection to fail silently.","message":"Headers must include 'client-type', 'Appid', 'ClientId', 'Timestamp', and 'Authorization' with correct values.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use import or set type: 'module' in package.json. If you need CJS, consider dynamic import().","message":"Library is ESM-only; does not export a CommonJS build.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Error handling may require listening to the 'error' event. Check if connect() actually rejects; if not, wrap with timeout.","message":"The `connect()` method returns a Promise that never rejects on network errors?","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'activ':55 'appear':54 'appid':44 'auth':68 'authent':27 'automat':25 'backend':41 'base':32 'browser':16 'built':20,66 'built-in':65 'cadenc':53 'capabl':36 'chat':77 'client':3,6,51 'clientid':45 'connect':10 'dedic':60 'differenti':59 'environ':19 'etc':46 'event':31 'event-bas':30 'frequent':57 'generic':49 'header':28 'heavili':37 'javascript':73 'librari':7 'log':69 'logic':72 'messag':33,78 'node.js':18 'openim':1,4,12,40,61,75 'protocol':62 'provid':24 'reconnect':26,71 'releas':52 'requir':43 'server':14 'servic':42 'subscribe/unsubscribe':35 'support':63 'tailor':38 'typescript':22,76 'updat':58 'v1.0.41':8 'websocket':2,5,13,50,74","created_at":"2026-06-07T16:58:49.744574+00:00","updated_at":"2026-06-07T16:58:49.744574+00:00","problems":[{"fix":"Use import { OpenIMWebSocket } from 'openim-websocket'.","cause":"Importing incorrectly as CommonJS require().","error":"TypeError: client.connect is not a function"},{"fix":"Verify headers contain valid Authorization: Bearer <token> and that Appid, ClientId, Timestamp are correct and current.","cause":"Missing or incorrect Authorization header or expiry.","error":"WebSocket connection to 'ws://...' failed: Error during WebSocket handshake: Unexpected response code: 401"},{"fix":"Run npm install openim-websocket. For TypeScript projects, ensure tsconfig includes 'node_modules' or types.","cause":"Package not installed or module resolution failure.","error":"Cannot find module 'openim-websocket'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/Qiutianxiaxue/openim-websocket#readme","github":"https://github.com/Qiutianxiaxue/openim-websocket","docs":null,"changelog":null,"pypi":null,"npm":"openim-websocket","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}