UNPKG

@snap/camera-kit

Version:
101 lines 5.01 kB
import type { Lens } from "../Lens"; import type { RequestStateEventTarget } from "../../handlers/requestStateEmittingHandler"; import type { LensAssetManifestItem } from "../../generated-proto/pb_schema/camera_kit/v3/lens"; import { LensAssetManifestItem_RequestTiming, LensAssetManifestItem_Type } from "../../generated-proto/pb_schema/camera_kit/v3/lens"; import type { MetricsEventTarget } from "../../metrics/metricsEventTarget"; import type { AssetDescriptor, AssetType } from "../../lens-core-module/generated-types"; import type { LensCore } from "../../lens-core-module/lensCore"; export declare function mapManfiestItemToAssetType(lensCore: LensCore, type: LensAssetManifestItem_Type): AssetType; export interface Asset { assetId: string; assetBuffer: ArrayBuffer; assetType: AssetType; assetChecksum: string | undefined; } export type AssetResponse = ArrayBuffer | { data: ArrayBuffer; checksum?: string; }; /** * Represents a request for loading assets through {@link AssetLoader}. This object specifies the asset to be loaded, * optionally defines the lens context, includes an asset manifest if available, and indicates the priority of the load. * * @category Lenses */ export interface LoadAssetRequest { /** * Describes the asset to be loaded. */ assetDescriptor: AssetDescriptor; /** * Specifies the lens context for the asset load, if applicable. */ lens: Lens | undefined; /** * Lens asset manifest. */ assetManifest: LensAssetManifestItem[]; /** * Indicates whether the asset fetch should be treated with lower priority compared to other * network requests on the page. When set to true, this request may be deferred in favor of higher-priority * traffic, potentially improving overall page responsiveness and load times for critical assets. */ lowPriority: boolean; } /** * An AssetLoader is used to retrieve assets. A separate loader may be defined to retrieve different asset types. * * @category Lenses * * @param request The {@link LoadAssetRequest} detailing the asset to be loaded, its context, and loading priority. * @returns A promise that resolves to an {@link AssetResponse} for asynchronous loading, * or an {@link AssetResponse} directly for synchronous operations. */ export type AssetLoader = (request: LoadAssetRequest) => Promise<AssetResponse> | AssetResponse; /** * Registers a remote asset provider function with a given instance of LensCore, and uses a provided mapping of asset * types to loading functions to acquire remote asset data and pass it to LensCore. * * *Note:* LensCoreModule.initialize must be called on the desired LensCoreModule instance **prior** to passing it * to the LensAssetProvider constructor. If this class is instantiated with a LensCoreModule that has not been * initialized, the registry of the asset provider function will fail silently and no remote assets will be loaded. */ export declare class LensAssetRepository { private readonly lensCore; private readonly assetLoaders; private readonly metrics; private readonly requestStateEventTarget; private readonly cachedAssetKeys; constructor(lensCore: LensCore, assetLoaders: Map<AssetType, [keyof LensCore["AssetType"], AssetLoader]>, metrics: MetricsEventTarget, requestStateEventTarget: RequestStateEventTarget); /** * Caches lens assets defined in asset manifest. * * @param assetManifest Lens asset manifest. * @param lens Lens to cache assets of. * @param assetTimings Optionally specifies what assets to cache. By default, on-demand assets are not cached. * @returns Promise rejects if any required assets could not be loaded – if this occurs, it's very likely the Lens * with this manifest will not function. */ cacheAssets(assetManifest: LensAssetManifestItem[], lens: Lens, assetTimings?: LensAssetManifestItem_RequestTiming[], lowPriority?: boolean): Promise<void>; /** * Calls the correct asset loader to fetch the asset's data, * depending on the requested asset's type and provides that to LensCore. */ loadAsset(request: LoadAssetRequest): Promise<void>; /** * Downloads and caches assets if applicable. Does nothing for assets that are already in cache. * @param assetDescriptors Asset ID and type pairs. * @param lens Lens to load assets for. * @param assetManifest Lens asset manifest. */ private cacheAssetsByDescriptor; } /** * @internal */ export declare const lensAssetRepositoryFactory: { (args_0: LensCore, args_1: AssetLoader, args_2: AssetLoader, args_3: AssetLoader, args_4: MetricsEventTarget, args_5: RequestStateEventTarget): LensAssetRepository; token: "lensAssetRepository"; dependencies: readonly ["lensCore", "deviceDependentAssetLoader", "remoteMediaAssetLoader", "staticAssetLoader", "metricsEventTarget", "requestStateEventTarget"]; }; //# sourceMappingURL=LensAssetRepository.d.ts.map