/** * @file Network Utilities * @description Shared utilities for network information and quality detection * * This module provides cross-browser network information access and quality * assessment utilities. It's used by network-aware hooks and prefetching logic. */ /** * Connection quality type based on Network Information API */ export type ConnectionType = '4g' | '3g' | '2g' | 'slow-2g' | 'unknown'; /** * Network information from the Navigator.connection API */ export interface NetworkInformation { /** Effective connection type (4g, 3g, etc.) */ effectiveType?: ConnectionType; /** Estimated downlink speed in Mbps */ downlink?: number; /** Estimated round-trip time in ms */ rtt?: number; /** Whether user has enabled data saver mode */ saveData?: boolean; } /** * Get current network information from browser * * Uses the Network Information API if available. Falls back to safe defaults * if the API is not supported (e.g., Firefox, Safari). * * @returns Current network information * * @example * ```ts * const network = getNetworkInfo(); * console.log(`Connection: ${network.effectiveType}, RTT: ${network.rtt}ms`); * ``` */ export declare function getNetworkInfo(): NetworkInformation; /** * Check if current connection meets minimum quality requirement * * @param current - Current connection type * @param minimum - Minimum required connection type * @returns True if current meets or exceeds minimum quality * * @example * ```ts * if (meetsMinimumQuality(network.effectiveType, '3g')) { * // Load high-quality assets * } * ``` */ export declare function meetsMinimumQuality(current: ConnectionType, minimum: ConnectionType): boolean; /** * Check if prefetching should be allowed based on network conditions * * @param options - Prefetch configuration options * @param options.respectDataSaver - Skip prefetch if data saver is enabled * @param options.minConnectionQuality - Minimum connection quality required * @returns True if prefetching should proceed * * @example * ```ts * if (shouldAllowPrefetch({ minConnectionQuality: '3g' })) { * prefetchData(); * } * ``` */ export declare function shouldAllowPrefetch(options?: { respectDataSaver?: boolean; minConnectionQuality?: ConnectionType; }): boolean; /** * Monitor network quality changes * * Sets up an event listener for network quality changes. Returns a cleanup * function to remove the listener. * * @param callback - Function called when network quality changes * @returns Cleanup function to remove the listener * * @example * ```ts * const unsubscribe = monitorNetworkQuality((info) => { * console.log('Network changed:', info.effectiveType); * }); * * // Later, cleanup * unsubscribe(); * ``` */ export declare function monitorNetworkQuality(callback: (info: NetworkInformation) => void): () => void; /** * Check if connection is considered slow * * A connection is slow if it's 2G/slow-2G, has low downlink speed, * high RTT, or data saver mode is enabled. * * @param threshold - Optional custom thresholds * @returns True if connection is slow */ export declare function isSlowConnection(threshold?: { maxDownlink?: number; maxRtt?: number; }): boolean; /** * Get descriptive quality label for connection * * @returns Human-readable quality label */ export declare function getConnectionQualityLabel(type?: ConnectionType): string;