UNPKG

@toast-studios/asset-manager

Version:

A React Native asset management library with intelligent caching and loading strategies

137 lines (136 loc) 3.73 kB
import { Asset, AssetManagerConfig, AssetManifest, DownloadProgress, EventCallback, NetworkConditions, StorageInfo } from '../types/index'; /** * Main Toast Asset Manager class for intelligent asset downloading and management */ export declare class ToastAssetManager { private config; private manifest?; private networkMonitor; private storageManager; private downloadManager; private strategy; private downloadQueue; private processing; private destroyed; private currentNetworkConditions?; private progressCallback?; private gameReadyCallback?; private networkChangeCallback?; constructor(config: Partial<AssetManagerConfig>); /** * Start the complete asset management process - initialize, load manifest, and begin downloads */ start(manifest?: AssetManifest): Promise<void>; /** * Initialize the asset manager */ private initialize; /** * Load asset manifest - either from parameter or from configured URL */ private loadManifest; /** * Fetch manifest from the configured URL with app version and language parameters */ private fetchManifestFromUrl; /** * Start downloading assets based on current strategy */ private startDownloads; /** * Check if game is ready to play (all default assets downloaded) */ isGameReadyToPlay(): Promise<boolean>; /** * Get path to a specific asset */ getAssetPath(asset: Asset): string; /** * Get asset by ID */ getAsset(assetId: string): Asset | undefined; /** * Get storage information */ getStorageInfo(): Promise<StorageInfo>; /** * Get hash-based deduplication statistics */ getDeduplicationStats(): Promise<{ totalAssets: number; uniqueFiles: number; savedSpace: number; dedupRatio: number; savedSpaceMB: number; }>; /** * Get the actual file path for an asset by ID (resolves hash-based references) */ getAssetPathById(assetId: string): Promise<string | null>; /** * Cleanup old assets */ cleanup(): Promise<number>; /** * Set progress callback for download updates */ onProgress(callback: EventCallback<DownloadProgress>): void; /** * Set game ready callback */ onGameReady(callback: EventCallback<boolean>): void; /** * Set network change callback */ onNetworkChange(callback: EventCallback<NetworkConditions>): void; /** * Destroy the asset manager and cleanup resources */ destroy(): Promise<void>; /** * Manually flush all pending storage operations to disk * Useful before critical operations or app shutdown */ flushStorage(): Promise<void>; /** * Get storage batching statistics * Useful for monitoring and debugging performance */ getStorageBatchingStats(): { pendingAssetUpdates: number; pendingHashUpdates: number; hasPendingTimer: boolean; }; /** * Queue a bundle for download */ private queueDownload; /** * Process download queue with concurrency control */ private processDownloadQueue; /** * Start downloading a bundle */ private startBundleDownload; /** * Get bundle priority */ private getBundlePriority; /** * Find asset by ID across all bundles */ private findAssetById; /** * Handle network condition changes */ private handleNetworkChange; /** * Start automatic cleanup */ private startAutoCleanup; /** * Log message if logging is enabled */ private log; }