import { NetworkTierConfig } from '../../config/performance.config'; /** * Network connection type */ export type ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'wifi' | 'wimax' | 'other' | 'none' | 'unknown'; /** * Effective connection type (Network Information API) */ export type EffectiveConnectionType = 'slow-2g' | '2g' | '3g' | '4g'; /** * Request timing breakdown */ export interface RequestTiming { readonly name: string; readonly url: string; readonly startTime: number; readonly duration: number; /** DNS lookup time */ readonly dnsLookup: number; /** TCP connection time */ readonly tcpConnect: number; /** TLS negotiation time (HTTPS only) */ readonly tlsNegotiation: number; /** Time to first byte */ readonly ttfb: number; /** Content download time */ readonly downloadTime: number; /** Transfer size in bytes */ readonly transferSize: number; /** Encoded body size */ readonly encodedBodySize: number; /** Decoded body size */ readonly decodedBodySize: number; /** Resource type */ readonly initiatorType: string; /** Effective bandwidth during this request (bytes/sec) */ readonly effectiveBandwidth: number; /** Server timing entries */ readonly serverTiming: ServerTimingEntry[]; /** Timestamp */ readonly timestamp: number; } /** * Server timing entry */ export interface ServerTimingEntry { readonly name: string; readonly duration: number; readonly description: string; } /** * Network quality metrics */ export interface NetworkQuality { /** Effective connection type */ readonly effectiveType: EffectiveConnectionType; /** Estimated downlink speed in Mbps */ readonly downlink: number; /** Estimated round-trip time in ms */ readonly rtt: number; /** Data saver enabled */ readonly saveData: boolean; /** Connection type */ readonly type: ConnectionType; /** Network tier configuration */ readonly tier: NetworkTierConfig; /** Overall quality score (0-100) */ readonly score: number; /** Is connection metered */ readonly isMetered: boolean; /** Timestamp */ readonly timestamp: number; } /** * Bandwidth measurement */ export interface BandwidthMeasurement { readonly timestamp: number; /** Estimated bandwidth in bytes/sec */ readonly bandwidth: number; /** Number of samples used */ readonly sampleCount: number; /** Confidence level (0-1) */ readonly confidence: number; /** Trend direction */ readonly trend: 'improving' | 'stable' | 'degrading'; } /** * Request priority hint */ export type RequestPriority = 'highest' | 'high' | 'normal' | 'low' | 'lowest'; /** * Priority recommendation */ export interface PriorityRecommendation { readonly url: string; readonly resourceType: string; readonly recommendedPriority: RequestPriority; readonly reason: string; readonly fetchPriority?: 'high' | 'low' | 'auto'; readonly shouldPreload: boolean; readonly shouldPreconnect: boolean; readonly shouldDefer: boolean; } /** * Network statistics */ export interface NetworkStats { readonly totalRequests: number; readonly totalTransferSize: number; readonly averageTtfb: number; readonly averageDownloadTime: number; readonly averageBandwidth: number; readonly p50Ttfb: number; readonly p95Ttfb: number; readonly slowRequests: number; readonly failedRequests: number; readonly requestsByType: Record; readonly sizeByType: Record; } /** * Analyzer configuration */ export interface NetworkAnalyzerConfig { /** Slow request threshold (ms) */ readonly slowThreshold?: number; /** Maximum request history */ readonly maxHistorySize?: number; /** Enable auto-monitoring */ readonly autoMonitor?: boolean; /** Bandwidth measurement interval (ms) */ readonly bandwidthInterval?: number; /** Callback on slow request */ readonly onSlowRequest?: (timing: RequestTiming) => void; /** Callback on network quality change */ readonly onQualityChange?: (quality: NetworkQuality) => void; /** Enable debug logging */ readonly debug?: boolean; } /** * Generate unique ID */ /** * Comprehensive network performance analyzer */ export declare class NetworkPerformanceAnalyzer { private static instance; private readonly config; private readonly requestHistory; private readonly bandwidthHistory; private resourceObserver; private bandwidthIntervalId; private lastQuality; private connectionChangeHandler; /** * Private constructor for singleton pattern */ private constructor(); /** * Get singleton instance */ static getInstance(config?: NetworkAnalyzerConfig): NetworkPerformanceAnalyzer; /** * Reset singleton instance (for testing) */ static resetInstance(): void; /** * Start monitoring network performance */ startMonitoring(): void; /** * Stop monitoring */ stopMonitoring(): void; /** * Analyze a specific request by URL */ analyzeRequest(url: string): RequestTiming | null; /** * Analyze all requests matching a pattern */ analyzeRequestsMatching(pattern: RegExp): RequestTiming[]; /** * Get current network quality */ getQuality(): NetworkQuality; /** * Get quality-based loading strategy */ getLoadingStrategy(): { imageQuality: 'high' | 'medium' | 'low' | 'placeholder'; prefetchStrategy: 'aggressive' | 'moderate' | 'conservative' | 'none'; shouldReduceMotion: boolean; shouldDeferNonCritical: boolean; maxConcurrentRequests: number; }; /** * Measure current bandwidth from recent requests */ measureBandwidth(): BandwidthMeasurement | null; /** * Get estimated bandwidth */ getEstimatedBandwidth(): number; /** * Get priority recommendation for a resource */ getPriorityRecommendation(url: string, resourceType: string, options?: { isAboveFold?: boolean; isLCP?: boolean; isInteractive?: boolean; }): PriorityRecommendation; /** * Get network statistics */ getStats(): NetworkStats; /** * Get request history */ getHistory(): RequestTiming[]; /** * Get slow requests */ getSlowRequests(): RequestTiming[]; /** * Clear history */ clearHistory(): void; /** * Generate network performance report */ generateReport(): string; /** * Start resource timing observer */ private startResourceObserver; /** * Stop resource observer */ private stopResourceObserver; /** * Start bandwidth measurement */ private startBandwidthMeasurement; /** * Stop bandwidth measurement */ private stopBandwidthMeasurement; /** * Start connection change listener */ private startConnectionListener; /** * Stop connection listener */ private stopConnectionListener; /** * Check if network quality has changed significantly */ private hasQualityChanged; /** * Process a resource timing entry */ private processResourceEntry; /** * Calculate bandwidth trend */ private calculateBandwidthTrend; /** * Trim history to max size */ private trimHistory; /** * Debug logging */ private log; } /** * Get the singleton NetworkPerformanceAnalyzer instance */ export declare function getNetworkAnalyzer(config?: NetworkAnalyzerConfig): NetworkPerformanceAnalyzer; /** * Get current network quality (convenience function) */ export declare function getNetworkQuality(): NetworkQuality; /** * Check if on slow connection */ export declare function isSlowConnection(): boolean; /** * Check if data saver is enabled */ export declare function isDataSaverEnabled(): boolean; /** * Get loading strategy based on network */ export declare function getAdaptiveLoadingStrategy(): ReturnType;