fleeta-api-lib
Version:
A comprehensive library for fleet management applications - API, Auth, Device management
253 lines • 8.15 kB
TypeScript
/**
* GPS Data Provider
* Central data management layer between GPS WebSocket SDK and UI components
* Handles data processing, optimization, caching, and distribution to subscribers
*/
import { type DeviceGpsInfo } from '../gps-websocket';
import type { GpsDataProviderConfig, GpsDataStats, GpsDataProviderState } from './types';
/**
* GPS Data Update callback type
*/
export type GpsDataUpdateCallback = (devices: DeviceGpsInfo[]) => void;
export type GpsConnectionCallback = (connected: boolean) => void;
export type GpsErrorCallback = (error: Error) => void;
export type GpsStatsCallback = (stats: GpsDataStats) => void;
/**
* GPS Data Provider Class
* Manages GPS data flow from WebSocket to UI components with optimization and caching
*/
export declare class GpsDataProvider {
private config;
private gpsSDK;
private isInitialized;
private isConnected;
private currentDevices;
private previousDevices;
private deviceHistory;
private updateCallbacks;
private connectionCallbacks;
private errorCallbacks;
private statsCallbacks;
private stats;
private lastUpdateTime;
private updateTimestamps;
private cache;
private batchQueue;
private batchTimer;
private lastProcessTime;
private processingInProgress;
private eventHandlers;
/**
* Create GPS Data Provider instance
* @param config - Provider configuration (uses AuthStore and API endpoints)
*/
constructor(config: Partial<GpsDataProviderConfig>);
/**
* Initialize provider and start WebSocket connection
*/
initialize(): void;
/**
* Connect to GPS WebSocket
*/
connectWebSocket(): void;
/**
* Disconnect from GPS WebSocket (but keep Provider alive)
*/
disconnectWebSocket(): void;
/**
* Check if WebSocket is connected
*/
isWebSocketConnected(): boolean;
/**
* Update authentication from AuthStore
* Call this when AuthStore state changes
*/
updateAuthFromStore(): void;
/**
* Get current JWT token
*/
getCurrentJwtToken(): string | null;
/**
* Get current GPS device data
* @returns Current device data
*/
getCurrentData(): DeviceGpsInfo[];
/**
* Get GPS data history
* @returns Array of historical device data
*/
getDataHistory(): DeviceGpsInfo[][];
/**
* Get current provider state
* @returns Provider state
*/
getState(): GpsDataProviderState;
/**
* Get GPS data for multiple specific devices (Multi Live View)
* @param psnList - List of PSNs to track
*/
requestGpsPsnsMultiLiveView(psnList: string[]): Promise<void>;
/**
* Get GPS data for public devices in zone (no authentication required)
* @param sw - Southwest coordinate (lat_lng format)
* @param ne - Northeast coordinate (lat_lng format)
*/
requestGpsZoneNoAuth(sw: string, ne: string): Promise<void>;
/**
* Get GPS data for user's devices in specified zone
* @param sw - Southwest coordinate (lat_lng format)
* @param ne - Northeast coordinate (lat_lng format)
*/
requestGpsZoneMyDevices(sw: string, ne: string): Promise<void>;
/**
* Get GPS data for all devices in specified zone
* @param sw - Southwest coordinate (lat_lng format)
* @param ne - Northeast coordinate (lat_lng format)
*/
requestGpsZoneAllDevices(sw: string, ne: string): Promise<void>;
/**
* Get GPS data for specific group devices in zone
* @param sw - Southwest coordinate (lat_lng format)
* @param ne - Northeast coordinate (lat_lng format)
* @param groupIdList - Array of group IDs to filter
*/
requestGpsZoneGroupMyDevices(sw: string, ne: string, groupIdList: string[]): Promise<void>;
/**
* Get GPS data for all devices in specific groups within zone
* @param sw - Southwest coordinate (lat_lng format)
* @param ne - Northeast coordinate (lat_lng format)
* @param groupIdList - Array of group IDs to filter
*/
requestGpsZoneGroupAllDevices(sw: string, ne: string, groupIdList: string[]): Promise<void>;
/**
* Get GPS data for all user's devices
*/
requestGpsPsnsMyDevices(): Promise<void>;
/**
* Get GPS data for a specific device
* @param psn - Device PSN (Product Serial Number)
*/
requestGpsPsnsSpecificDevice(psn: string): Promise<void>;
/**
* Register callback for GPS data updates
* @param callback - Function to call when GPS data updates
*/
registerUpdateCallback(callback: GpsDataUpdateCallback): void;
/**
* Unregister GPS data update callback
* @param callback - Function to remove from callbacks
*/
unregisterUpdateCallback(callback: GpsDataUpdateCallback): void;
/**
* Register callback for connection status changes
* @param callback - Function to call when connection status changes
*/
registerConnectionCallback(callback: GpsConnectionCallback): void;
/**
* Unregister connection status callback
* @param callback - Function to remove from callbacks
*/
unregisterConnectionCallback(callback: GpsConnectionCallback): void;
/**
* Register callback for error notifications
* @param callback - Function to call when errors occur
*/
registerErrorCallback(callback: GpsErrorCallback): void;
/**
* Unregister error callback
* @param callback - Function to remove from callbacks
*/
unregisterErrorCallback(callback: GpsErrorCallback): void;
/**
* Register callback for statistics updates
* @param callback - Function to call when stats update
*/
registerStatsCallback(callback: GpsStatsCallback): void;
/**
* Unregister statistics callback
* @param callback - Function to remove from callbacks
*/
unregisterStatsCallback(callback: GpsStatsCallback): void;
/**
* Clear all callbacks (useful for cleanup)
*/
clearAllCallbacks(): void;
/**
* Request data using any GPS WebSocket action (Generic method)
* @param action - GPS WebSocket action name
* @param params - Action-specific parameters
*/
requestGpsData(action: string, params?: any): Promise<void>;
/**
* Destroy provider and cleanup resources
*/
destroy(): void;
/**
* Setup WebSocket event handlers
*/
private setupWebSocketEventHandlers;
/**
* Process incoming GPS data
* @param devices - Raw GPS device data
* @param source - Data source
*/
private processIncomingData;
/**
* Update current device data and statistics
* @param devices - New device data
* @param source - Data source
*/
private updateCurrentData;
/**
* Update provider statistics
*/
private updateStatistics;
/**
* Track update rate for performance monitoring
*/
private trackUpdateRate;
/**
* Notify subscribers of connection changes
* @param connected - Connection status
*/
private notifyConnectionChange;
/**
* Handle errors and notify subscribers
* @param error - Error to handle
*/
private handleError;
/**
* Emit provider event
* @param event - Event type
* @param data - Event data
*/
private emitEvent;
/**
* Start batch processing
*/
private startBatchProcessing;
/**
* Stop batch processing
*/
private stopBatchProcessing;
/**
* Notify all update callbacks with new device data
* @param devices - Updated device data
*/
private notifyUpdateCallbacks;
/**
* Notify all connection callbacks with connection status
* @param connected - Connection status
*/
private notifyConnectionCallbacks;
/**
* Notify all error callbacks with error information
* @param error - Error to notify
*/
private notifyErrorCallbacks;
/**
* Notify all stats callbacks with updated statistics
*/
private notifyStatsCallbacks;
}
//# sourceMappingURL=GpsDataProvider.d.ts.map