UNPKG

fleeta-api-lib

Version:

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

143 lines 4.28 kB
/** * Event WebSocket SDK Implementation * Provides real-time WebPush event communication with FleetA servers */ import { type EventWsEvent, type EventWsEventHandler, type EventConnectionState, type EventWebSocketSDKOptions } from './types'; /** * Event WebSocket SDK Class * Facade pattern: Provides simple interface for WebPush event handling */ export declare class EventWebSocketSDK { private connectionManager; private eventManager; private config; private isInitialized; /** * Create Event WebSocket SDK instance * Authentication is automatically handled via AuthStore * @param options - SDK configuration options (optional) */ constructor(options?: Partial<EventWebSocketSDKOptions>); /** * Initialize the SDK */ initialize(): void; /** * Connect to Event WebSocket server * Automatically uses AuthStore authentication */ connect(): void; /** * Disconnect from Event WebSocket server */ disconnect(): void; /** * Check WebSocket connection status */ isConnected(): boolean; /** * Get current connection state */ getConnectionState(): EventConnectionState; /** * Update authentication from AuthStore * Call this when AuthStore auth state changes */ updateAuthFromStore(): void; /** * Add event listener for WebPush events * @param event - Event type to listen for * @param handler - Event handler function */ on<T = any>(event: EventWsEvent, handler: EventWsEventHandler<T>): void; /** * Remove event listener for WebPush events * @param event - Event type * @param handler - Event handler to remove */ off(event: EventWsEvent, handler: EventWsEventHandler): void; /** * Remove all event listeners for a specific event type * @param event - Event type (optional - removes all if not specified) */ removeAllListeners(event?: EventWsEvent): void; /** * Set PSN filters to receive events only from specific devices * @param psns - Array of PSNs to filter by (empty array = receive all) */ setPsnFilters(psns: string[]): void; /** * Add PSN to filter list * @param psn - PSN to add to filter */ addPsnFilter(psn: string): void; /** * Remove PSN from filter list * @param psn - PSN to remove from filter */ removePsnFilter(psn: string): void; /** * Clear all PSN filters (receive all events) */ clearPsnFilters(): void; /** * Get current PSN filters * @returns Array of current PSN filters */ getPsnFilters(): string[]; /** * Check if PSN filtering is enabled * @returns True if PSN filtering is active */ isPsnFilteringEnabled(): boolean; /** * Set custom PSN extraction function * @param extractorFn - Custom function to extract PSN from message text */ setPsnExtractor(extractorFn: (message: string) => string | null): void; /** * Test PSN extraction on a message (for debugging) * @param message - Message text to test * @returns Extracted PSN or null */ testPsnExtraction(message: string): string | null; /** * Get connection statistics * @returns Connection statistics and status */ getConnectionStats(): { isConnected: boolean; state: EventConnectionState; hasValidAuth: boolean; totalHandlers: number; registeredEvents: EventWsEvent[]; psnFiltering: { enabled: boolean; activeFilters: string[]; filterCount: number; }; }; /** * Destroy SDK and cleanup all resources */ destroy(): void; /** * Generate connection URL with JWT token * @returns WebSocket URL with authentication */ private generateConnectionUrl; /** * Update connection URL with latest authentication */ private updateConnectionUrl; /** * Setup integration between managers */ private setupManagerIntegration; /** * Handle incoming WebSocket messages * @param event - MessageEvent from WebSocket */ private handleMessage; } //# sourceMappingURL=sdk.d.ts.map