fleeta-api-lib
Version:
A comprehensive library for fleet management applications - API, Auth, Device management
159 lines • 5.4 kB
TypeScript
/**
* GPS WebSocket SDK Implementation
* Provides real-time GPS data communication with FleetA servers
*/
import type { GpsWsEvent, GpsWsEventHandler, GpsConnectionState, ActionKey, ActionRequestMap, ActionResponseMap, GpsWebSocketSDKOptions } from './types';
/**
* GPS WebSocket SDK Class
* Facade pattern: Provides simple interface while delegating to specialized managers
*/
export declare class GpsWebSocketSDK {
private connectionManager;
private authManager;
private eventManager;
private requestManager;
private stateMachine;
/**
* Create GPS WebSocket SDK instance
* WebSocket URL is automatically obtained from API endpoint system
* @param options - SDK configuration options (optional, uses AuthStore by default)
*/
constructor(options?: Partial<Omit<GpsWebSocketSDKOptions, 'url' | 'token' | 'email'>>);
/**
* Set JWT authentication token
* Note: This will override AuthStore token temporarily
*/
setToken(token: string): void;
/**
* Update authentication from AuthStore
* Call this when AuthStore auth state changes
*/
updateAuthFromStore(): void;
/**
* Get current JWT token
*/
getCurrentToken(): string | undefined;
/**
* Check if token is set
*/
hasValidToken(): boolean;
/**
* Connect to GPS WebSocket server
* Automatically uses AuthStore authentication
*/
connect(): void;
/**
* Disconnect from GPS WebSocket server
*/
disconnect(): void;
/**
* Check WebSocket connection status
*/
isWebSocketConnected(): boolean;
/**
* Get current connection state
*/
getConnectionState(): GpsConnectionState;
/**
* Get current WebSocket ready state
*/
getReadyState(): number | undefined;
/**
* Generic send method with Promise-based response matching
*/
send<K extends ActionKey>(action: K, payload: Omit<ActionRequestMap[K], "action" | "sequenceId"> & {
sequenceId?: number;
}, timeoutMs?: number): Promise<ActionResponseMap[K]>;
/**
* Add event listener for GPS WebSocket events
*/
on<T = any>(event: GpsWsEvent, handler: GpsWsEventHandler<T>): void;
/**
* Remove event listener for GPS WebSocket events
*/
off(event: GpsWsEvent, handler: GpsWsEventHandler): void;
/**
* Remove all event listeners for a specific event type
*/
removeAllListeners(event?: GpsWsEvent): void;
/**
* Get statistics about the WebSocket connection
*/
getConnectionStats(): {
isConnected: boolean;
state: GpsConnectionState;
hasToken: boolean;
pendingRequests: number;
};
/**
* Destroy SDK and cleanup all resources
*/
destroy(): void;
/**
* Setup integration between managers
*/
private setupManagerIntegration;
/**
* Update connection URL based on auth configuration
*/
private updateConnectionUrl;
/**
* Handle incoming WebSocket messages
*/
private handleMessage;
/**
* Handle real-time GPS data
*/
private handleRealTimeData;
/**
* Ensure authentication before API calls
*/
private ensureAuthenticated;
/**
* Get GPS data for public devices in zone (no authentication required)
* @param sw - Southwest coordinate (lat,lng)
* @param ne - Northeast coordinate (lat,lng)
*/
gpsZoneNoAuth(sw: string, ne: string): Promise<ActionResponseMap['gpsZoneNoAuth']>;
/**
* Get GPS data for user's devices in specified zone
* @param sw - Southwest coordinate (lat,lng)
* @param ne - Northeast coordinate (lat,lng)
*/
gpsZoneMyDevices(sw: string, ne: string): Promise<ActionResponseMap['gpsZoneMyDevices']>;
/**
* Get GPS data for all devices in specified zone
* @param sw - Southwest coordinate (lat,lng)
* @param ne - Northeast coordinate (lat,lng)
*/
gpsZoneAllDevices(sw: string, ne: string): Promise<ActionResponseMap['gpsZoneAllDevices']>;
/**
* Get GPS data for specific group devices in zone
* @param sw - Southwest coordinate (lat,lng)
* @param ne - Northeast coordinate (lat,lng)
* @param groupIdList - Array of group IDs to filter
*/
gpsZoneGroupMyDevices(sw: string, ne: string, groupIdList: string[]): Promise<ActionResponseMap['gpsZoneGroupMyDevices']>;
/**
* Get GPS data for all devices in specific groups within zone
* @param sw - Southwest coordinate (lat,lng)
* @param ne - Northeast coordinate (lat,lng)
* @param groupIdList - Array of group IDs to filter
*/
gpsZoneGroupAllDevices(sw: string, ne: string, groupIdList: string[]): Promise<ActionResponseMap['gpsZoneGroupAllDevices']>;
/**
* Get GPS data for all user's devices
*/
gpsPsnsMyDevices(): Promise<ActionResponseMap['gpsPsnsMyDevices']>;
/**
* Get GPS data for a specific device
* @param psn - Device PSN (Product Serial Number)
*/
gpsPsnsSpecificDevice(psn: string): Promise<ActionResponseMap['gpsPsnsSpecificDevice']>;
/**
* Get GPS data for multiple specific devices (Multi Live View)
* @param psns - Array of device PSNs
*/
gpsPsnsMultiLiveView(psns: string[]): Promise<ActionResponseMap['gpsPsnsMultiLiveView']>;
}
//# sourceMappingURL=sdk.d.ts.map