@magnaflow/ws-client
v1.0.2
Published
WebSocket client library with message queue, reconnection, and push message handling
Maintainers
Readme
@magnaflow/ws-client
WebSocket client primitives with queueing, heartbeat, reconnection, and push-message handling.
What It Provides
WebSocketServiceas the high-level clientWebSocketCorefor low-level connection lifecycleMessageManagerfor request/response matchingTasksServicefor scheduled maintenance tasksPushMessageServicefor typed push-message registration
Install
npm install @magnaflow/ws-clientKey Exports
WebSocketServiceWebSocketCoreMessageManagerTasksServicePushMessageServiceEventEmittergenerateUniqueIdWEBSOCKET_EVENTSHEARTBEAT_CONFIGRECONNECTION_CONFIGMESSAGE_CONFIGTASK_CONFIGERROR_MESSAGESLOG_MESSAGES
Example
import { WebSocketService, WEBSOCKET_EVENTS } from '@magnaflow/ws-client';
const ws = new WebSocketService({
reconnect: {
maxAttempts: 5,
baseDelay: 1000,
maxDelay: 30000,
},
});
await ws.connectAsync('wss://example.com/ws');
ws.on(WEBSOCKET_EVENTS.CONNECT, () => {
console.log('connected');
});Notes
- This package assumes a browser-like WebSocket runtime.
- Request/response matching is based on
noncevalues managed byMessageManager.
Development
bunx nx run ws-client:lint
bunx nx run ws-client:test
bunx nx run ws-client:buildLicense
This package is part of the merchant-v2-sdk monorepo and is covered by the root MIT license.
See ../../LICENSE for details.
