Registry / messaging / cy-plugin-websocket

cy-plugin-websocket

JSON →
library2.0.5jsnpmunverified

A WebSocket client wrapper library with auto-reconnect (exponential backoff), heartbeat mechanism, message queue, and Emittery-based event system. Version 2.0.5, stable with monthly releases. Key differentiators: full TypeScript support, enum-based event names for type safety, configurable heartbeat and reconnect strategies, and built-in message buffering during disconnection. Requires peer dependency Emittery ^1.2.0.

npm install cy-plugin-websocket
INSTALL
IMPORT
SIG · CY-PLUGIN-WEBSOCKE
C
cy-plugin-websocket
messagingjavascriptv2.0.5
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.

SocketClient
✓ import { SocketClient, enumSocketEvent } from 'cy-plugin-websocket'
✗ import SocketClient from 'cy-plugin-websocket'
Both SocketClient and enumSocketEvent are named exports. Default export does not exist.
enumSocketEvent
✓ import { enumSocketEvent } from 'cy-plugin-websocket'
✗ import { EnumSocketEvent } from 'cy-plugin-websocket'
Exact name is 'enumSocketEvent' (camelCase). Incorrect casing leads to undefined.
ISocketOption
✓ import type { ISocketOption } from 'cy-plugin-websocket'
✗ import { ISocketOption } from 'cy-plugin-websocket'
ISocketOption is a TypeScript interface, should be imported as type for better tree-shaking.

Shows creation of SocketClient with advanced config, connection, event handling using enumSocketEvent, sending a message, and closing the connection.

import { SocketClient, enumSocketEvent } from 'cy-plugin-websocket'; const socket = new SocketClient('wss://example.com/ws', { debug: true, connectResend: true, heartOption: { message: { type: 'ping' }, interval: 30000 }, reconnectOption: { maxCount: 5, interval: 2000, maxInterval: 10000 } }); socket.connect(); socket.on(enumSocketEvent.OPEN, () => console.log('Connected')); socket.on(enumSocketEvent.MESSAGE, (data) => console.log('Message:', data)); socket.on(enumSocketEvent.ERROR, (err) => console.error('Error:', err)); socket.send({ type: 'chat', message: 'Hello World' }); // Later socket.close();
Debug
Known issues
breakingImporting SocketClient as default export fails in versions >=2.0.0
fix
Use named import: import { SocketClient } from 'cy-plugin-websocket'
affects: >=2.0.0
gotchaEvent names must use enumSocketEvent enum, not raw strings
fix
Use enumSocketEvent.OPEN instead of 'open' for type safety and compatibility
affects: >=2.0.0
deprecatedMethod 'on' with string event name is deprecated since 2.0.0
fix
Use enumSocketEvent for event names
affects: >=2.0.0
gotchaHeavy reliance on Emittery peer dependency; missing Emittery causes runtime error
fix
Install emittery@1.2.0 as a dependency: npm install emittery@1.2.0 --save
affects: >=1.0.0
gotchaTypeScript types are exported but not on DefinitelyTyped; use built-in types
fix
No extra @types package needed; types are included in the package
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: emmiter.on is not a function
Missing or incompatible Emittery peer dependency
fix
Install emittery@1.2.0: npm install emittery@1.2.0
Module '"cy-plugin-websocket"' has no exported member 'SocketClient'
Using default import when only named export exists
fix
Use named import: import { SocketClient } from 'cy-plugin-websocket'
Cannot find module 'cy-plugin-websocket' or its corresponding type declarations.
Package not installed or TypeScript not resolving types correctly
fix
Install package: npm install cy-plugin-websocket; ensure tsconfig.json includes node module resolution
Uncaught TypeError: socket.on is not a function
Attempting to use 'on' before calling connect()
fix
Call socket.connect() before adding event listeners
Upgrade
Version history
2.0.5latest on npm
Audit
Dependencies
emitteryrequiredEvent system dependency; must be installed separately as a peer dependency
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
cy-plugin-websocket — npm install cy-plugin-websocket · libregistry