@snap/camera-kit 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -15
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/CameraKit.html +5 -3
- package/docs/html/classes/CameraKitSession.html +5 -4
- package/docs/html/classes/CameraKitSource.html +5 -3
- package/docs/html/classes/LensPerformanceMeasurement.html +5 -3
- package/docs/html/classes/LensPerformanceMetrics.html +5 -3
- package/docs/html/classes/LensRepository.html +5 -3
- package/docs/html/classes/LensSources.html +5 -3
- package/docs/html/classes/Transform2D.html +5 -3
- package/docs/html/classes/TypedCustomEvent.html +5 -3
- package/docs/html/classes/TypedEventTarget.html +5 -3
- package/docs/html/functions/Injectable.html +5 -3
- package/docs/html/functions/bootstrapCameraKit.html +5 -3
- package/docs/html/functions/createExtension.html +5 -3
- package/docs/html/functions/createImageSource.html +5 -3
- package/docs/html/functions/createMediaStreamSource.html +6 -4
- package/docs/html/functions/createUserMediaSource.html +9 -3
- package/docs/html/functions/createVideoSource.html +5 -3
- package/docs/html/functions/estimateLensPerformance.html +5 -3
- package/docs/html/functions/getRequiredBootstrapURLs.html +5 -3
- package/docs/html/functions/lensSourcesFactory.html +5 -3
- package/docs/html/functions/uriHandlersFactory.html +5 -3
- package/docs/html/index.html +11 -9
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +5 -3
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +5 -3
- package/docs/html/interfaces/ComputedFrameMetrics.html +5 -3
- package/docs/html/interfaces/CreateSessionOptions.html +5 -3
- package/docs/html/interfaces/EstimatedLensPerformance.html +5 -3
- package/docs/html/interfaces/Lens.html +16 -6
- package/docs/html/interfaces/LensSource.html +5 -3
- package/docs/html/interfaces/MediaStreamSourceOptions.html +5 -3
- package/docs/html/interfaces/Preview.html +133 -0
- package/docs/html/interfaces/Snapcode.html +140 -0
- package/docs/html/interfaces/UriCancelRequest.html +5 -3
- package/docs/html/interfaces/UriHandler.html +5 -3
- package/docs/html/interfaces/UriRequest.html +5 -3
- package/docs/html/interfaces/UriResponse.html +5 -3
- package/docs/html/interfaces/VideoSourceOptions.html +5 -3
- package/docs/html/modules.html +8 -4
- package/docs/html/types/AssetLoader.html +5 -3
- package/docs/html/types/AssetTiming.html +5 -3
- package/docs/html/types/BenchmarkError.html +5 -3
- package/docs/html/types/BootstrapError.html +5 -3
- package/docs/html/types/CacheKeyNotFoundError.html +5 -3
- package/docs/html/types/CameraKitDeviceInfo.html +5 -3
- package/docs/html/types/CameraKitSessionEventListener.html +5 -3
- package/docs/html/types/CameraKitSessionEvents.html +5 -3
- package/docs/html/types/CameraKitSourceError.html +5 -3
- package/docs/html/types/CameraKitSourceInfo.html +5 -3
- package/docs/html/types/CameraKitSourceOptions.html +5 -3
- package/docs/html/types/ConfigurationError.html +5 -3
- package/docs/html/types/Keyboard.html +5 -3
- package/docs/html/types/KeyboardEvents.html +5 -3
- package/docs/html/types/LegalError.html +5 -3
- package/docs/html/types/LensAssetError.html +5 -3
- package/docs/html/types/LensContentValidationError.html +5 -3
- package/docs/html/types/LensError.html +5 -3
- package/docs/html/types/LensExecutionError.html +5 -3
- package/docs/html/types/LensImagePickerError.html +5 -3
- package/docs/html/types/LensLaunchParams.html +5 -3
- package/docs/html/types/LensMetricsEvents.html +5 -3
- package/docs/html/types/LensPerformanceCluster.html +5 -3
- package/docs/html/types/LensView.html +5 -3
- package/docs/html/types/LensWait.html +5 -3
- package/docs/html/types/PersistentStoreError.html +5 -3
- package/docs/html/types/PlatformNotSupportedError.html +5 -3
- package/docs/html/types/PublicContainer.html +5 -3
- package/docs/html/types/RenderTarget.html +5 -3
- package/docs/html/types/Uri.html +5 -3
- package/docs/html/types/UriHandlers.html +5 -3
- package/docs/html/types/WebGLError.html +5 -3
- package/docs/html/variables/extensionRequestContext.html +5 -3
- package/docs/md/README.md +18 -15
- package/docs/md/classes/CameraKit.md +1 -1
- package/docs/md/classes/CameraKitSession.md +1 -2
- package/docs/md/classes/CameraKitSource.md +1 -1
- package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
- package/docs/md/classes/LensPerformanceMetrics.md +1 -1
- package/docs/md/classes/LensRepository.md +1 -1
- package/docs/md/classes/LensSources.md +1 -1
- package/docs/md/classes/Transform2D.md +1 -1
- package/docs/md/classes/TypedCustomEvent.md +1 -1
- package/docs/md/classes/TypedEventTarget.md +1 -1
- package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +1 -1
- package/docs/md/interfaces/CameraKitSourceSubscriber.md +1 -1
- package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
- package/docs/md/interfaces/CreateSessionOptions.md +1 -1
- package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
- package/docs/md/interfaces/Lens.md +14 -3
- package/docs/md/interfaces/LensSource.md +1 -1
- package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
- package/docs/md/interfaces/Preview.md +19 -0
- package/docs/md/interfaces/Snapcode.md +28 -0
- package/docs/md/interfaces/UriCancelRequest.md +1 -1
- package/docs/md/interfaces/UriHandler.md +1 -1
- package/docs/md/interfaces/UriRequest.md +1 -1
- package/docs/md/interfaces/UriResponse.md +1 -1
- package/docs/md/interfaces/VideoSourceOptions.md +1 -1
- package/docs/md/modules.md +11 -3
- package/lib/CameraKit.d.ts +10 -6
- package/lib/CameraKit.js +2 -1
- package/lib/CameraKit.js.map +1 -1
- package/lib/__tests__/data.js +9 -1
- package/lib/__tests__/data.js.map +1 -1
- package/lib/assertPlatformSupported.js +1 -1
- package/lib/assertPlatformSupported.js.map +1 -1
- package/lib/benchmark/webglUtils.js +2 -2
- package/lib/benchmark/webglUtils.js.map +1 -1
- package/lib/bootstrapCameraKit.js +4 -2
- package/lib/bootstrapCameraKit.js.map +1 -1
- package/lib/common/validate.js +2 -2
- package/lib/common/validate.js.map +1 -1
- package/lib/dependency-injection/RootServices.d.ts +2 -0
- package/lib/dependency-injection/RootServices.js.map +1 -1
- package/lib/environment.json +1 -1
- package/lib/events/scan.js +1 -1
- package/lib/events/scan.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +17 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +63 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +38 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +64 -3
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +70 -2
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +457 -3
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +109 -3
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +1339 -1852
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +55 -132
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +8 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +181 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +406 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +42 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
- package/lib/generated-proto/pb_schema/common/ruid.d.ts +2 -0
- package/lib/generated-proto/pb_schema/common/ruid.js +2 -0
- package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -1
- package/lib/generated-proto/pb_schema/common/value.d.ts +22 -0
- package/lib/generated-proto/pb_schema/common/value.js +45 -0
- package/lib/generated-proto/pb_schema/common/value.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +2 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.js +12 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -1
- package/lib/handlers/HandlerChainBuilder.d.ts +15 -0
- package/lib/handlers/HandlerChainBuilder.js +8 -1
- package/lib/handlers/HandlerChainBuilder.js.map +1 -1
- package/lib/handlers/requestStateEmittingHandler.d.ts +18 -5
- package/lib/handlers/requestStateEmittingHandler.js +12 -8
- package/lib/handlers/requestStateEmittingHandler.js.map +1 -1
- package/lib/handlers/responseCachingHandler.d.ts +10 -2
- package/lib/handlers/responseCachingHandler.js +13 -4
- package/lib/handlers/responseCachingHandler.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js.map +1 -1
- package/lib/lens/Lens.d.ts +32 -3
- package/lib/lens/Lens.js +10 -3
- package/lib/lens/Lens.js.map +1 -1
- package/lib/lens/LensLaunchParams.js +6 -4
- package/lib/lens/LensLaunchParams.js.map +1 -1
- package/lib/lens/LensPersistenceStore.js +1 -1
- package/lib/lens/LensPersistenceStore.js.map +1 -1
- package/lib/lens/LensRepository.d.ts +3 -2
- package/lib/lens/LensRepository.js +6 -5
- package/lib/lens/LensRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetRepository.d.ts +5 -3
- package/lib/lens/assets/LensAssetRepository.js +21 -12
- package/lib/lens/assets/LensAssetRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetsProvider.js +1 -1
- package/lib/lens/assets/LensAssetsProvider.js.map +1 -1
- package/lib/lens/lensEnvelopeUtil.js +1 -1
- package/lib/lens/lensEnvelopeUtil.js.map +1 -1
- package/lib/lens-client-interface/imagePicker.js +2 -2
- package/lib/lens-client-interface/imagePicker.js.map +1 -1
- package/lib/lens-client-interface/lensClientInterface.js +1 -1
- package/lib/lens-client-interface/lensClientInterface.js.map +1 -1
- package/lib/lens-core-module/loader/lensCoreFactory.js +1 -1
- package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -1
- package/lib/lensCoreWasmVersions.json +3 -3
- package/lib/media-sources/FunctionSource.js +1 -1
- package/lib/media-sources/FunctionSource.js.map +1 -1
- package/lib/media-sources/MediaStreamSource.d.ts +5 -1
- package/lib/media-sources/MediaStreamSource.js +30 -6
- package/lib/media-sources/MediaStreamSource.js.map +1 -1
- package/lib/metrics/reporters/reportHttpMetrics.d.ts +3 -3
- package/lib/metrics/reporters/reportHttpMetrics.js +2 -2
- package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
- package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +3 -3
- package/lib/metrics/reporters/reportLensAndAssetDownload.js +6 -2
- package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -1
- package/lib/metrics/reporters/reporters.d.ts +3 -2
- package/lib/remote-configuration/cofHandler.d.ts +4 -1
- package/lib/remote-configuration/cofHandler.js +10 -6
- package/lib/remote-configuration/cofHandler.js.map +1 -1
- package/lib/remote-configuration/remoteConfiguration.d.ts +5 -3
- package/lib/remote-configuration/remoteConfiguration.js +6 -4
- package/lib/remote-configuration/remoteConfiguration.js.map +1 -1
- package/lib/session/CameraKitSession.d.ts +0 -1
- package/lib/session/CameraKitSession.js +4 -4
- package/lib/session/CameraKitSession.js.map +1 -1
- package/lib/session/lensState.js +2 -3
- package/lib/session/lensState.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensAssetRepository.js","sourceRoot":"","sources":["../../../src/lens/assets/LensAssetRepository.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAEnE,OAAO,EACH,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,GACzB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAEH,mCAAmC,EACnC,0BAA0B,GAC7B,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAA8B,eAAe,EAAkB,MAAM,wBAAwB,CAAC;AACrG,OAA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AI,SAAS,CAAC,KAAK,IAAI,EACnF,EAAE,KAAK,EAAE,KAAK,EAAE,CACnB,CACJ,CAAC;iBACL;YACL,CAAC,CAAA,CAAC,CACT,CAAC;QACN,CAAC;KAAA;CACJ;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAChD,qBAAqB,EACrB;IACI,eAAe,CAAC,KAAK;IACrB,iCAAiC,CAAC,KAAK;IACvC,6BAA6B,CAAC,KAAK;IACnC,wBAAwB,CAAC,KAAK;IAC9B,yBAAyB,CAAC,KAAK;CACzB,EACV,CACI,QAAwB,EACxB,0BAAuC,EACvC,sBAAmC,EACnC,iBAA8B,EAC9B,OAA2B,EAC7B,EAAE,CACA,IAAI,mBAAmB,CACnB,QAAQ,EACR,IAAI,GAAG,CAAC;IACJ,CAAC,QAAQ,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC,iBAAiB,EAAE,0BAA0B,CAAC,CAAC;IACrF,CAAC,QAAQ,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,CAAC;IACnF,oEAAoE;IACpE,yEAAyE;IACzE,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;IACzD,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;CAC7D,CAAC,EACF,OAAO,CACV,CACR,CAAC","sourcesContent":["import { ensureError } from \"../../common/errorHelpers\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { Lens } from \"../Lens\";\nimport {\n dispatchRequestCompleted,\n dispatchRequestErrored,\n dispatchRequestStarted,\n} from \"../../handlers/requestStateEmittingHandler\";\nimport { AssetDownloadDimensions } from \"../../metrics/reporters/reportLensAndAssetDownload\";\nimport {\n LensAssetManifestItem,\n LensAssetManifestItem_RequestTiming,\n LensAssetManifestItem_Type,\n} from \"../../generated-proto/pb_schema/camera_kit/v3/lens\";\nimport { AssetDescriptor, AssetType, lensCoreFactory, LensCoreModule } from \"../../lens-core-module\";\nimport { assertUnreachable } from \"../../common/assertions\";\nimport { getLogger } from \"../../logger/logger\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"../../metrics/metricsEventTarget\";\nimport { TypedCustomEvent } from \"../../events/TypedCustomEvent\";\nimport { deviceDependentAssetLoaderFactory } from \"./deviceDependentAssetLoader\";\nimport { remoteMediaAssetLoaderFactory } from \"./remoteMediaAssetLoaderFactory\";\nimport { staticAssetLoaderFactory } from \"./staticAssetLoader\";\n\nconst logger = getLogger(\"LensAssetRepository\");\n\n/**\n * Computes cache key for asset ID and loader type pair.\n * @param asset Asset ID and loader type pair.\n * @returns Cache key.\n */\nfunction getCacheKey(asset: AssetDescriptor) {\n return `${asset.assetId}_${asset.assetType.value}`;\n}\n\nexport function mapManfiestItemToAssetType(lensCore: LensCoreModule, type: LensAssetManifestItem_Type): AssetType {\n switch (type) {\n case LensAssetManifestItem_Type.ASSET:\n return lensCore.AssetType.Static;\n case LensAssetManifestItem_Type.DEVICE_DEPENDENT_ASSET_UNSET:\n case LensAssetManifestItem_Type.UNRECOGNIZED:\n return lensCore.AssetType.DeviceDependent;\n default:\n return assertUnreachable(type);\n }\n}\n\nexport interface Asset {\n assetId: string;\n assetBuffer: ArrayBuffer;\n assetType: AssetType;\n assetChecksum: string | undefined;\n}\n\nexport type AssetResponse =\n | ArrayBuffer\n | {\n data: ArrayBuffer;\n checksum?: string;\n };\n\n/**\n * An AssetLoader is used to retrieve assets. A separate loader may be defined to retrieve different asset types.\n *\n * @category Lenses\n */\nexport type AssetLoader = (\n asset: AssetDescriptor,\n lens?: Lens,\n assetManifest?: LensAssetManifestItem[]\n) => Promise<AssetResponse> | AssetResponse;\n\n/**\n * Registers a remote asset provider function with a given instance of LensCore, and uses a provided mapping of asset\n * types to loading functions to acquire remote asset data and pass it to LensCore.\n *\n * *Note:* LensCoreModule.initialize must be called on the desired LensCoreModule instance **prior** to passing it\n * to the LensAssetProvider constructor. If this class is instantiated with a LensCoreModule that has not been\n * initialized, the registry of the asset provider function will fail silently and no remote assets will be loaded.\n */\nexport class LensAssetRepository {\n private readonly cachedAssetKeys = new Set<string>();\n\n constructor(\n private readonly lensCore: LensCoreModule,\n private readonly assetLoaders: Map<AssetType, [keyof LensCoreModule[\"AssetType\"], AssetLoader]>,\n private readonly metrics: MetricsEventTarget\n ) {}\n\n /**\n * Caches lens assets defined in asset manifest.\n *\n * @param assetManifest Lens asset manifest.\n * @param lens Lens to cache assets of.\n * @param assetTimings Optionally specifies what assets to cache. By default, on-demand assets are not cached.\n * @returns Promise rejects if any required assets could not be loaded – if this occurs, it's very likely the Lens\n * with this manifest will not function.\n */\n public async cacheAssets(\n assetManifest: LensAssetManifestItem[],\n lens: Lens,\n assetTimings: LensAssetManifestItem_RequestTiming[] = [LensAssetManifestItem_RequestTiming.REQUIRED]\n ): Promise<void> {\n const assetTimingsToPreload = new Set([\n // That is a bad naming, but PRELOAD_UNSET actually means\n // that an asset has to be preloaded\n LensAssetManifestItem_RequestTiming.PRELOAD_UNSET,\n ...assetTimings,\n ]);\n const assetDescriptors = assetManifest\n .filter((asset) => {\n return assetTimingsToPreload.has(asset.requestTiming);\n })\n .map(({ id, type }) => ({\n assetId: id,\n assetType: mapManfiestItemToAssetType(this.lensCore, type),\n }));\n\n if (assetDescriptors.length) {\n // When preloading, we *do* want load failures to reject Promise.all (assets listed in the manifest\n // are known to be hard requirements of the lens).\n return this.cacheAssetsByDescriptor(assetDescriptors, lens, assetManifest);\n }\n }\n\n /**\n * Calls the correct asset loader to fetch the asset's data,\n * depending on the requested asset's type and provides that to LensCore.\n */\n public async loadAsset(\n assetDescriptor: AssetDescriptor,\n lens: Lens | undefined,\n assetManifest: LensAssetManifestItem[] | undefined\n ): Promise<void> {\n const { assetId, assetType } = assetDescriptor;\n const [assetTypeName, assetLoader] = this.assetLoaders.get(assetType) ?? [];\n const safeAssetTypeName = assetTypeName ?? \"unknown\";\n const dimensions: AssetDownloadDimensions = {\n requestType: \"asset\",\n assetId: assetId,\n assetType: safeAssetTypeName,\n lensId: lens?.id ?? \"unknown\",\n };\n\n const { requestId } = dispatchRequestStarted({ dimensions });\n\n try {\n if (!assetLoader) {\n throw new Error(`Cannot get asset \"${assetId}\". Asset type \"${safeAssetTypeName}\" is not supported.`);\n }\n\n const assetResponse = await assetLoader(assetDescriptor, lens, assetManifest);\n const assetBuffer = \"data\" in assetResponse ? assetResponse.data : assetResponse;\n const assetChecksum = \"checksum\" in assetResponse ? assetResponse.checksum : undefined;\n\n if (assetBuffer.byteLength === 0) {\n throw new Error(`Got empty response for asset \"${assetId}\" from \"${safeAssetTypeName}\" loader.`);\n }\n\n dispatchRequestCompleted({ requestId, dimensions, status: 200, sizeByte: assetBuffer.byteLength });\n\n this.lensCore.provideRemoteAssetsResponse({\n assetId,\n assetBuffer,\n assetType,\n assetChecksum,\n onFailure: (reason) => {\n const lensCoreError = ensureError(reason);\n if (/validation failed/.test(lensCoreError.message)) {\n this.metrics.dispatchEvent(\n new TypedCustomEvent(\"assetValidationFailed\", {\n name: \"assetValidationFailed\",\n assetId,\n })\n );\n }\n logger.warn(new Error(`Failed to provide lens asset \"${assetId}\".`, { cause: lensCoreError }));\n },\n });\n } catch (error) {\n const wrappedError = new Error(`Failed to load lens asset \"${assetId}\".`, { cause: error });\n dispatchRequestErrored({ requestId, dimensions, error: wrappedError });\n throw wrappedError;\n }\n }\n\n /**\n * Downloads and caches assets if applicable. Does nothing for assets that are already in cache.\n * @param assetDescriptors Asset ID and type pairs.\n * @param lens Lens to load assets for.\n * @param assetManifest Lens asset manifest.\n */\n private async cacheAssetsByDescriptor(\n assetDescriptors: AssetDescriptor[],\n lens: Lens,\n assetManifest: LensAssetManifestItem[] | undefined\n ): Promise<void> {\n await Promise.all(\n assetDescriptors\n .filter((assetDescriptors) => !this.cachedAssetKeys.has(getCacheKey(assetDescriptors)))\n .map(async (assetDescriptor) => {\n try {\n // NOTE: we allow concurrent cache request to download the same asset more than once,\n // because that is better than skipping second request when the firs one fails.\n // In future we could improve concurretn logic with observables as part of\n // https://jira.sc-corp.net/browse/CAMKIT-3931\n await this.loadAsset(assetDescriptor, lens, assetManifest);\n this.cachedAssetKeys.add(getCacheKey(assetDescriptor));\n } catch (error) {\n const { assetId, assetType } = assetDescriptor;\n const [assetTypeName] = this.assetLoaders.get(assetType) ?? [];\n logger.warn(\n new Error(\n `Failed to cache asset \"${assetId}\" of type \"${assetTypeName ?? assetType.value}\".`,\n { cause: error }\n )\n );\n }\n })\n );\n }\n}\n\n/**\n * @internal\n */\nexport const lensAssetRepositoryFactory = Injectable(\n \"lensAssetRepository\",\n [\n lensCoreFactory.token,\n deviceDependentAssetLoaderFactory.token,\n remoteMediaAssetLoaderFactory.token,\n staticAssetLoaderFactory.token,\n metricsEventTargetFactory.token,\n ] as const,\n (\n lensCore: LensCoreModule,\n deviceDependentAssetLoader: AssetLoader,\n remoteMediaAssetLoader: AssetLoader,\n staticAssetLoader: AssetLoader,\n metrics: MetricsEventTarget\n ) =>\n new LensAssetRepository(\n lensCore,\n new Map([\n [lensCore.AssetType.DeviceDependent, [\"DeviceDependent\", deviceDependentAssetLoader]],\n [lensCore.AssetType.RemoteMediaByUrl, [\"RemoteMediaByUrl\", remoteMediaAssetLoader]],\n // URL type is deprecated and was introduced before RemoteMediaByURL\n // however, there are some lenses still using it so we need to support it\n [lensCore.AssetType.URL, [\"URL\", remoteMediaAssetLoader]],\n [lensCore.AssetType.Static, [\"Static\", staticAssetLoader]],\n ]),\n metrics\n )\n);\n"]}
|
|
1
|
+
{"version":3,"file":"LensAssetRepository.js","sourceRoot":"","sources":["../../../src/lens/assets/LensAssetRepository.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAEnE,OAAO,EAEH,wBAAwB,EACxB,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AQ,EAAE,iBAAiB,CAAC,CAAC;CAC7D,CAAC,EACF,OAAO,EACP,uBAAuB,CAC1B,CACR,CAAC","sourcesContent":["import { ensureError } from \"../../common/errorHelpers\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { Lens } from \"../Lens\";\nimport {\n RequestStateEventTarget,\n dispatchRequestCompleted,\n dispatchRequestErrored,\n dispatchRequestStarted,\n requestStateEventTargetFactory,\n} from \"../../handlers/requestStateEmittingHandler\";\nimport { AssetDownloadDimensions } from \"../../metrics/reporters/reportLensAndAssetDownload\";\nimport {\n LensAssetManifestItem,\n LensAssetManifestItem_RequestTiming,\n LensAssetManifestItem_Type,\n} from \"../../generated-proto/pb_schema/camera_kit/v3/lens\";\nimport { AssetDescriptor, AssetType, lensCoreFactory, LensCoreModule } from \"../../lens-core-module\";\nimport { assertUnreachable } from \"../../common/assertions\";\nimport { getLogger } from \"../../logger/logger\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"../../metrics/metricsEventTarget\";\nimport { TypedCustomEvent } from \"../../events/TypedCustomEvent\";\nimport { deviceDependentAssetLoaderFactory } from \"./deviceDependentAssetLoader\";\nimport { remoteMediaAssetLoaderFactory } from \"./remoteMediaAssetLoaderFactory\";\nimport { staticAssetLoaderFactory } from \"./staticAssetLoader\";\n\nconst logger = getLogger(\"LensAssetRepository\");\n\n/**\n * Computes cache key for asset ID and loader type pair.\n * @param asset Asset ID and loader type pair.\n * @returns Cache key.\n */\nfunction getCacheKey(asset: AssetDescriptor) {\n return `${asset.assetId}_${asset.assetType.value}`;\n}\n\nexport function mapManfiestItemToAssetType(lensCore: LensCoreModule, type: LensAssetManifestItem_Type): AssetType {\n switch (type) {\n case LensAssetManifestItem_Type.ASSET:\n return lensCore.AssetType.Static;\n case LensAssetManifestItem_Type.DEVICE_DEPENDENT_ASSET_UNSET:\n case LensAssetManifestItem_Type.UNRECOGNIZED:\n return lensCore.AssetType.DeviceDependent;\n default:\n return assertUnreachable(type);\n }\n}\n\nexport interface Asset {\n assetId: string;\n assetBuffer: ArrayBuffer;\n assetType: AssetType;\n assetChecksum: string | undefined;\n}\n\nexport type AssetResponse =\n | ArrayBuffer\n | {\n data: ArrayBuffer;\n checksum?: string;\n };\n\n/**\n * An AssetLoader is used to retrieve assets. A separate loader may be defined to retrieve different asset types.\n *\n * @category Lenses\n */\nexport type AssetLoader = (\n asset: AssetDescriptor,\n lens?: Lens,\n assetManifest?: LensAssetManifestItem[]\n) => Promise<AssetResponse> | AssetResponse;\n\n/**\n * Registers a remote asset provider function with a given instance of LensCore, and uses a provided mapping of asset\n * types to loading functions to acquire remote asset data and pass it to LensCore.\n *\n * *Note:* LensCoreModule.initialize must be called on the desired LensCoreModule instance **prior** to passing it\n * to the LensAssetProvider constructor. If this class is instantiated with a LensCoreModule that has not been\n * initialized, the registry of the asset provider function will fail silently and no remote assets will be loaded.\n */\nexport class LensAssetRepository {\n private readonly cachedAssetKeys = new Set<string>();\n\n constructor(\n private readonly lensCore: LensCoreModule,\n private readonly assetLoaders: Map<AssetType, [keyof LensCoreModule[\"AssetType\"], AssetLoader]>,\n private readonly metrics: MetricsEventTarget,\n private readonly requestStateEventTarget: RequestStateEventTarget\n ) {}\n\n /**\n * Caches lens assets defined in asset manifest.\n *\n * @param assetManifest Lens asset manifest.\n * @param lens Lens to cache assets of.\n * @param assetTimings Optionally specifies what assets to cache. By default, on-demand assets are not cached.\n * @returns Promise rejects if any required assets could not be loaded – if this occurs, it's very likely the Lens\n * with this manifest will not function.\n */\n public async cacheAssets(\n assetManifest: LensAssetManifestItem[],\n lens: Lens,\n assetTimings: LensAssetManifestItem_RequestTiming[] = [LensAssetManifestItem_RequestTiming.REQUIRED]\n ): Promise<void> {\n const assetTimingsToPreload = new Set([\n // That is a bad naming, but PRELOAD_UNSET actually means\n // that an asset has to be preloaded\n LensAssetManifestItem_RequestTiming.PRELOAD_UNSET,\n ...assetTimings,\n ]);\n const assetDescriptors = assetManifest\n .filter((asset) => {\n return assetTimingsToPreload.has(asset.requestTiming);\n })\n .map(({ id, type }) => ({\n assetId: id,\n assetType: mapManfiestItemToAssetType(this.lensCore, type),\n }));\n\n if (assetDescriptors.length) {\n // When preloading, we *do* want load failures to reject Promise.all (assets listed in the manifest\n // are known to be hard requirements of the lens).\n return this.cacheAssetsByDescriptor(assetDescriptors, lens, assetManifest);\n }\n }\n\n /**\n * Calls the correct asset loader to fetch the asset's data,\n * depending on the requested asset's type and provides that to LensCore.\n */\n public async loadAsset(\n assetDescriptor: AssetDescriptor,\n lens: Lens | undefined,\n assetManifest: LensAssetManifestItem[] | undefined\n ): Promise<void> {\n const { assetId, assetType } = assetDescriptor;\n const [assetTypeName, assetLoader] = this.assetLoaders.get(assetType) ?? [];\n const safeAssetTypeName = assetTypeName ?? \"unknown\";\n const dimensions: AssetDownloadDimensions = {\n requestType: \"asset\",\n assetId: assetId,\n assetType: safeAssetTypeName,\n lensId: lens?.id ?? \"unknown\",\n };\n\n const { requestId } = dispatchRequestStarted(this.requestStateEventTarget, { dimensions });\n\n try {\n if (!assetLoader) {\n throw new Error(`Cannot get asset ${assetId}. Asset type ${safeAssetTypeName} is not supported.`);\n }\n\n const assetResponse = await assetLoader(assetDescriptor, lens, assetManifest);\n const assetBuffer = \"data\" in assetResponse ? assetResponse.data : assetResponse;\n const assetChecksum = \"checksum\" in assetResponse ? assetResponse.checksum : undefined;\n\n if (assetBuffer.byteLength === 0) {\n throw new Error(`Got empty response for asset ${assetId} from ${safeAssetTypeName} loader.`);\n }\n\n dispatchRequestCompleted(this.requestStateEventTarget, {\n requestId,\n dimensions,\n status: 200,\n sizeByte: assetBuffer.byteLength,\n });\n\n this.lensCore.provideRemoteAssetsResponse({\n assetId,\n assetBuffer,\n assetType,\n assetChecksum,\n onFailure: (reason) => {\n const lensCoreError = ensureError(reason);\n if (/validation failed/.test(lensCoreError.message)) {\n this.metrics.dispatchEvent(\n new TypedCustomEvent(\"assetValidationFailed\", {\n name: \"assetValidationFailed\",\n assetId,\n })\n );\n }\n logger.warn(new Error(`Failed to provide lens asset ${assetId}.`, { cause: lensCoreError }));\n },\n });\n } catch (error) {\n const wrappedError = new Error(`Failed to load lens asset ${assetId}.`, { cause: error });\n dispatchRequestErrored(this.requestStateEventTarget, { requestId, dimensions, error: wrappedError });\n throw wrappedError;\n }\n }\n\n /**\n * Downloads and caches assets if applicable. Does nothing for assets that are already in cache.\n * @param assetDescriptors Asset ID and type pairs.\n * @param lens Lens to load assets for.\n * @param assetManifest Lens asset manifest.\n */\n private async cacheAssetsByDescriptor(\n assetDescriptors: AssetDescriptor[],\n lens: Lens,\n assetManifest: LensAssetManifestItem[] | undefined\n ): Promise<void> {\n await Promise.all(\n assetDescriptors\n .filter((assetDescriptors) => !this.cachedAssetKeys.has(getCacheKey(assetDescriptors)))\n .map(async (assetDescriptor) => {\n try {\n // NOTE: we allow concurrent cache request to download the same asset more than once,\n // because that is better than skipping second request when the firs one fails.\n // In future we could improve concurretn logic with observables as part of\n // https://jira.sc-corp.net/browse/CAMKIT-3931\n await this.loadAsset(assetDescriptor, lens, assetManifest);\n this.cachedAssetKeys.add(getCacheKey(assetDescriptor));\n } catch (error) {\n const { assetId, assetType } = assetDescriptor;\n const [assetTypeName] = this.assetLoaders.get(assetType) ?? [];\n logger.warn(\n new Error(`Failed to cache asset ${assetId} of type ${assetTypeName ?? assetType.value}.`, {\n cause: error,\n })\n );\n }\n })\n );\n }\n}\n\n/**\n * @internal\n */\nexport const lensAssetRepositoryFactory = Injectable(\n \"lensAssetRepository\",\n [\n lensCoreFactory.token,\n deviceDependentAssetLoaderFactory.token,\n remoteMediaAssetLoaderFactory.token,\n staticAssetLoaderFactory.token,\n metricsEventTargetFactory.token,\n requestStateEventTargetFactory.token,\n ] as const,\n (\n lensCore: LensCoreModule,\n deviceDependentAssetLoader: AssetLoader,\n remoteMediaAssetLoader: AssetLoader,\n staticAssetLoader: AssetLoader,\n metrics: MetricsEventTarget,\n requestStateEventTarget: RequestStateEventTarget\n ) =>\n new LensAssetRepository(\n lensCore,\n new Map([\n [lensCore.AssetType.DeviceDependent, [\"DeviceDependent\", deviceDependentAssetLoader]],\n [lensCore.AssetType.RemoteMediaByUrl, [\"RemoteMediaByUrl\", remoteMediaAssetLoader]],\n // URL type is deprecated and was introduced before RemoteMediaByURL\n // however, there are some lenses still using it so we need to support it\n [lensCore.AssetType.URL, [\"URL\", remoteMediaAssetLoader]],\n [lensCore.AssetType.Static, [\"Static\", staticAssetLoader]],\n ]),\n metrics,\n requestStateEventTarget\n )\n);\n"]}
|
|
@@ -34,7 +34,7 @@ export const registerLensAssetsProvider = Injectable("registerLensAssetsProvider
|
|
|
34
34
|
assetId,
|
|
35
35
|
assetType,
|
|
36
36
|
});
|
|
37
|
-
logger.error(lensAssetError(`
|
|
37
|
+
logger.error(lensAssetError(`Error occurred while handling lens asset ${assetId} request.`, error));
|
|
38
38
|
}
|
|
39
39
|
}));
|
|
40
40
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensAssetsProvider.js","sourceRoot":"","sources":["../../../src/lens/assets/LensAssetsProvider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAkB,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAkB,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAuB,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAExF,MAAM,MAAM,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAC;AAO9C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAChD,4BAA4B,EAC5B,CAAC,eAAe,CAAC,KAAK,EAAE,qBAAqB,CAAC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F,MAAM,MAAM,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAC;AAO9C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAChD,4BAA4B,EAC5B,CAAC,eAAe,CAAC,KAAK,EAAE,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,CAAC,KAAK,CAAU,EAC/F,CAAC,QAAwB,EAAE,cAA8B,EAAE,mBAAwC,EAAE,EAAE;IACnG,QAAQ,CAAC,uBAAuB,CAAC,CAAO,eAAe,EAAE,EAAE;;QACvD,0FAA0F;QAC1F,sFAAsF;QACtF,uDAAuD;QACvD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;QACzD,IAAI;YACA,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC7E,MAAM,mBAAmB,CAAC,SAAS,CAC/B,eAAe,EACf,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,EAC1B,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,0CAAE,aAAa,CAC/B,CAAC;SACL;QAAC,OAAO,KAAK,EAAE;YACZ,gEAAgE;YAChE,yFAAyF;YACzF,kGAAkG;YAClG,QAAQ,CAAC,2BAA2B,CAAC;gBACjC,OAAO;gBACP,SAAS;aACZ,CAAC,CAAC;YACH,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,4CAA4C,OAAO,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;SACvG;IACL,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { Injectable } from \"../../dependency-injection/Injectable\";\nimport { lensAssetError } from \"../../namedErrors\";\nimport { lensCoreFactory, LensCoreModule } from \"../../lens-core-module\";\nimport { getLogger } from \"../../logger/logger\";\nimport { MakeTaggedBusinessEvent } from \"../../metrics/businessEventsReporter\";\nimport { toPublicLens } from \"../Lens\";\nimport { LensRepository, lensRepositoryFactory } from \"../LensRepository\";\nimport { LensAssetRepository, lensAssetRepositoryFactory } from \"./LensAssetRepository\";\n\nconst logger = getLogger(\"LensAssetProvider\");\n\n/**\n * The AssetValidationFailed metric reports every time we handle an asset checksum validation failure.\n */\nexport type AssetValidationFailed = MakeTaggedBusinessEvent<\"assetValidationFailed\">;\n\n/**\n * Registers a remote asset provider function with a given instance of LensCore.\n *\n * *Note:* LensCoreModule.initialize must be called on the desired LensCoreModule instance **prior** to passing it\n * to the LensAssetsProvider constructor. If this class is instantiated with a LensCoreModule that has not been\n * initialized, the registry of the asset provider function will fail silently and no remote assets will be loaded.\n * @internal\n */\nexport const registerLensAssetsProvider = Injectable(\n \"registerLensAssetsProvider\",\n [lensCoreFactory.token, lensRepositoryFactory.token, lensAssetRepositoryFactory.token] as const,\n (lensCore: LensCoreModule, lensRepository: LensRepository, lensAssetRepository: LensAssetRepository) => {\n lensCore.setRemoteAssetsProvider(async (assetDescriptor) => {\n // Fetch an asset and provide it to LensCore. If fetching the asset fails we give LensCore\n // an empty response (which it may handle in a variety of ways, e.g. retry, gracefully\n // degrade lens behavior, throw error) and then reject.\n const { assetId, assetType, effectId } = assetDescriptor;\n try {\n const lens = effectId ? lensRepository.getLensMetadata(effectId) : undefined;\n await lensAssetRepository.loadAsset(\n assetDescriptor,\n lens && toPublicLens(lens),\n lens?.content?.assetManifest\n );\n } catch (error) {\n // if an error occurs, LensCore handles things in different ways\n // depending on the active lens. It might: 1) retry, 2) gracefully degrade lens behavior,\n // 3) lens JS might throw, which will be passed to the exceptionHandler we register with LensCore.\n lensCore.provideRemoteAssetsResponse({\n assetId,\n assetType,\n });\n logger.error(lensAssetError(`Error occurred while handling lens asset ${assetId} request.`, error));\n }\n });\n }\n);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lensEnvelopeUtil.js","sourceRoot":"","sources":["../../src/lens/lensEnvelopeUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAG7E;;GAEG;AACH,SAAS,cAAc,CAAC,QAAqB;IACzC,IAAI;QACA,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;KAC3D;IAAC,WAAM;QACJ,MAAM,IAAI,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"lensEnvelopeUtil.js","sourceRoot":"","sources":["../../src/lens/lensEnvelopeUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAG7E;;GAEG;AACH,SAAS,cAAc,CAAC,QAAqB;IACzC,IAAI;QACA,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;KAC3D;IAAC,WAAM;QACJ,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;KAC7C;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,SAAwB;IACpD,OAAO,SAAS,CAAC,MAAM,CAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7G,CAAC","sourcesContent":["import { Envelope } from \"../generated-proto/pb_schema/camera_kit/v3/export\";\nimport { LensProto } from \"./Lens\";\n\n/**\n * @internal\n */\nfunction decodeEnvelope(envelope: ArrayBuffer) {\n try {\n return Envelope.decode(new Uint8Array(envelope)).lenses;\n } catch {\n throw new Error(\"Invalid lens envelope.\");\n }\n}\n\n/**\n * @internal\n */\nexport function decodeEnvelopes(envelopes: ArrayBuffer[]) {\n return envelopes.reduce<LensProto[]>((lenses, envelope) => [...lenses, ...decodeEnvelope(envelope)], []);\n}\n"]}
|
|
@@ -57,7 +57,7 @@ function getMimeType({ ImageEnabled, VideoEnabled }) {
|
|
|
57
57
|
if (VideoEnabled === "1")
|
|
58
58
|
types.push(...enumerateSupportedVideoTypes(mimeTypes.video));
|
|
59
59
|
if (types.length === 0) {
|
|
60
|
-
throw new Error("Unknown media type requested");
|
|
60
|
+
throw new Error("Unknown media type requested.");
|
|
61
61
|
}
|
|
62
62
|
return types;
|
|
63
63
|
}
|
|
@@ -77,7 +77,7 @@ function getOrientation(data, lensCore) {
|
|
|
77
77
|
return orientationMap[(_a = extractJpegOrientationTag(data)) !== null && _a !== void 0 ? _a : 1 /* Orientation.TopLeft */];
|
|
78
78
|
}
|
|
79
79
|
catch (error) {
|
|
80
|
-
logger.info("Error occured while reading EXIF orientation tag", error);
|
|
80
|
+
logger.info("Error occured while reading EXIF orientation tag.", error);
|
|
81
81
|
return lensCore.ExternalMediaOrientation.CW0;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imagePicker.js","sourceRoot":"","sources":["../../src/lens-client-interface/imagePicker.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAe,MAAM,QAAQ,CAAC;AAEhE,MAAM,MAAM,GAAG,SAAS,CAAC,gCAAgC,CAAC,CAAC;AAE3D,sDAAsD;AACtD,2FAA2F;AAC3F,MAAM,SAAS,GAAG;IACd,KAAK,EAAE;QACH,YAAY;QACZ,WAAW;QACX,WAAW;QACX,YAAY;QACZ,WAAW;QACX,eAAe;QACf,YAAY;QACZ,YAAY;KACf;IACD,KAAK,EAAE;QACH,YAAY;QACZ,aAAa;QACb,YAAY;QACZ,WAAW;QACX,YAAY;QACZ,WAAW;QACX,iBAAiB;QACjB,YAAY;QACZ,iBAAiB;KACpB;CACK,CAAC;AAEX,QAAQ,CA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Z;qBACJ;iBACJ;aACJ,CAAC,CAAC;SACN;aAAM;YACH,QAAQ,CAAC,oBAAoB,CAAC;gBAC1B,IAAI;gBACJ,WAAW,EAAE,QAAQ,CAAC,wBAAwB,CAAC,GAAG;aACrD,CAAC,CAAC;SACN;IACL,CAAC;CAAA","sourcesContent":["import { fileOpen, FileWithHandle } from \"browser-fs-access\";\nimport { ClientInterfaceData, LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { getLogger } from \"../logger/logger\";\nimport { extractJpegOrientationTag, Orientation } from \"./exif\";\n\nconst logger = getLogger(\"lensClientInterfaceImagePicker\");\n\n// Common MIME types supported by all browsers as per:\n// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\nconst mimeTypes = {\n image: [\n \"image/avif\",\n \"image/bmp\",\n \"image/gif\",\n \"image/jpeg\",\n \"image/png\",\n \"image/svg+xml\",\n \"image/tiff\",\n \"image/webp\",\n ],\n video: [\n \"video/3gpp\",\n \"video/3gpp2\",\n \"video/mp2t\",\n \"video/mp4\",\n \"video/mpeg\",\n \"video/ogg\",\n \"video/quicktime\",\n \"video/webm\",\n \"video/x-msvideo\",\n ],\n} as const;\n\nfunction* enumerateSupportedVideoTypes(types: typeof mimeTypes.video) {\n // test video element to perform MIME types support check\n const testVideoElement = typeof document !== \"undefined\" ? document.createElement(\"video\") : undefined;\n for (const type of types) {\n if (testVideoElement?.canPlayType(type) || false) {\n yield type;\n }\n }\n}\n\nfunction readFileAsArrayBuffer(file: FileWithHandle): Promise<ArrayBuffer> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.addEventListener(\"load\", (event) => {\n // Safety: target.result is always an ArrayBuffer because we read file using readAsArrayBuffer()\n resolve(event.target!.result as ArrayBuffer);\n });\n reader.addEventListener(\"error\", (event) => {\n reject(event.target!.error);\n });\n reader.readAsArrayBuffer(file);\n });\n}\n\nfunction getMimeType({ ImageEnabled, VideoEnabled }: ClientInterfaceData) {\n const types = [];\n if (ImageEnabled === \"1\") types.push(...mimeTypes.image);\n if (VideoEnabled === \"1\") types.push(...enumerateSupportedVideoTypes(mimeTypes.video));\n if (types.length === 0) {\n throw new Error(\"Unknown media type requested.\");\n }\n return types;\n}\n\nfunction getOrientation(data: ArrayBuffer, lensCore: LensCoreModule) {\n const orientationMap = {\n [Orientation.TopLeft]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.TopRight]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.BottomRight]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.BottomLeft]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.LeftTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightBottom]: lensCore.ExternalMediaOrientation.CW270,\n [Orientation.LeftBottom]: lensCore.ExternalMediaOrientation.CW270,\n };\n try {\n return orientationMap[extractJpegOrientationTag(data) ?? Orientation.TopLeft];\n } catch (error) {\n logger.info(\"Error occured while reading EXIF orientation tag.\", error);\n return lensCore.ExternalMediaOrientation.CW0;\n }\n}\n\n/**\n * Shows file open dialog to allow user to select image/video and provides the selection to LensCore.\n *\n * @internal\n */\nexport async function pickClientImage(clientInterfaceData: ClientInterfaceData, lensCore: LensCoreModule) {\n const mimeTypes = getMimeType(clientInterfaceData);\n logger.debug(`Opening file dialog for MIME types: ${mimeTypes}`);\n\n const file = await fileOpen({ mimeTypes });\n logger.debug(`Selected file MIME type: ${file.type}`);\n\n const data = await readFileAsArrayBuffer(file);\n if (file.type.startsWith(\"image/\")) {\n lensCore.provideExternalImage({\n data,\n orientation: getOrientation(data, lensCore),\n // As per Corvyn: both iOS and Android clients have the ability to pick out individual faces\n // from an image to apply the effect on, using each of their native face detectors (not using LensCore).\n // That's what the faceRects is for. For now, we can just apply the effect to the whole image (so face rect\n // [[0,0][1,1]]). In future, in order to be able to pick out individual faces in the media picker, we could:\n // - hook up some external web face tracking library\n // - make LensCore to expose face tracker to external clients\n faceRects: [\n {\n origin: {\n x: 0,\n y: 0,\n },\n size: {\n width: 1,\n height: 1,\n },\n },\n ],\n });\n } else {\n lensCore.provideExternalVideo({\n data,\n orientation: lensCore.ExternalMediaOrientation.CW0,\n });\n }\n}\n"]}
|
|
@@ -22,7 +22,7 @@ export const registerLensClientInterfaceHandler = Injectable("registerLensClient
|
|
|
22
22
|
if (interfaceControl === lensCore.InterfaceControl.ImagePicker &&
|
|
23
23
|
interfaceAction === lensCore.InterfaceAction.Show) {
|
|
24
24
|
yield pickClientImage(data, lensCore).catch((error) => {
|
|
25
|
-
logger.error(lensImagePickerError("
|
|
25
|
+
logger.error(lensImagePickerError("Error occurred while attempting to select an image file for the lens request.", error));
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lensClientInterface.js","sourceRoot":"","sources":["../../src/lens-client-interface/lensClientInterface.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,UAAU,CACxD,oCAAoC,EACpC,CAAC,eAAe,CAAC,KAAK,CAAU,EAChC,CAAC,QAAwB,EAAE,EAAE;IACzB,8DAA8D;IAC9D,IAAI,CAAC,QAAQ,CAAC,gCAAgC,EAAE;QAC5C,MAAM,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;QACvF,OAAO;KACV;IAED,QAAQ,CAAC,gCAAgC,CAAC,CAAO,EA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C,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBAClD,MAAM,CAAC,KAAK,CACR,oBAAoB,CAChB,+EAA+E,EAC/E,KAAK,CACR,CACJ,CAAC;YACN,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { lensImagePickerError } from \"../namedErrors\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { lensCoreFactory } from \"../lens-core-module\";\nimport { LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { getLogger } from \"../logger/logger\";\nimport { pickClientImage } from \"./imagePicker\";\n\nconst logger = getLogger(\"lensClientInterface\");\n\n/**\n * Registers client interface handler in LensCore.\n *\n * @internal\n * @param lensCore LensCore instance to register in.\n * @param sessionErrors EventTarget to dispatch errors in.\n */\nexport const registerLensClientInterfaceHandler = Injectable(\n \"registerLensClientInterfaceHandler\",\n [lensCoreFactory.token] as const,\n (lensCore: LensCoreModule) => {\n // Make sure we are compatible with previous LensCore versions\n if (!lensCore.setClientInterfaceRequestHandler) {\n logger.warn(\"Current LensCore version doesn't support lens client interface requests\");\n return;\n }\n\n lensCore.setClientInterfaceRequestHandler(async ({ data, interfaceControl, interfaceAction }) => {\n if (\n interfaceControl === lensCore.InterfaceControl.ImagePicker &&\n interfaceAction === lensCore.InterfaceAction.Show\n ) {\n await pickClientImage(data, lensCore).catch((error) => {\n logger.error(\n lensImagePickerError(\n \"Error occurred while attempting to select an image file for the lens request.\",\n error\n )\n );\n });\n }\n });\n }\n);\n"]}
|
|
@@ -81,7 +81,7 @@ export const lensCoreFactory = Injectable("lensCore", [defaultFetchHandlerFactor
|
|
|
81
81
|
lensCoreWASM = (_b = findMatch(/\.wasm/, assetURLs)) !== null && _b !== void 0 ? _b : "";
|
|
82
82
|
if (!lensCoreJS || !lensCoreWASM) {
|
|
83
83
|
throw new Error(`Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +
|
|
84
|
-
`this list: ${assetURLs}
|
|
84
|
+
`this list: ${assetURLs}.`);
|
|
85
85
|
}
|
|
86
86
|
// Fetching here and creating an Object URL lets LensCore optimized loading itself in a WebWorker,
|
|
87
87
|
// otherwise the glue script would need to be downloaded again.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lensCoreFactory.js","sourceRoot":"","sources":["../../../src/lens-core-module/loader/lensCoreFactory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,YAAY,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAA0B,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAgB,MAAM,oCAAoC,CAAC;AAE9F,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,MAAM,MAAM,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAE5C,MAAM,UAAU,GAAG,CAAC,wBAAwB,EAAE,0BAA0B,CAAC,CAAC;AAE1E,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,OAAiB,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3F,MAAM,gBAAgB,GAAG;IACrB,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,IAAI;IACV,UAAU,EAAE,IAAI;CACnB,CAAC;AAEF,MAAM,yBAAyB,GAAG;IAC9B,CAAC,gBAAgB,CAAC,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,EAAE,cAAc;IACrE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,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C;QACnE,UAAU,GAAG,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;KAChD;IAED,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC;IAE7B,MAAM,QAAQ,GAAG,MAAM,IAAI,OAAO,CAA2C,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7F,IAAI,aAA+C,CAAC;QACpD,qDAAqD;QACrD,mEAAmE;QACnE,wCAAwC;QACxC,mCAAmC;QACnC,mKAAmK;QACnK,MAAM,UAAU,GAAG,UAAU,CAAC,kBAAkB,CAC5C,CAAC,aAAa,GAAG;YACb,kEAAkE;YAClE,mBAAmB,EAAE,UAAU;YAC/B,4DAA4D;YAC5D,eAAe,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,EAAE;gBAC/C,WAAW,CAAC,oBAAoB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;qBAChE,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE;oBAChC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;oBAClC,2CAA2C;oBAC3C,aAAa,CAAC,cAAc,GAAG,MAAM,CAAC;oBACtC,OAAO,CAAC,UAAU,CAAC,CAAC;gBACxB,CAAC,CAAC;qBACD,KAAK,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;SACJ,CAAC,CACL,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,6DAA6D;IAC7D,IAAI,YAAY,CAAC,OAAO,IAAI,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,EAAE;QACxD,MAAM,CAAC,IAAI,CACP,4BAA4B,QAAQ,CAAC,cAAc,EAAE,gCACjD,YAAY,CAAC,OACjB,GAAG,CACN,CAAC;KACL;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAA,CACJ,CAAC","sourcesContent":["import { simd, exceptions } from \"wasm-feature-detect\";\nimport lensCoreWasm from \"../../lensCoreWasmVersions.json\";\nimport { loadScript } from \"../../common\";\nimport { CameraKitConfiguration, configurationToken } from \"../../configuration\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { InitialEmscriptenModule, LensCoreModule } from \"../generated-types\";\nimport { getLogger } from \"../../logger/logger\";\nimport { cameraKitUserAgent } from \"../../common/cameraKitUserAgent\";\n\nconst logger = getLogger(\"lensCoreFactory\");\n\nconst wasmAssets = [\"LensCoreWebAssembly.js\", \"LensCoreWebAssembly.wasm\"];\n\nconst findMatch = (regex: RegExp, strings: string[]) => strings.find((s) => regex.test(s));\n\nconst PlatformFeatures = {\n Default: 0,\n Simd: 0b01,\n Exceptions: 0b10,\n};\n\nconst platformFeaturesToFlavour = {\n [PlatformFeatures.Exceptions | PlatformFeatures.Simd]: \"rel-simd-neh\",\n [PlatformFeatures.Simd]: \"release-simd\",\n [PlatformFeatures.Exceptions]: \"rel-neh\",\n [PlatformFeatures.Default]: \"release\",\n};\n\n/**\n * Returns a list of URLs for resources which will be fetched during {@link bootstrapCameraKit}.\n *\n * When CameraKit is used on a website, these URLs much be reachable in order for CameraKit to be successfully\n * bootstrapped.\n *\n * @param endpointOverride Optional endpoint override to load the assets from.\n * @returns An array of asset URLs.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function getRequiredBootstrapURLs(endpointOverride?: string): Promise<string[]> {\n // If we have an endpoint override, remove trailing `/` so we can construct a valid URL.\n const endpoint = endpointOverride?.replace(/[\\/]+$/, \"\");\n\n let [simdFeature, exceptionsFeature] = await Promise.all([\n simd().then((supported) => (supported ? PlatformFeatures.Simd : PlatformFeatures.Default)),\n exceptions().then((supported) => (supported ? PlatformFeatures.Exceptions : PlatformFeatures.Default)),\n ]);\n\n // Although Safari 16.4 reports SIMD support, LensCore encounters rendering bugs when using SIMD in Safari 16.4.\n // Therefore, we have made the decision to disable SIMD for now until Safari stabilizes the feature.\n const { brand } = cameraKitUserAgent.browser;\n if (brand === \"Safari\") simdFeature = PlatformFeatures.Default;\n\n const flavor = platformFeaturesToFlavour[simdFeature | exceptionsFeature];\n\n const version = lensCoreWasm.version;\n const buildNumber = lensCoreWasm.buildNumber;\n return wasmAssets.map((asset) => {\n if (endpoint) return `${endpoint}/${asset}`;\n const { origin, pathname, search } = new URL(lensCoreWasm.baseUrl);\n return `${origin}${pathname}/${version}/${buildNumber}/${flavor}/${asset}${search}`;\n });\n}\n\n/**\n * This component is responsible for:\n * 1) Loading LensCore WebAssembly (WASM) assets\n * 2) Using the WASM assets to initialize the LensCore WASM module\n *\n * By default, WASM assets will be loaded from the Bolt CDN – but if `endpoint` is provided, assets will be loaded\n * using it as a base URL.\n *\n * @internal\n */\nexport const lensCoreFactory = Injectable(\n \"lensCore\",\n [defaultFetchHandlerFactory.token, configurationToken] as const,\n async (handler: FetchHandler, { lensCoreOverrideUrls, wasmEndpointOverride }: CameraKitConfiguration) => {\n let lensCoreJS: string;\n let lensCoreWASM: string;\n\n if (lensCoreOverrideUrls) {\n lensCoreJS = lensCoreOverrideUrls.js;\n lensCoreWASM = lensCoreOverrideUrls.wasm;\n } else {\n const endpointOverride = wasmEndpointOverride ?? undefined;\n const assetURLs = await getRequiredBootstrapURLs(endpointOverride);\n\n lensCoreJS = findMatch(/\\.js/, assetURLs) ?? \"\";\n lensCoreWASM = findMatch(/\\.wasm/, assetURLs) ?? \"\";\n\n if (!lensCoreJS || !lensCoreWASM) {\n throw new Error(\n `Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +\n `this list: ${assetURLs}`\n );\n }\n\n // Fetching here and creating an Object URL lets LensCore optimized loading itself in a WebWorker,\n // otherwise the glue script would need to be downloaded again.\n const glueScript = await handler(lensCoreJS).then((r) => r.blob());\n lensCoreJS = URL.createObjectURL(glueScript);\n }\n\n await loadScript(lensCoreJS);\n\n const lensCore = await new Promise<InitialEmscriptenModule & LensCoreModule>((resolve, reject) => {\n let initialModule: Partial<InitialEmscriptenModule>;\n // will trigger WASM initialization and data loading,\n // after completion it will be safe to call imported WASM functions\n // More about emscripten initialization:\n // eslint-disable-next-line max-len\n // https://emscripten.org/docs/getting_started/FAQ.html?highlight=modularize#how-can-i-tell-when-the-page-is-fully-loaded-and-it-is-safe-to-call-compiled-functions\n const moduleInit = globalThis.createLensesModule(\n (initialModule = {\n // url will be used for loading glue JS during Worker inialization\n mainScriptUrlOrBlob: lensCoreJS,\n // will be triggered by Emscripten during the initialization\n instantiateWasm: (importObject, receiveInstance) => {\n WebAssembly.instantiateStreaming(handler(lensCoreWASM), importObject)\n .then(function ({ instance, module }) {\n receiveInstance(instance, module);\n // compiled module will be reused in Worker\n initialModule.compiledModule = module;\n resolve(moduleInit);\n })\n .catch(reject);\n },\n })\n );\n });\n\n // print warning if loaded version differs from hardcoded one\n if (lensCoreWasm.version != `${lensCore.getCoreVersion()}`) {\n logger.warn(\n `Loaded LensCore version (${lensCore.getCoreVersion()}) differs from expected one (${\n lensCoreWasm.version\n })`\n );\n }\n\n return lensCore;\n }\n);\n"]}
|
|
1
|
+
{"version":3,"file":"lensCoreFactory.js","sourceRoot":"","sources":["../../../src/lens-core-module/loader/lensCoreFactory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,YAAY,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAA0B,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAgB,MAAM,oCAAoC,CAAC;AAE9F,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,MAAM,MAAM,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAE5C,MAAM,UAAU,GAAG,CAAC,wBAAwB,EAAE,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,KAAK,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;SACJ,CAAC,CACL,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,6DAA6D;IAC7D,IAAI,YAAY,CAAC,OAAO,IAAI,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,EAAE;QACxD,MAAM,CAAC,IAAI,CACP,4BAA4B,QAAQ,CAAC,cAAc,EAAE,gCACjD,YAAY,CAAC,OACjB,GAAG,CACN,CAAC;KACL;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAA,CACJ,CAAC","sourcesContent":["import { simd, exceptions } from \"wasm-feature-detect\";\nimport lensCoreWasm from \"../../lensCoreWasmVersions.json\";\nimport { loadScript } from \"../../common\";\nimport { CameraKitConfiguration, configurationToken } from \"../../configuration\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { InitialEmscriptenModule, LensCoreModule } from \"../generated-types\";\nimport { getLogger } from \"../../logger/logger\";\nimport { cameraKitUserAgent } from \"../../common/cameraKitUserAgent\";\n\nconst logger = getLogger(\"lensCoreFactory\");\n\nconst wasmAssets = [\"LensCoreWebAssembly.js\", \"LensCoreWebAssembly.wasm\"];\n\nconst findMatch = (regex: RegExp, strings: string[]) => strings.find((s) => regex.test(s));\n\nconst PlatformFeatures = {\n Default: 0,\n Simd: 0b01,\n Exceptions: 0b10,\n};\n\nconst platformFeaturesToFlavour = {\n [PlatformFeatures.Exceptions | PlatformFeatures.Simd]: \"rel-simd-neh\",\n [PlatformFeatures.Simd]: \"release-simd\",\n [PlatformFeatures.Exceptions]: \"rel-neh\",\n [PlatformFeatures.Default]: \"release\",\n};\n\n/**\n * Returns a list of URLs for resources which will be fetched during {@link bootstrapCameraKit}.\n *\n * When CameraKit is used on a website, these URLs much be reachable in order for CameraKit to be successfully\n * bootstrapped.\n *\n * @param endpointOverride Optional endpoint override to load the assets from.\n * @returns An array of asset URLs.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function getRequiredBootstrapURLs(endpointOverride?: string): Promise<string[]> {\n // If we have an endpoint override, remove trailing `/` so we can construct a valid URL.\n const endpoint = endpointOverride?.replace(/[\\/]+$/, \"\");\n\n let [simdFeature, exceptionsFeature] = await Promise.all([\n simd().then((supported) => (supported ? PlatformFeatures.Simd : PlatformFeatures.Default)),\n exceptions().then((supported) => (supported ? PlatformFeatures.Exceptions : PlatformFeatures.Default)),\n ]);\n\n // Although Safari 16.4 reports SIMD support, LensCore encounters rendering bugs when using SIMD in Safari 16.4.\n // Therefore, we have made the decision to disable SIMD for now until Safari stabilizes the feature.\n const { brand } = cameraKitUserAgent.browser;\n if (brand === \"Safari\") simdFeature = PlatformFeatures.Default;\n\n const flavor = platformFeaturesToFlavour[simdFeature | exceptionsFeature];\n\n const version = lensCoreWasm.version;\n const buildNumber = lensCoreWasm.buildNumber;\n return wasmAssets.map((asset) => {\n if (endpoint) return `${endpoint}/${asset}`;\n const { origin, pathname, search } = new URL(lensCoreWasm.baseUrl);\n return `${origin}${pathname}/${version}/${buildNumber}/${flavor}/${asset}${search}`;\n });\n}\n\n/**\n * This component is responsible for:\n * 1) Loading LensCore WebAssembly (WASM) assets\n * 2) Using the WASM assets to initialize the LensCore WASM module\n *\n * By default, WASM assets will be loaded from the Bolt CDN – but if `endpoint` is provided, assets will be loaded\n * using it as a base URL.\n *\n * @internal\n */\nexport const lensCoreFactory = Injectable(\n \"lensCore\",\n [defaultFetchHandlerFactory.token, configurationToken] as const,\n async (handler: FetchHandler, { lensCoreOverrideUrls, wasmEndpointOverride }: CameraKitConfiguration) => {\n let lensCoreJS: string;\n let lensCoreWASM: string;\n\n if (lensCoreOverrideUrls) {\n lensCoreJS = lensCoreOverrideUrls.js;\n lensCoreWASM = lensCoreOverrideUrls.wasm;\n } else {\n const endpointOverride = wasmEndpointOverride ?? undefined;\n const assetURLs = await getRequiredBootstrapURLs(endpointOverride);\n\n lensCoreJS = findMatch(/\\.js/, assetURLs) ?? \"\";\n lensCoreWASM = findMatch(/\\.wasm/, assetURLs) ?? \"\";\n\n if (!lensCoreJS || !lensCoreWASM) {\n throw new Error(\n `Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +\n `this list: ${assetURLs}.`\n );\n }\n\n // Fetching here and creating an Object URL lets LensCore optimized loading itself in a WebWorker,\n // otherwise the glue script would need to be downloaded again.\n const glueScript = await handler(lensCoreJS).then((r) => r.blob());\n lensCoreJS = URL.createObjectURL(glueScript);\n }\n\n await loadScript(lensCoreJS);\n\n const lensCore = await new Promise<InitialEmscriptenModule & LensCoreModule>((resolve, reject) => {\n let initialModule: Partial<InitialEmscriptenModule>;\n // will trigger WASM initialization and data loading,\n // after completion it will be safe to call imported WASM functions\n // More about emscripten initialization:\n // eslint-disable-next-line max-len\n // https://emscripten.org/docs/getting_started/FAQ.html?highlight=modularize#how-can-i-tell-when-the-page-is-fully-loaded-and-it-is-safe-to-call-compiled-functions\n const moduleInit = globalThis.createLensesModule(\n (initialModule = {\n // url will be used for loading glue JS during Worker inialization\n mainScriptUrlOrBlob: lensCoreJS,\n // will be triggered by Emscripten during the initialization\n instantiateWasm: (importObject, receiveInstance) => {\n WebAssembly.instantiateStreaming(handler(lensCoreWASM), importObject)\n .then(function ({ instance, module }) {\n receiveInstance(instance, module);\n // compiled module will be reused in Worker\n initialModule.compiledModule = module;\n resolve(moduleInit);\n })\n .catch(reject);\n },\n })\n );\n });\n\n // print warning if loaded version differs from hardcoded one\n if (lensCoreWasm.version != `${lensCore.getCoreVersion()}`) {\n logger.warn(\n `Loaded LensCore version (${lensCore.getCoreVersion()}) differs from expected one (${\n lensCoreWasm.version\n })`\n );\n }\n\n return lensCore;\n }\n);\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
3
|
-
"buildNumber": "
|
|
4
|
-
"baseUrl": "https://cf-st.sc-cdn.net/d/
|
|
2
|
+
"version": "214",
|
|
3
|
+
"buildNumber": "22",
|
|
4
|
+
"baseUrl": "https://cf-st.sc-cdn.net/d/NhOZEMtsN1zJBWzj2dabN?go=IgsKCTIBBEgBUFxgAQ%3D%3D&uc=9"
|
|
5
5
|
}
|
|
@@ -21,7 +21,7 @@ const getImageBitmap = (imageData, format) => __awaiter(void 0, void 0, void 0,
|
|
|
21
21
|
case "nv12":
|
|
22
22
|
case "yuv":
|
|
23
23
|
if (!window.VideoFrame)
|
|
24
|
-
return Promise.reject(new Error(`Cannot process frame. ImageData in ${format}
|
|
24
|
+
return Promise.reject(new Error(`Cannot process frame. ImageData in ${format} is not supported by this browser.`));
|
|
25
25
|
const frame = new VideoFrame(imageData.data.buffer, {
|
|
26
26
|
format: "NV12",
|
|
27
27
|
codedWidth: imageData.width,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionSource.js","sourceRoot":"","sources":["../../src/media-sources/FunctionSource.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAqD,MAAM,mBAAmB,CAAC;AAEvG,MAAM,eAAe,GAAG,CAAO,MAAyB,EAAE,QAAwB,EAAsB,EAAE;IACtG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACjC,0FAA0F;IAC1F,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,MAAM,IAAI,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE;QACvC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACpG,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACnD,OAAO,IAAI,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAA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,CAAA,CAAC,CAAC;wBACH,2FAA2F;wBAC3F,gFAAgF;wBAChF,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;wBACvE,OAAO,WAAW,CAAC;oBACvB,CAAC,CAAC,CAAC;iBACN;gBAAC,OAAO,KAAK,EAAE;oBACZ,WAAW,CACP,IAAI,KAAK,CACL,kEAAkE;wBAC9D,uBAAuB,MAAA,cAAc,CAAC,IAAI,mCAAI,WAAW,GAAG,EAChE,EAAE,KAAK,EAAE,KAAK,EAAE,CACnB,CACJ,CAAC;iBACL;YACL,CAAC,CAAA,CAAC,CAAC;YACP,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;QAChD,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE;YACX,kBAAkB,GAAG,KAAK,CAAC;QAC/B,CAAC;KACJ,CAAC;IAEF,OAAO,IAAI,eAAe,CAAC,EAAE,wBAAwB,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACxF,CAAC,CAAC","sourcesContent":["import { LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { CameraKitSource, CameraKitSourceOptions, CameraKitSourceSubscriber } from \"./CameraKitSource\";\n\nconst getYUVImageData = async (canvas: HTMLCanvasElement, lensCore: LensCoreModule): Promise<ImageData> => {\n const { width, height } = canvas;\n // A YUV buffer has lower-res UV channels, so the total number of bytes works out like so:\n const outputBuffer = new ArrayBuffer((width * height * 3) / 2);\n await new Promise((onSuccess, onFailure) => {\n lensCore.imageToYuvBuffer({ image: canvas, width, height, outputBuffer, onSuccess, onFailure });\n });\n const pixels = new Uint8ClampedArray(outputBuffer);\n return new ImageData(pixels, width, height);\n};\n\nconst getRGBImageData = (output: HTMLCanvasElement, imageReader2D: CanvasRenderingContext2D | null): ImageData => {\n if (imageReader2D === null) return new ImageData(0, 0);\n imageReader2D.drawImage(output, 0, 0);\n return imageReader2D.getImageData(0, 0, output.width, output.height);\n};\n\nconst getImageBitmap = async (imageData: ImageData, format: FrameFormat): Promise<ImageBitmap> => {\n switch (format) {\n case \"nv12\":\n case \"yuv\":\n if (!window.VideoFrame)\n return Promise.reject(\n new Error(`Cannot process frame. ImageData in ${format} ` + `is not supported by this browser.`)\n );\n const frame = new VideoFrame(imageData.data.buffer, {\n format: \"NV12\",\n codedWidth: imageData.width,\n codedHeight: imageData.height,\n timestamp: 0,\n });\n return createImageBitmap(frame);\n case \"rgb\":\n return createImageBitmap(imageData);\n }\n};\n\n/** @internal */\nexport type FrameFormat = \"rgb\" | \"yuv\" | \"nv12\";\n\n/** @internal */\nexport interface FrameInput {\n format?: FrameFormat;\n imageData: ImageData;\n timestampMillis: number;\n}\n\n/** @internal */\nexport interface FrameOutput {\n live: ImageData;\n capture: ImageData;\n}\n\n/** @internal */\nexport interface MediaSourceFunction {\n (render: (frame: FrameInput) => Promise<FrameOutput>): Promise<void>;\n}\n\n/**\n * Creates a {@link CameraKitSource} from a function which provides per-frame pixel data to CameraKit.\n *\n * @param sourceFunction This function will be called in a requestAnimationFrame loop. Each time it is called, it is\n * passed a `render` function. It may call `render` and CameraKit will process the pixel data passed to `render` and\n * return a Promise of the processed pixels (along with rendering them to the normal output canvases).\n * @param options\n * @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.\n *\n * @internal\n */\nexport const createFunctionSource = (\n sourceFunction: MediaSourceFunction,\n options: Omit<CameraKitSourceOptions, \"fpsLimit\"> = {}\n): CameraKitSource => {\n let width = 0;\n let height = 0;\n let shouldProcessFrame = true;\n\n // We require an auxiliary canvas that we can use to read back pixel data (unless we're in YUV mode, in which case\n // we use LensCore to convert between formats and we don't need this canvas).\n const imageReaderCanvas = document.createElement(\"canvas\");\n const imageReader2D = imageReaderCanvas.getContext(\"2d\");\n\n const subscriber: CameraKitSourceSubscriber = {\n onAttach: (source, lensCore, reportError) => {\n const outputs = lensCore.getOutputCanvases();\n const output = {\n live: outputs[lensCore.CanvasType.Preview.value],\n capture: outputs[lensCore.CanvasType.Capture.value],\n };\n\n const processFrame = (\n source: CameraKitSource,\n lensCore: LensCoreModule,\n reportError: (error: Error) => void\n ) =>\n requestAnimationFrame(async () => {\n if (!shouldProcessFrame) return;\n try {\n await sourceFunction(({ format, imageData, timestampMillis }) => {\n const frameOutput = new Promise<FrameOutput>(async (resolve, reject) => {\n const inputFrame = await getImageBitmap(imageData, format ?? \"rgb\");\n if (inputFrame.width !== width || inputFrame.height !== height) {\n width = imageReaderCanvas.width = inputFrame.width;\n height = imageReaderCanvas.height = inputFrame.height;\n // We don't await this promise, because we want to continue to process frames and\n // let LensCore manage the concurrency between setting resolution and processing a\n // frame.\n source.setRenderSize(width, height);\n }\n lensCore.processFrame({\n inputFrame,\n timestampMillis,\n onSuccess: async () => {\n // Closing releases graphics resources associated with the frame, now that is\n // has been processed.\n inputFrame.close();\n\n switch (format ?? \"rgb\") {\n case \"nv12\":\n case \"yuv\":\n const [live, capture] = await Promise.all([\n getYUVImageData(output.live, lensCore),\n getYUVImageData(output.capture, lensCore),\n ]).catch((error) => {\n reject(error);\n return [undefined, undefined] as const;\n });\n // if either of these is undefined, we'll have already rejected\n // the promise, so we can return.\n if (!live || !capture) return;\n return resolve({ live, capture });\n case \"rgb\":\n return resolve({\n live: getRGBImageData(output.live, imageReader2D),\n capture: getRGBImageData(output.capture, imageReader2D),\n });\n }\n },\n onFailure: (error) => {\n inputFrame.close();\n reject(error);\n },\n });\n });\n // Even if there's an error processing the frame, we do want to attempt to process the next\n // frame. We expect `sourceFunction` to handle a rejected `frameOutput` Promise.\n frameOutput.finally(() => processFrame(source, lensCore, reportError));\n return frameOutput;\n });\n } catch (error) {\n reportError(\n new Error(\n \"Failure to process frame, which was not handled by the provided \" +\n `MediaSourceFunction ${sourceFunction.name ?? \"anonymous\"}.`,\n { cause: error }\n )\n );\n }\n });\n processFrame(source, lensCore, reportError);\n },\n onDetach: () => {\n shouldProcessFrame = false;\n },\n };\n\n return new CameraKitSource({ useManualFrameProcessing: true }, subscriber, options);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"FunctionSource.js","sourceRoot":"","sources":["../../src/media-sources/FunctionSource.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAqD,MAAM,mBAAmB,CAAC;AAEvG,MAAM,eAAe,GAAG,CAAO,MAAyB,EAAE,QAAwB,EAAsB,EAAE;IACtG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACjC,0FAA0F;IAC1F,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,MAAM,IAAI,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE;QACvC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACpG,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACnD,OAAO,IAAI,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC,CAAA,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,MAAyB,EAAE,aAA8C,EAAa,EAAE;IAC7G,IAAI,aAAa,KAAK,IAAI;QAAE,OAAO,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACvD,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACtC,OAAO,aAAa,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AACzE,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAO,SAAoB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P,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;QAChD,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE;YACX,kBAAkB,GAAG,KAAK,CAAC;QAC/B,CAAC;KACJ,CAAC;IAEF,OAAO,IAAI,eAAe,CAAC,EAAE,wBAAwB,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACxF,CAAC,CAAC","sourcesContent":["import { LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { CameraKitSource, CameraKitSourceOptions, CameraKitSourceSubscriber } from \"./CameraKitSource\";\n\nconst getYUVImageData = async (canvas: HTMLCanvasElement, lensCore: LensCoreModule): Promise<ImageData> => {\n const { width, height } = canvas;\n // A YUV buffer has lower-res UV channels, so the total number of bytes works out like so:\n const outputBuffer = new ArrayBuffer((width * height * 3) / 2);\n await new Promise((onSuccess, onFailure) => {\n lensCore.imageToYuvBuffer({ image: canvas, width, height, outputBuffer, onSuccess, onFailure });\n });\n const pixels = new Uint8ClampedArray(outputBuffer);\n return new ImageData(pixels, width, height);\n};\n\nconst getRGBImageData = (output: HTMLCanvasElement, imageReader2D: CanvasRenderingContext2D | null): ImageData => {\n if (imageReader2D === null) return new ImageData(0, 0);\n imageReader2D.drawImage(output, 0, 0);\n return imageReader2D.getImageData(0, 0, output.width, output.height);\n};\n\nconst getImageBitmap = async (imageData: ImageData, format: FrameFormat): Promise<ImageBitmap> => {\n switch (format) {\n case \"nv12\":\n case \"yuv\":\n if (!window.VideoFrame)\n return Promise.reject(\n new Error(`Cannot process frame. ImageData in ${format} is not supported by this browser.`)\n );\n const frame = new VideoFrame(imageData.data.buffer, {\n format: \"NV12\",\n codedWidth: imageData.width,\n codedHeight: imageData.height,\n timestamp: 0,\n });\n return createImageBitmap(frame);\n case \"rgb\":\n return createImageBitmap(imageData);\n }\n};\n\n/** @internal */\nexport type FrameFormat = \"rgb\" | \"yuv\" | \"nv12\";\n\n/** @internal */\nexport interface FrameInput {\n format?: FrameFormat;\n imageData: ImageData;\n timestampMillis: number;\n}\n\n/** @internal */\nexport interface FrameOutput {\n live: ImageData;\n capture: ImageData;\n}\n\n/** @internal */\nexport interface MediaSourceFunction {\n (render: (frame: FrameInput) => Promise<FrameOutput>): Promise<void>;\n}\n\n/**\n * Creates a {@link CameraKitSource} from a function which provides per-frame pixel data to CameraKit.\n *\n * @param sourceFunction This function will be called in a requestAnimationFrame loop. Each time it is called, it is\n * passed a `render` function. It may call `render` and CameraKit will process the pixel data passed to `render` and\n * return a Promise of the processed pixels (along with rendering them to the normal output canvases).\n * @param options\n * @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.\n *\n * @internal\n */\nexport const createFunctionSource = (\n sourceFunction: MediaSourceFunction,\n options: Omit<CameraKitSourceOptions, \"fpsLimit\"> = {}\n): CameraKitSource => {\n let width = 0;\n let height = 0;\n let shouldProcessFrame = true;\n\n // We require an auxiliary canvas that we can use to read back pixel data (unless we're in YUV mode, in which case\n // we use LensCore to convert between formats and we don't need this canvas).\n const imageReaderCanvas = document.createElement(\"canvas\");\n const imageReader2D = imageReaderCanvas.getContext(\"2d\");\n\n const subscriber: CameraKitSourceSubscriber = {\n onAttach: (source, lensCore, reportError) => {\n const outputs = lensCore.getOutputCanvases();\n const output = {\n live: outputs[lensCore.CanvasType.Preview.value],\n capture: outputs[lensCore.CanvasType.Capture.value],\n };\n\n const processFrame = (\n source: CameraKitSource,\n lensCore: LensCoreModule,\n reportError: (error: Error) => void\n ) =>\n requestAnimationFrame(async () => {\n if (!shouldProcessFrame) return;\n try {\n await sourceFunction(({ format, imageData, timestampMillis }) => {\n const frameOutput = new Promise<FrameOutput>(async (resolve, reject) => {\n const inputFrame = await getImageBitmap(imageData, format ?? \"rgb\");\n if (inputFrame.width !== width || inputFrame.height !== height) {\n width = imageReaderCanvas.width = inputFrame.width;\n height = imageReaderCanvas.height = inputFrame.height;\n // We don't await this promise, because we want to continue to process frames and\n // let LensCore manage the concurrency between setting resolution and processing a\n // frame.\n source.setRenderSize(width, height);\n }\n lensCore.processFrame({\n inputFrame,\n timestampMillis,\n onSuccess: async () => {\n // Closing releases graphics resources associated with the frame, now that is\n // has been processed.\n inputFrame.close();\n\n switch (format ?? \"rgb\") {\n case \"nv12\":\n case \"yuv\":\n const [live, capture] = await Promise.all([\n getYUVImageData(output.live, lensCore),\n getYUVImageData(output.capture, lensCore),\n ]).catch((error) => {\n reject(error);\n return [undefined, undefined] as const;\n });\n // if either of these is undefined, we'll have already rejected\n // the promise, so we can return.\n if (!live || !capture) return;\n return resolve({ live, capture });\n case \"rgb\":\n return resolve({\n live: getRGBImageData(output.live, imageReader2D),\n capture: getRGBImageData(output.capture, imageReader2D),\n });\n }\n },\n onFailure: (error) => {\n inputFrame.close();\n reject(error);\n },\n });\n });\n // Even if there's an error processing the frame, we do want to attempt to process the next\n // frame. We expect `sourceFunction` to handle a rejected `frameOutput` Promise.\n frameOutput.finally(() => processFrame(source, lensCore, reportError));\n return frameOutput;\n });\n } catch (error) {\n reportError(\n new Error(\n \"Failure to process frame, which was not handled by the provided \" +\n `MediaSourceFunction ${sourceFunction.name ?? \"anonymous\"}.`,\n { cause: error }\n )\n );\n }\n });\n processFrame(source, lensCore, reportError);\n },\n onDetach: () => {\n shouldProcessFrame = false;\n },\n };\n\n return new CameraKitSource({ useManualFrameProcessing: true }, subscriber, options);\n};\n"]}
|
|
@@ -21,13 +21,17 @@ export interface MediaStreamSourceOptions {
|
|
|
21
21
|
* @returns A Promise, resolving to {@link CameraKitSource}
|
|
22
22
|
*
|
|
23
23
|
* @category Rendering
|
|
24
|
+
*
|
|
25
|
+
* @deprecated The helper will be removed in one of the future releases.
|
|
26
|
+
* Consumer apps are responsible for acquiring a media stream,
|
|
27
|
+
* which can then be supplied to {@link createMediaStreamSource}.
|
|
24
28
|
*/
|
|
25
29
|
export declare function createUserMediaSource(constraints?: MediaStreamConstraints, options?: CameraKitSourceOptions<MediaStreamSourceOptions>): Promise<CameraKitSource>;
|
|
26
30
|
/**
|
|
27
31
|
* Create a {@link CameraKitSource} from any
|
|
28
32
|
* [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).
|
|
29
33
|
*
|
|
30
|
-
* @param stream Any MediaStream, such as obtained via `canvas.captureStream()`
|
|
34
|
+
* @param stream Any MediaStream, such as obtained via `canvas.captureStream()` or `mediaDevices.getUserMedia()`.
|
|
31
35
|
* @param options
|
|
32
36
|
* @param options.transform We apply no transformation by default.
|
|
33
37
|
* @param options.disableSourceAudio By default we pass audio to lens. Settings this to true will disable sending audio
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
+
import { ensureError } from "../common/errorHelpers";
|
|
2
3
|
import { Transform2D } from "../transforms";
|
|
3
4
|
import { CameraKitSource } from "./CameraKitSource";
|
|
4
5
|
const defaultOptions = {
|
|
5
6
|
transform: Transform2D.Identity,
|
|
6
7
|
disableSourceAudio: false,
|
|
7
8
|
};
|
|
9
|
+
function closeWorklet(worklet) {
|
|
10
|
+
if (!worklet)
|
|
11
|
+
return;
|
|
12
|
+
worklet.port.onmessage = null;
|
|
13
|
+
worklet.disconnect();
|
|
14
|
+
}
|
|
8
15
|
/**
|
|
9
16
|
* Create a {@link CameraKitSource} from a user's media device -- this calls
|
|
10
17
|
* [MediaDevices.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) to get a
|
|
@@ -21,6 +28,10 @@ const defaultOptions = {
|
|
|
21
28
|
* @returns A Promise, resolving to {@link CameraKitSource}
|
|
22
29
|
*
|
|
23
30
|
* @category Rendering
|
|
31
|
+
*
|
|
32
|
+
* @deprecated The helper will be removed in one of the future releases.
|
|
33
|
+
* Consumer apps are responsible for acquiring a media stream,
|
|
34
|
+
* which can then be supplied to {@link createMediaStreamSource}.
|
|
24
35
|
*/
|
|
25
36
|
export function createUserMediaSource(constraints = { video: true }, options = {}) {
|
|
26
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -32,7 +43,7 @@ export function createUserMediaSource(constraints = { video: true }, options = {
|
|
|
32
43
|
* Create a {@link CameraKitSource} from any
|
|
33
44
|
* [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).
|
|
34
45
|
*
|
|
35
|
-
* @param stream Any MediaStream, such as obtained via `canvas.captureStream()`
|
|
46
|
+
* @param stream Any MediaStream, such as obtained via `canvas.captureStream()` or `mediaDevices.getUserMedia()`.
|
|
36
47
|
* @param options
|
|
37
48
|
* @param options.transform We apply no transformation by default.
|
|
38
49
|
* @param options.disableSourceAudio By default we pass audio to lens. Settings this to true will disable sending audio
|
|
@@ -51,6 +62,7 @@ export function createMediaStreamSource(stream, options = {}) {
|
|
|
51
62
|
const sampleRate = 44100;
|
|
52
63
|
let audioContext = undefined;
|
|
53
64
|
let audioSource = undefined;
|
|
65
|
+
let worklet = undefined;
|
|
54
66
|
let microphoneRecorderUrl;
|
|
55
67
|
if (enableSourceAudio) {
|
|
56
68
|
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_AudioWorklet
|
|
@@ -86,8 +98,16 @@ export function createMediaStreamSource(stream, options = {}) {
|
|
|
86
98
|
reportError(error);
|
|
87
99
|
},
|
|
88
100
|
});
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
try {
|
|
102
|
+
// There is a possibility of the onAttach method being called twice in a row due to a bug.
|
|
103
|
+
// To ensure there are not leaks, it is better to close any existing connections.
|
|
104
|
+
closeWorklet(worklet);
|
|
105
|
+
audioSource === null || audioSource === void 0 ? void 0 : audioSource.disconnect();
|
|
106
|
+
yield (audioContext === null || audioContext === void 0 ? void 0 : audioContext.close());
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
// We still want to continue if anything above failed
|
|
110
|
+
reportError(ensureError(error));
|
|
91
111
|
}
|
|
92
112
|
audioContext = new AudioContext();
|
|
93
113
|
audioSource = audioContext.createMediaStreamSource(stream);
|
|
@@ -96,13 +116,13 @@ export function createMediaStreamSource(stream, options = {}) {
|
|
|
96
116
|
.addModule(microphoneRecorderUrl)
|
|
97
117
|
.then(() => {
|
|
98
118
|
if (audioContext) {
|
|
99
|
-
|
|
119
|
+
worklet = new AudioWorkletNode(audioContext, "microphone-worklet");
|
|
100
120
|
scopedAudioSource.connect(worklet);
|
|
101
121
|
worklet.connect(audioContext.destination);
|
|
102
122
|
// NOTE: We subscribe to messages here, and they will continue to arrive
|
|
103
123
|
// even after audioContext.close() is called. To disconnect the audio worklets
|
|
104
|
-
// created here, we need to track
|
|
105
|
-
// By calling
|
|
124
|
+
// created here, we need to track two variables - worklet and audioSource.
|
|
125
|
+
// By calling disconnect() on them, we can properly
|
|
106
126
|
// disconnect the audio worklets.
|
|
107
127
|
worklet.port.onmessage = (e) => {
|
|
108
128
|
if (e.data.eventType === "data") {
|
|
@@ -130,6 +150,10 @@ export function createMediaStreamSource(stream, options = {}) {
|
|
|
130
150
|
}
|
|
131
151
|
}),
|
|
132
152
|
onDetach: (reportError) => __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
if (worklet) {
|
|
154
|
+
closeWorklet(worklet);
|
|
155
|
+
worklet = undefined;
|
|
156
|
+
}
|
|
133
157
|
if (audioSource) {
|
|
134
158
|
audioSource.disconnect();
|
|
135
159
|
audioSource = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaStreamSource.js","sourceRoot":"","sources":["../../src/media-sources/MediaStreamSource.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAE5E,MAAM,cAAc,GAA6B;IAC7C,SAAS,EAAE,WAAW,CAAC,QAAQ;IAC/B,kBAAkB,EAAE,KAAK;CAC5B,CAAC;AAQF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAgB,qBAAqB,CACvC,cAAsC,EAAE,KAAK,EAAE,IAAI,EAAE,EACrD,UAA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AAC,CAAC;gBACH,YAAY,GAAG,SAAS,CAAC;aAC5B;QACL,CAAC,CAAA;KACJ,EACD,OAAO,CACV,CAAC;AACN,CAAC","sourcesContent":["import { Transform2D } from \"../transforms\";\nimport { CameraKitSource, CameraKitSourceOptions } from \"./CameraKitSource\";\n\nconst defaultOptions: MediaStreamSourceOptions = {\n transform: Transform2D.Identity,\n disableSourceAudio: false,\n};\n\n/** @category Rendering */\nexport interface MediaStreamSourceOptions {\n transform: Transform2D;\n disableSourceAudio: boolean; // defaults to false\n}\n\n/**\n * Create a {@link CameraKitSource} from a user's media device -- this calls\n * [MediaDevices.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) to get a\n * MediaStream and then calls {@link createMediaStreamSource}.\n *\n * @param constraints Specify contraints used to get a MediaStream from a media device. By default we simply request\n * a video stream.\n * @param options\n * @param options.transform By default we horizontally mirror the video stream. The most common use-case is to obtain a\n * stream from a front-facing web cam, which requires mirroring to be viewed naturally.\n * @param options.cameraType By default we set this to 'front' to indicate a camera pointed at the user (e.g. a webcam).\n * @param options.fpsLimit By default we set no limit on FPS – if the source device has a known FPS setting this limit\n * may prevent CameraKit from using more compute resources than strictly necessary.\n * @returns A Promise, resolving to {@link CameraKitSource}\n *\n * @category Rendering\n */\nexport async function createUserMediaSource(\n constraints: MediaStreamConstraints = { video: true },\n options: CameraKitSourceOptions<MediaStreamSourceOptions> = {}\n): Promise<CameraKitSource> {\n const stream = await navigator.mediaDevices.getUserMedia(constraints);\n return createMediaStreamSource(stream, { transform: Transform2D.MirrorX, cameraType: \"front\", ...options });\n}\n\n/**\n * Create a {@link CameraKitSource} from any\n * [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).\n *\n * @param stream Any MediaStream, such as obtained via `canvas.captureStream()`\n * @param options\n * @param options.transform We apply no transformation by default.\n * @param options.disableSourceAudio By default we pass audio to lens. Settings this to true will disable sending audio\n * to the lens.\n * @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.\n * @param options.fpsLimit By default we set no limit on FPS – if the MediaStream has a known FPS setting this limit\n * may prevent CameraKit from using more compute resources than strictly necessary.\n *\n * @category Rendering\n */\nexport function createMediaStreamSource(\n stream: MediaStream,\n options: CameraKitSourceOptions<MediaStreamSourceOptions> = {}\n): CameraKitSource {\n const optionsNotNull = {\n ...defaultOptions,\n ...options,\n };\n\n const { width, height } =\n stream.getVideoTracks().length > 0 ? stream.getVideoTracks()[0].getSettings() : { width: 0, height: 0 };\n const enableSourceAudio: boolean = stream.getAudioTracks().length > 0 && !optionsNotNull.disableSourceAudio;\n\n const simulateStereoAudio = true;\n const sampleRate: number = 44100;\n\n let audioContext: AudioContext | undefined = undefined;\n let audioSource: MediaStreamAudioSourceNode | undefined = undefined;\n let microphoneRecorderUrl: string;\n\n if (enableSourceAudio) {\n // https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_AudioWorklet\n const microphoneRecorderWorklet = `\n class MicrophoneWorkletProcessor extends AudioWorkletProcessor {\n process(inputs, outputs, parameters) {\n this.port.postMessage({\n eventType: 'data',\n buffer: inputs\n });\n return true;\n }\n }\n registerProcessor('microphone-worklet', MicrophoneWorkletProcessor);`;\n const microphoneRecorderBlob = new Blob([microphoneRecorderWorklet], {\n type: \"application/javascript\",\n });\n microphoneRecorderUrl = URL.createObjectURL(microphoneRecorderBlob);\n }\n\n return new CameraKitSource(\n { media: stream },\n {\n onAttach: async (source, lensCore, reportError) => {\n if (width !== undefined && height !== undefined) await source.setRenderSize(width, height);\n await source.setTransform(optionsNotNull.transform);\n\n if (enableSourceAudio) {\n // Audio paramters set has to be called before lens is applied\n lensCore.setAudioParameters({\n parameters: {\n numChannels: simulateStereoAudio ? 2 : 1,\n sampleRate,\n },\n onFailure: (error: Error) => {\n reportError(error);\n },\n });\n\n if (audioContext) {\n await audioContext.close();\n }\n\n audioContext = new AudioContext();\n audioSource = audioContext.createMediaStreamSource(stream);\n const scopedAudioSource = audioSource;\n audioContext.audioWorklet\n .addModule(microphoneRecorderUrl)\n .then(() => {\n if (audioContext) {\n const worklet = new AudioWorkletNode(audioContext, \"microphone-worklet\");\n scopedAudioSource.connect(worklet);\n worklet.connect(audioContext.destination);\n // NOTE: We subscribe to messages here, and they will continue to arrive\n // even after audioContext.close() is called. To disconnect the audio worklets\n // created here, we need to track another variable - audioSource.\n // By calling audioSource.disconnect(), we can properly\n // disconnect the audio worklets.\n worklet.port.onmessage = (e) => {\n if (e.data.eventType === \"data\") {\n // developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor/process\n // inputs[n][m] is the list of samples in the n-th input at the m-th channel.\n const leftSamples = e.data.buffer[0][0] as Float32Array;\n let inputBuffers = [leftSamples];\n if (simulateStereoAudio) {\n const rightSamples =\n e.data.buffer[0].length > 1 ? e.data.buffer[0][1] : leftSamples.slice();\n inputBuffers.push(rightSamples);\n }\n\n lensCore.processAudioSampleBuffer({\n input: inputBuffers,\n onFailure: (error: Error) => {\n reportError(error);\n },\n });\n }\n };\n }\n })\n .catch((error: Error) => {\n reportError(error);\n });\n }\n },\n onDetach: async (reportError) => {\n if (audioSource) {\n audioSource.disconnect();\n audioSource = undefined;\n }\n if (audioContext) {\n await audioContext.close().catch((error: Error) => {\n reportError(error);\n });\n audioContext = undefined;\n }\n },\n },\n options\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MediaStreamSource.js","sourceRoot":"","sources":["../../src/media-sources/MediaStreamSource.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAE5E,MAAM,cAAc,GAA6B;IAC7C,SAAS,EAAE,WAAW,CAAC,QAAQ;IAC/B,kBAAkB,EAAE,KAAK;CAC5B,CAAC;AAEF,SAAS,YAAY,CAAC,OAAqC;IACvD,IAAI,CAAC,OAAO;QAAE,OA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AAK,CAAC,CAAC;oCACvB,CAAC;iCACJ,CAAC,CAAC;6BACN;wBACL,CAAC,CAAC;qBACL;gBACL,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;oBACpB,WAAW,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC,CAAC,CAAC;aACV;QACL,CAAC,CAAA;QACD,QAAQ,EAAE,CAAO,WAAW,EAAE,EAAE;YAC5B,IAAI,OAAO,EAAE;gBACT,YAAY,CAAC,OAAO,CAAC,CAAC;gBACtB,OAAO,GAAG,SAAS,CAAC;aACvB;YACD,IAAI,WAAW,EAAE;gBACb,WAAW,CAAC,UAAU,EAAE,CAAC;gBACzB,WAAW,GAAG,SAAS,CAAC;aAC3B;YACD,IAAI,YAAY,EAAE;gBACd,MAAM,YAAY,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;oBAC9C,WAAW,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC,CAAC,CAAC;gBACH,YAAY,GAAG,SAAS,CAAC;aAC5B;QACL,CAAC,CAAA;KACJ,EACD,OAAO,CACV,CAAC;AACN,CAAC","sourcesContent":["import { ensureError } from \"../common/errorHelpers\";\nimport { Transform2D } from \"../transforms\";\nimport { CameraKitSource, CameraKitSourceOptions } from \"./CameraKitSource\";\n\nconst defaultOptions: MediaStreamSourceOptions = {\n transform: Transform2D.Identity,\n disableSourceAudio: false,\n};\n\nfunction closeWorklet(worklet: AudioWorkletNode | undefined) {\n if (!worklet) return;\n worklet.port.onmessage = null;\n worklet.disconnect();\n}\n\n/** @category Rendering */\nexport interface MediaStreamSourceOptions {\n transform: Transform2D;\n disableSourceAudio: boolean; // defaults to false\n}\n\n/**\n * Create a {@link CameraKitSource} from a user's media device -- this calls\n * [MediaDevices.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) to get a\n * MediaStream and then calls {@link createMediaStreamSource}.\n *\n * @param constraints Specify contraints used to get a MediaStream from a media device. By default we simply request\n * a video stream.\n * @param options\n * @param options.transform By default we horizontally mirror the video stream. The most common use-case is to obtain a\n * stream from a front-facing web cam, which requires mirroring to be viewed naturally.\n * @param options.cameraType By default we set this to 'front' to indicate a camera pointed at the user (e.g. a webcam).\n * @param options.fpsLimit By default we set no limit on FPS – if the source device has a known FPS setting this limit\n * may prevent CameraKit from using more compute resources than strictly necessary.\n * @returns A Promise, resolving to {@link CameraKitSource}\n *\n * @category Rendering\n *\n * @deprecated The helper will be removed in one of the future releases.\n * Consumer apps are responsible for acquiring a media stream,\n * which can then be supplied to {@link createMediaStreamSource}.\n */\nexport async function createUserMediaSource(\n constraints: MediaStreamConstraints = { video: true },\n options: CameraKitSourceOptions<MediaStreamSourceOptions> = {}\n): Promise<CameraKitSource> {\n const stream = await navigator.mediaDevices.getUserMedia(constraints);\n return createMediaStreamSource(stream, { transform: Transform2D.MirrorX, cameraType: \"front\", ...options });\n}\n\n/**\n * Create a {@link CameraKitSource} from any\n * [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).\n *\n * @param stream Any MediaStream, such as obtained via `canvas.captureStream()` or `mediaDevices.getUserMedia()`.\n * @param options\n * @param options.transform We apply no transformation by default.\n * @param options.disableSourceAudio By default we pass audio to lens. Settings this to true will disable sending audio\n * to the lens.\n * @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.\n * @param options.fpsLimit By default we set no limit on FPS – if the MediaStream has a known FPS setting this limit\n * may prevent CameraKit from using more compute resources than strictly necessary.\n *\n * @category Rendering\n */\nexport function createMediaStreamSource(\n stream: MediaStream,\n options: CameraKitSourceOptions<MediaStreamSourceOptions> = {}\n): CameraKitSource {\n const optionsNotNull = {\n ...defaultOptions,\n ...options,\n };\n\n const { width, height } =\n stream.getVideoTracks().length > 0 ? stream.getVideoTracks()[0].getSettings() : { width: 0, height: 0 };\n const enableSourceAudio: boolean = stream.getAudioTracks().length > 0 && !optionsNotNull.disableSourceAudio;\n\n const simulateStereoAudio = true;\n const sampleRate: number = 44100;\n\n let audioContext: AudioContext | undefined = undefined;\n let audioSource: MediaStreamAudioSourceNode | undefined = undefined;\n let worklet: AudioWorkletNode | undefined = undefined;\n let microphoneRecorderUrl: string;\n\n if (enableSourceAudio) {\n // https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_AudioWorklet\n const microphoneRecorderWorklet = `\n class MicrophoneWorkletProcessor extends AudioWorkletProcessor {\n process(inputs, outputs, parameters) {\n this.port.postMessage({\n eventType: 'data',\n buffer: inputs\n });\n return true;\n }\n }\n registerProcessor('microphone-worklet', MicrophoneWorkletProcessor);`;\n const microphoneRecorderBlob = new Blob([microphoneRecorderWorklet], {\n type: \"application/javascript\",\n });\n microphoneRecorderUrl = URL.createObjectURL(microphoneRecorderBlob);\n }\n\n return new CameraKitSource(\n { media: stream },\n {\n onAttach: async (source, lensCore, reportError) => {\n if (width !== undefined && height !== undefined) await source.setRenderSize(width, height);\n await source.setTransform(optionsNotNull.transform);\n\n if (enableSourceAudio) {\n // Audio paramters set has to be called before lens is applied\n lensCore.setAudioParameters({\n parameters: {\n numChannels: simulateStereoAudio ? 2 : 1,\n sampleRate,\n },\n onFailure: (error: Error) => {\n reportError(error);\n },\n });\n\n try {\n // There is a possibility of the onAttach method being called twice in a row due to a bug.\n // To ensure there are not leaks, it is better to close any existing connections.\n closeWorklet(worklet);\n audioSource?.disconnect();\n await audioContext?.close();\n } catch (error) {\n // We still want to continue if anything above failed\n reportError(ensureError(error));\n }\n\n audioContext = new AudioContext();\n audioSource = audioContext.createMediaStreamSource(stream);\n const scopedAudioSource = audioSource;\n audioContext.audioWorklet\n .addModule(microphoneRecorderUrl)\n .then(() => {\n if (audioContext) {\n worklet = new AudioWorkletNode(audioContext, \"microphone-worklet\");\n scopedAudioSource.connect(worklet);\n worklet.connect(audioContext.destination);\n // NOTE: We subscribe to messages here, and they will continue to arrive\n // even after audioContext.close() is called. To disconnect the audio worklets\n // created here, we need to track two variables - worklet and audioSource.\n // By calling disconnect() on them, we can properly\n // disconnect the audio worklets.\n worklet.port.onmessage = (e) => {\n if (e.data.eventType === \"data\") {\n // developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor/process\n // inputs[n][m] is the list of samples in the n-th input at the m-th channel.\n const leftSamples = e.data.buffer[0][0] as Float32Array;\n let inputBuffers = [leftSamples];\n if (simulateStereoAudio) {\n const rightSamples =\n e.data.buffer[0].length > 1 ? e.data.buffer[0][1] : leftSamples.slice();\n inputBuffers.push(rightSamples);\n }\n\n lensCore.processAudioSampleBuffer({\n input: inputBuffers,\n onFailure: (error: Error) => {\n reportError(error);\n },\n });\n }\n };\n }\n })\n .catch((error: Error) => {\n reportError(error);\n });\n }\n },\n onDetach: async (reportError) => {\n if (worklet) {\n closeWorklet(worklet);\n worklet = undefined;\n }\n if (audioSource) {\n audioSource.disconnect();\n audioSource = undefined;\n }\n if (audioContext) {\n await audioContext.close().catch((error: Error) => {\n reportError(error);\n });\n audioContext = undefined;\n }\n },\n },\n options\n );\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CofDimensions } from "../../remote-configuration/cofHandler";
|
|
2
|
-
import { Dimensions } from "../../handlers/requestStateEmittingHandler";
|
|
2
|
+
import { Dimensions, RequestStateEventTarget } from "../../handlers/requestStateEmittingHandler";
|
|
3
3
|
import { OperationalMetricsReporter } from "../operationalMetricsReporter";
|
|
4
4
|
import { AssetDownloadDimensions, LensDownloadDimensions } from "./reportLensAndAssetDownload";
|
|
5
5
|
declare global {
|
|
@@ -11,7 +11,7 @@ declare global {
|
|
|
11
11
|
}
|
|
12
12
|
export declare const isRelevantRequest: (value: Dimensions) => value is CofDimensions | AssetDownloadDimensions | LensDownloadDimensions;
|
|
13
13
|
export declare const reportHttpMetrics: {
|
|
14
|
-
(args_0: OperationalMetricsReporter): void;
|
|
14
|
+
(args_0: OperationalMetricsReporter, args_1: RequestStateEventTarget): void;
|
|
15
15
|
token: "reportHttpMetrics";
|
|
16
|
-
dependencies: readonly ["operationalMetricsReporter"];
|
|
16
|
+
dependencies: readonly ["operationalMetricsReporter", "requestStateEventTarget"];
|
|
17
17
|
};
|
|
@@ -2,7 +2,7 @@ import { assertUnreachable } from "../../common/assertions";
|
|
|
2
2
|
import { Injectable } from "../../dependency-injection/Injectable";
|
|
3
3
|
import { scan } from "../../events/scan";
|
|
4
4
|
import { COF_REQUEST_TYPE } from "../../remote-configuration/cofHandler";
|
|
5
|
-
import {
|
|
5
|
+
import { requestStateEventTargetFactory, } from "../../handlers/requestStateEmittingHandler";
|
|
6
6
|
import { operationalMetricReporterFactory } from "../operationalMetricsReporter";
|
|
7
7
|
import { isLensOrAssetRequest } from "./reportLensAndAssetDownload";
|
|
8
8
|
const getContentType = (dimensions) => {
|
|
@@ -45,7 +45,7 @@ const getStatus = (event) => {
|
|
|
45
45
|
export const isRelevantRequest = (value) => {
|
|
46
46
|
return isLensOrAssetRequest(value) || value["requestType"] === COF_REQUEST_TYPE;
|
|
47
47
|
};
|
|
48
|
-
export const reportHttpMetrics = Injectable("reportHttpMetrics", [operationalMetricReporterFactory.token], (reporter) => {
|
|
48
|
+
export const reportHttpMetrics = Injectable("reportHttpMetrics", [operationalMetricReporterFactory.token, requestStateEventTargetFactory.token], (reporter, requestStateEventTarget) => {
|
|
49
49
|
scan({ name: "inProgress", inProgress: new Map() })(requestStateEventTarget, ["started", "completed", "errored"], (state, event) => {
|
|
50
50
|
var _a, _b;
|
|
51
51
|
const { inProgress } = state;
|