@toast-studios/asset-manager
Version:
A React Native asset management library with intelligent caching and loading strategies
75 lines (74 loc) • 2.22 kB
TypeScript
import { INetworkMonitor, NetworkConditions } from '../types/index';
/**
* Network monitoring utility for React Native - optimized for Indian low-end devices
*/
export declare class NetworkMonitor implements INetworkMonitor {
private isMonitoring;
private unsubscribe?;
private pingTimeoutMs;
private pingTargets;
private lastPingTime;
private cachedPing?;
private pingCacheDuration;
constructor(pingTimeoutMs?: number, pingTargets?: string[]);
/**
* Get current network conditions
*/
getCurrentConditions(): Promise<NetworkConditions>;
/**
* Start monitoring network changes
*/
startMonitoring(callback: (conditions: NetworkConditions) => void): void;
/**
* Stop monitoring network changes
*/
stopMonitoring(): void;
/**
* Static method to test ping target configuration (for testing/debugging purposes)
*
* @param pingTargets Array of ping target URLs to test
* @param pingTimeout Timeout in milliseconds
* @returns Promise with ping results
*/
static testPingTargets(pingTargets?: string[], pingTimeout?: number): Promise<{
targets: string[];
results: Array<{
url: string;
ping?: number;
error?: string;
}>;
median?: number;
}>;
/**
* Measure network ping to configured endpoints - optimized for data efficiency
*/
measurePing(): Promise<number>;
/**
* Ping a specific URL and measure response time
*/
private pingUrl;
/**
* Process NetInfo object into NetworkConditions
*/
private processNetInfo;
/**
* Map NetInfo network type to our NetworkType enum
*/
private mapNetworkType;
/**
* Estimate speed from effective connection type - optimized for Indian networks
*/
private estimateSpeedFromType;
/**
* Estimate speed from connection type when effective type is unavailable
*/
private estimateSpeedFromConnectionType;
/**
* Estimate ping from connection type without network calls
*/
private estimatePingFromConnectionType;
/**
* Cleanup resources
*/
destroy(): void;
}