UNPKG

fleeta-api-lib

Version:

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

124 lines 3.98 kB
/** * GPS WebSocket SDK Utility Functions * Helper functions for GPS coordinate handling and data processing */ import type { DeviceGpsInfo } from './types'; /** * Coordinate bounds interface for map zones */ export interface CoordinateBounds { sw: { lat: number; lng: number; }; ne: { lat: number; lng: number; }; } /** * Convert coordinate bounds to string format required by GPS WebSocket API * @param bounds - Coordinate bounds object * @returns Formatted coordinate strings for sw and ne */ export declare function boundsToCoordinateStrings(bounds: CoordinateBounds): { sw: string; ne: string; }; /** * Parse coordinate string to lat/lng object * @param coordString - Coordinate string in format "lat,lng" * @returns Parsed coordinate object */ export declare function parseCoordinateString(coordString: string): { lat: number; lng: number; }; /** * Validate coordinate bounds * @param bounds - Coordinate bounds to validate * @returns True if bounds are valid */ export declare function validateCoordinateBounds(bounds: CoordinateBounds): boolean; /** * Filter active devices from device list * @param devices - Array of device GPS info * @returns Array of active devices only */ export declare function filterActiveDevices(devices: DeviceGpsInfo[]): DeviceGpsInfo[]; /** * Filter devices by video sharing status * @param devices - Array of device GPS info * @param shareVideo - Video sharing status to filter by * @returns Array of devices with matching video sharing status */ export declare function filterDevicesByVideoSharing(devices: DeviceGpsInfo[], shareVideo: 'on' | 'off'): DeviceGpsInfo[]; /** * Calculate distance between two GPS coordinates (Haversine formula) * @param lat1 - Latitude of first point * @param lng1 - Longitude of first point * @param lat2 - Latitude of second point * @param lng2 - Longitude of second point * @returns Distance in kilometers */ export declare function calculateDistance(lat1: number, lng1: number, lat2: number, lng2: number): number; /** * Convert speed units * @param speedKmh - Speed in km/h * @param targetUnit - Target unit ('mph' or 'knots') * @returns Converted speed */ export declare function convertSpeed(speedKmh: number, targetUnit: 'mph' | 'knots'): number; /** * Normalize direction angle to 0-360 range * @param angle - Direction angle in degrees * @returns Normalized angle (0-360) */ export declare function normalizeDirectionAngle(angle: number | "undefined"): number | null; /** * Get direction name from angle * @param angle - Direction angle in degrees * @returns Direction name (N, NE, E, SE, S, SW, W, NW) */ export declare function getDirectionName(angle: number | "undefined"): string; /** * Format device GPS data for display * @param device - Device GPS information * @returns Formatted device data */ export declare function formatDeviceGpsData(device: DeviceGpsInfo): { name: string; location: string; speed: string; direction: string; status: string; }; /** * Group devices by their status * @param devices - Array of device GPS info * @returns Grouped devices by status */ export declare function groupDevicesByStatus(devices: DeviceGpsInfo[]): { active: DeviceGpsInfo[]; inactive: DeviceGpsInfo[]; videoSharing: DeviceGpsInfo[]; }; /** * Create a debounced function for GPS requests * Useful for preventing too frequent GPS updates * @param func - Function to debounce * @param delay - Delay in milliseconds * @returns Debounced function */ export declare function debounce<T extends (...args: any[]) => void>(func: T, delay: number): (...args: Parameters<T>) => void; /** * WebSocket connection state helper */ export declare const WebSocketState: { readonly CONNECTING: 0; readonly OPEN: 1; readonly CLOSING: 2; readonly CLOSED: 3; readonly getName: (state: number) => string; }; //# sourceMappingURL=utils.d.ts.map