UNPKG

fleeta-api-lib

Version:

A comprehensive library for fleet management applications - API, Auth, Device management

105 lines 2.71 kB
/** * Event WebSocket Connection Manager * Handles WebSocket connection lifecycle for WebPush events */ import type { EventConnectionState } from './types'; /** * Connection configuration interface */ export interface EventConnectionConfig { url: string; maxReconnectAttempts: number; reconnectDelay: number; heartbeatInterval?: number; } /** * Connection event callbacks */ export interface EventConnectionCallbacks { onOpen?: () => void; onClose?: (event: CloseEvent) => void; onError?: (error: Event) => void; onMessage?: (event: MessageEvent) => void; onStateChange?: (state: EventConnectionState) => void; } /** * WebSocket dependency interface for testing */ export interface EventWebSocketDependency { new (url: string): WebSocket; } /** * Event Connection Manager class * Manages WebSocket connection for WebPush events with automatic reconnection */ export declare class EventConnectionManager { private config; private callbacks; private WebSocketClass; private ws; private currentState; private reconnectTimer; private heartbeatTimer; private reconnectAttempts; private isConnecting; /** * Create event connection manager * @param config - Connection configuration * @param WebSocketClass - WebSocket constructor for dependency injection * @param callbacks - Event callbacks */ constructor(config: EventConnectionConfig, WebSocketClass?: EventWebSocketDependency, callbacks?: EventConnectionCallbacks); /** * Connect to Event WebSocket server */ connect(): void; /** * Disconnect from Event WebSocket server */ disconnect(): void; /** * Get current connection state */ getState(): EventConnectionState; /** * Check if WebSocket is connected */ isConnected(): boolean; /** * Update connection configuration */ updateConfig(newConfig: Partial<EventConnectionConfig>): void; /** * Update callbacks */ setCallbacks(callbacks: EventConnectionCallbacks): void; /** * Destroy connection manager */ destroy(): void; /** * Setup WebSocket event handlers */ private setupWebSocketHandlers; /** * Schedule automatic reconnection */ private scheduleReconnect; /** * Start heartbeat monitoring */ private startHeartbeat; /** * Clear reconnection timer */ private clearReconnectTimer; /** * Clear heartbeat timer */ private clearHeartbeatTimer; /** * Set connection state and notify callbacks */ private setState; } //# sourceMappingURL=ConnectionManager.d.ts.map