@snap/camera-kit 0.8.0 → 0.9.1
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/docs/html/assets/main.js +57 -53
- package/docs/html/assets/search.js +1 -1
- package/docs/html/assets/style.css +504 -362
- package/docs/html/classes/CameraKit.html +113 -47
- package/docs/html/classes/CameraKitSession.html +202 -142
- package/docs/html/classes/CameraKitSource.html +124 -60
- package/docs/html/classes/LensPerformanceMeasurement.html +112 -46
- package/docs/html/classes/LensPerformanceMetrics.html +97 -32
- package/docs/html/classes/LensRepository.html +130 -66
- package/docs/html/classes/LensSources.html +98 -32
- package/docs/html/classes/Transform2D.html +111 -43
- package/docs/html/classes/TypedCustomEvent.html +109 -47
- package/docs/html/classes/TypedEventTarget.html +125 -65
- package/docs/html/functions/Injectable.html +113 -120
- package/docs/html/functions/bootstrapCameraKit.html +100 -104
- package/docs/html/functions/createExtension.html +90 -94
- package/docs/html/functions/createImageSource.html +90 -93
- package/docs/html/functions/createMediaStreamSource.html +90 -93
- package/docs/html/functions/createUserMediaSource.html +92 -96
- package/docs/html/functions/createVideoSource.html +90 -93
- package/docs/html/functions/estimateLensPerformance.html +88 -92
- package/docs/html/functions/getRequiredBootstrapURLs.html +90 -94
- package/docs/html/functions/lensSourcesFactory.html +88 -91
- package/docs/html/functions/uriHandlersFactory.html +88 -91
- package/docs/html/index.html +134 -170
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +115 -49
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +111 -45
- package/docs/html/interfaces/ComputedFrameMetrics.html +98 -32
- package/docs/html/interfaces/CreateSessionOptions.html +95 -29
- package/docs/html/interfaces/EstimatedLensPerformance.html +98 -32
- package/docs/html/interfaces/Lens.html +115 -49
- package/docs/html/interfaces/LensSource.html +107 -41
- package/docs/html/interfaces/MediaStreamSourceOptions.html +94 -28
- package/docs/html/interfaces/UriCancelRequest.html +94 -28
- package/docs/html/interfaces/UriHandler.html +108 -42
- package/docs/html/interfaces/UriRequest.html +106 -40
- package/docs/html/interfaces/UriResponse.html +106 -40
- package/docs/html/interfaces/VideoSourceOptions.html +90 -24
- package/docs/html/modules.html +161 -164
- package/docs/html/types/AssetLoader.html +91 -94
- package/docs/html/types/AssetTiming.html +85 -88
- package/docs/html/types/BenchmarkError.html +85 -88
- package/docs/html/types/BootstrapError.html +86 -89
- package/docs/html/types/CacheKeyNotFoundError.html +85 -88
- package/docs/html/types/CameraKitDeviceInfo.html +87 -90
- package/docs/html/types/CameraKitSessionEventListener.html +86 -89
- package/docs/html/types/CameraKitSessionEvents.html +88 -91
- package/docs/html/types/CameraKitSourceError.html +85 -88
- package/docs/html/types/CameraKitSourceInfo.html +85 -88
- package/docs/html/types/CameraKitSourceOptions.html +88 -92
- package/docs/html/types/ConfigurationError.html +86 -89
- package/docs/html/types/Keyboard.html +108 -111
- package/docs/html/types/KeyboardEvents.html +86 -89
- package/docs/html/types/LegalError.html +85 -88
- package/docs/html/types/LensAssetError.html +85 -88
- package/docs/html/types/LensContentValidationError.html +85 -88
- package/docs/html/types/LensError.html +85 -88
- package/docs/html/types/LensExecutionError.html +86 -89
- package/docs/html/types/LensImagePickerError.html +85 -88
- package/docs/html/types/LensLaunchParams.html +85 -88
- package/docs/html/types/LensMetricsEvents.html +86 -89
- package/docs/html/types/LensPerformanceCluster.html +85 -88
- package/docs/html/types/LensView.html +85 -88
- package/docs/html/types/LensWait.html +85 -88
- package/docs/html/types/PersistentStoreError.html +85 -88
- package/docs/html/types/PlatformNotSupportedError.html +86 -89
- package/docs/html/types/PublicContainer.html +85 -88
- package/docs/html/types/RenderTarget.html +85 -88
- package/docs/html/types/Uri.html +85 -88
- package/docs/html/types/UriHandlers.html +86 -89
- package/docs/html/types/WebGLError.html +85 -88
- package/docs/html/variables/extensionRequestContext.html +85 -88
- package/docs/md/README.md +1 -1
- package/docs/md/classes/CameraKit.md +1 -1
- package/docs/md/classes/CameraKitSession.md +1 -1
- 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 +3 -3
- package/docs/md/classes/LensSources.md +1 -1
- package/docs/md/classes/Transform2D.md +3 -1
- package/docs/md/classes/TypedCustomEvent.md +1 -1
- package/docs/md/classes/TypedEventTarget.md +3 -3
- 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 +1 -1
- package/docs/md/interfaces/LensSource.md +1 -1
- package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
- 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 +3 -3
- package/lib/CameraKit.d.ts +9 -9
- package/lib/__tests__/data.d.ts +1 -1
- package/lib/__tests__/deferred.d.ts +1 -1
- package/lib/__tests__/jest.matchers.d.ts +1 -1
- package/lib/benchmark/estimateLensPerformanceCluster.d.ts +2 -2
- package/lib/bootstrapCameraKit.d.ts +1 -1
- package/lib/common/cameraKitUserAgent.d.ts +1 -1
- package/lib/common/localization.d.ts +8 -4
- package/lib/common/localization.js.map +1 -1
- package/lib/common/memoize.d.ts +2 -2
- package/lib/common/pageVisibility.js +1 -1
- package/lib/common/pageVisibility.js.map +1 -1
- package/lib/common/typeguards.d.ts +2 -2
- package/lib/common/types.d.ts +2 -2
- package/lib/common/validate.js +20 -12
- package/lib/common/validate.js.map +1 -1
- package/lib/configuration.d.ts +1 -1
- package/lib/configuration.js.map +1 -1
- package/lib/configurationOverrides.d.ts +1 -1
- package/lib/dependency-injection/Container.d.ts +5 -6
- package/lib/dependency-injection/Container.js +1 -1
- package/lib/dependency-injection/Container.js.map +1 -1
- package/lib/dependency-injection/PartialContainer.d.ts +10 -6
- package/lib/dependency-injection/PartialContainer.js.map +1 -1
- package/lib/dependency-injection/RootServices.d.ts +2 -2
- package/lib/dependency-injection/types.d.ts +9 -9
- package/lib/dependency-injection/types.js.map +1 -1
- package/lib/environment.json +1 -1
- package/lib/events/TypedCustomEvent.d.ts +1 -1
- package/lib/events/TypedEventTarget.d.ts +2 -2
- package/lib/events/scan.d.ts +1 -1
- package/lib/events/scan.js +3 -3
- package/lib/events/scan.js.map +1 -1
- package/lib/extensions/UriHandlers.d.ts +1 -1
- package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +3 -3
- 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 +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +9 -9
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +2 -2
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +17 -17
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +3 -3
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +25 -25
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +4 -4
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +4533 -333
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +4 -4
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +572 -32
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4 -4
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.d.ts +4 -4
- package/lib/generated-proto/pb_schema/common/ruid.d.ts +4 -4
- package/lib/generated-proto/pb_schema/common/value.d.ts +4 -4
- package/lib/generated-proto/pb_schema/google/api/http.d.ts +4 -4
- package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +4 -4
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +4 -4
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +4 -4
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/geocircle.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/geopoint.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/launch_params.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/lures.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/persistent_store.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +4 -4
- package/lib/handlers/HandlerChainBuilder.d.ts +18 -3
- package/lib/handlers/HandlerChainBuilder.js +8 -1
- package/lib/handlers/HandlerChainBuilder.js.map +1 -1
- package/lib/handlers/arrayBufferParsingHandler.d.ts +2 -2
- package/lib/handlers/arrayBufferParsingHandler.js.map +1 -1
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.d.ts +1 -1
- package/lib/handlers/defaultFetchHandler.d.ts +1 -1
- package/lib/handlers/headersModifyingFetchHandler.js +5 -1
- package/lib/handlers/headersModifyingFetchHandler.js.map +1 -1
- package/lib/handlers/noCorsRetryingFetchHandler.js +4 -3
- package/lib/handlers/noCorsRetryingFetchHandler.js.map +1 -1
- package/lib/handlers/requestStateEmittingHandler.d.ts +2 -2
- package/lib/handlers/requestStateEmittingHandler.js.map +1 -1
- package/lib/handlers/responseCachingHandler.d.ts +10 -2
- package/lib/handlers/responseCachingHandler.js +12 -3
- package/lib/handlers/responseCachingHandler.js.map +1 -1
- package/lib/handlers/retryingHandler.d.ts +7 -0
- package/lib/handlers/retryingHandler.js +14 -5
- package/lib/handlers/retryingHandler.js.map +1 -1
- package/lib/legal/legalPrompt.d.ts +1 -1
- package/lib/legal/legalPrompt.js.map +1 -1
- package/lib/legal/legalState.d.ts +1 -1
- package/lib/legal/legalState.js.map +1 -1
- package/lib/lens/Lens.d.ts +1 -1
- package/lib/lens/LensLaunchParams.d.ts +2 -2
- package/lib/lens/LensRepository.d.ts +7 -8
- package/lib/lens/LensRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetRepository.d.ts +2 -2
- package/lib/lens/assets/LensAssetsProvider.d.ts +1 -1
- package/lib/lens/assets/deviceDependentAssetLoader.d.ts +1 -1
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.d.ts +1 -1
- package/lib/lens/assets/staticAssetLoader.d.ts +1 -1
- package/lib/lens-core-module/generated-types.d.ts +29 -29
- package/lib/lens-core-module/loader/lensCoreFactory.d.ts +1 -1
- package/lib/lensCoreWasmVersions.json +3 -3
- package/lib/logger/logger.d.ts +2 -2
- package/lib/media-sources/CameraKitSource.d.ts +3 -3
- package/lib/media-sources/CameraKitSource.js.map +1 -1
- package/lib/media-sources/FunctionSource.d.ts +1 -1
- package/lib/media-sources/MediaStreamSource.js +25 -5
- package/lib/media-sources/MediaStreamSource.js.map +1 -1
- package/lib/metrics/businessEventsReporter.d.ts +4 -4
- package/lib/metrics/businessEventsReporter.js.map +1 -1
- package/lib/metrics/metricsEventTarget.d.ts +5 -5
- package/lib/metrics/metricsHandler.d.ts +1 -1
- package/lib/metrics/operationalMetricsReporter.d.ts +2 -2
- package/lib/metrics/reporters/reportBenchmarks.d.ts +1 -1
- package/lib/metrics/reporters/reportLegalState.d.ts +1 -1
- package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +4 -4
- package/lib/metrics/reporters/reportLensValidationFailed.d.ts +1 -1
- package/lib/metrics/reporters/reportLensView.d.ts +1 -1
- package/lib/metrics/reporters/reportLensView.js +1 -1
- package/lib/metrics/reporters/reportLensView.js.map +1 -1
- package/lib/metrics/reporters/reportLensWait.d.ts +1 -1
- package/lib/metrics/reporters/reportUserSession.d.ts +1 -1
- package/lib/metrics/reporters/reporters.d.ts +2 -2
- package/lib/namedErrors.d.ts +17 -17
- package/lib/persistence/Persistence.d.ts +1 -1
- package/lib/remote-configuration/cofHandler.d.ts +4 -2
- package/lib/remote-configuration/cofHandler.js +10 -5
- package/lib/remote-configuration/cofHandler.js.map +1 -1
- package/lib/remote-configuration/remoteConfiguration.d.ts +4 -3
- package/lib/remote-configuration/remoteConfiguration.js +5 -4
- package/lib/remote-configuration/remoteConfiguration.js.map +1 -1
- package/lib/session/CameraKitSession.d.ts +1 -1
- package/lib/session/CameraKitSession.js.map +1 -1
- package/lib/session/CameraKitSessionEvents.d.ts +3 -3
- package/lib/session/LensKeyboard.d.ts +2 -2
- package/lib/session/LensPerformanceMetrics.js.map +1 -1
- package/lib/session/lensState.d.ts +2 -2
- package/lib/session/lensState.js.map +1 -1
- package/lib/session/sessionState.d.ts +1 -1
- package/lib/transforms/Transform2D.js +2 -1
- package/lib/transforms/Transform2D.js.map +1 -1
- package/package.json +14 -14
- package/docs/html/assets/widgets.png +0 -0
- package/docs/html/assets/widgets@2x.png +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensRepository.js","sourceRoot":"","sources":["../../src/lens/LensRepository.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,mCAAmC,EAAE,MAAM,iDAAiD,CAAC;AACtG,OAAO,EAAE,0BAA0B,EAAgB,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EAAe,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAE5F,OAAO,EAAW,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAAE,mCAAmC,EAAE,MAAM,iDAAiD,CAAC;AACtG,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAmB,YAAY,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAuB,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE/F,MAAM,MAAM,GAAG,SAAS,CAAC,gB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AAgBK;IAFL,QAAQ;IACR,GAAG;IACkB,WAAA,KAAK,CAAC,iBAAiB,CAAC,CAAA;;;;oDAqB7C;AA2BK;IAFL,QAAQ;IACR,GAAG;IAEC,WAAA,KAAK,CAAC,WAAW,CAAC,CAAA;IAClB,WAAA,KAAK,CAAC,0BAA0B,CAAC,CAAA;;;;sDAgBrC;AAgDL;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAC3C,gBAAgB,EAChB;IACI,mCAAmC,CAAC,KAAK;IACzC,0BAA0B,CAAC,KAAK;IAChC,kBAAkB,CAAC,KAAK;IACxB,0BAA0B,CAAC,KAAK;CAC1B,EACV,CACI,wBAAsC,EACtC,mBAAiC,EACjC,WAAwB,EACxB,mBAAwC,EAC1C,EAAE;IACA,MAAM,gBAAgB,GAAG,IAAI,mBAAmB,CAAC,mBAAmB,CAAC;SAChE,GAAG,CAAC,iCAAiC,EAA0B,CAAC;SAChE,GAAG,CAAC,+BAA+B,EAAE,CAAC,CAAC,OAAO,CAAC;IACpD,OAAO,IAAI,cAAc,CAAC,wBAAwB,EAAE,gBAAgB,EAAE,WAAW,EAAE,mBAAmB,CAAC,CAAC;AAC5G,CAAC,CACJ,CAAC","sourcesContent":["import { guard, validate } from \"../common/validate\";\nimport { isArrayOfType, isSafeString, isSafeStringArray, isString, isUndefined } from \"../common/typeguards\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { cameraKitServiceFetchHandlerFactory } from \"../handlers/cameraKitServiceFetchHandlerFactory\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { LensSources, lensSourcesFactory } from \"../extensions/LensSources\";\nimport { createRequestStateEmittingHandler } from \"../handlers/requestStateEmittingHandler\";\nimport { LensDownloadDimensions } from \"../metrics/reporters/reportLensAndAssetDownload\";\nimport { Handler, HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport { createArrayBufferParsingHandler } from \"../handlers/arrayBufferParsingHandler\";\nimport { LensAssetManifestItem_RequestTiming } from \"../generated-proto/pb_schema/camera_kit/v3/lens\";\nimport { getLogger } from \"../logger/logger\";\nimport { errorLoggingDecorator } from \"../logger/errorLoggingDecorator\";\nimport { isLensArray, Lens, LensProto, toPublicLens } from \"./Lens\";\nimport { retrieveCameraKitLens, retrieveCameraKitLensGroup } from \"./lensHttpUtil\";\nimport { decodeEnvelopes } from \"./lensEnvelopeUtil\";\nimport { LensAssetRepository, lensAssetRepositoryFactory } from \"./assets/LensAssetRepository\";\n\nconst logger = getLogger(\"LensRepository\");\nconst log = errorLoggingDecorator(logger);\n\ntype LensFetchHandler = Handler<\n [RequestInfo, LensDownloadDimensions],\n [ArrayBuffer, Response],\n RequestInit | undefined\n>;\n\nconst assetTimingMap = {\n required: LensAssetManifestItem_RequestTiming.REQUIRED,\n onDemand: LensAssetManifestItem_RequestTiming.ON_DEMAND,\n};\n\nfunction isAssetTiming(value: unknown): value is AssetTiming {\n return isString(value) && assetTimingMap.hasOwnProperty(value);\n}\n\nfunction isOptionalAssetTimingArray(value: unknown): value is undefined | AssetTiming[] {\n return isUndefined(value) || isArrayOfType(isAssetTiming, value);\n}\n\n/**\n * Lens assets are included in a manifest, and each will indicate when that asset will be used by the lens.\n *\n * Assets can have the following timing values:\n * - `required`: the lens will definitely request this asset immediately when the lens is applied.\n * - `onDemand`: the lens may request this asset at some time while the lens is applied.\n *\n * Depending on the use-case, an application may want to cache both required and onDemand assets for\n * a particular lens, or may decide to only cache required assets (or cache no assets).\n *\n * @category Lenses\n */\nexport type AssetTiming = keyof typeof assetTimingMap;\n\nexport interface LensGroupsQueryResponse {\n errors: Error[];\n lenses: Lens[];\n}\n\nexport interface LensBinary {\n lensBuffer: ArrayBuffer;\n lensChecksum: string;\n}\n\n/**\n * The LensRepository is used to query for lenses from specific lens groups, or for a lens with a specific ID.\n *\n * Lens groups are configured in the CameraKit Portal -- that's where you'll find lens group IDs and lens IDs.\n *\n * Lenses must be loaded by the LensRepository before they can be applied to a {@link CameraKitSession}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(options)\n * const session = await cameraKit.createSession()\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * session.applyLens(lens)\n * ```\n *\n * @category Lenses\n */\nexport class LensRepository {\n private readonly metadataCache = new Map<string, LensProto>();\n private readonly binariesCache = new Map<string, ArrayBuffer>();\n\n /** @internal */\n constructor(\n private readonly lensMetadataFetchHandler: FetchHandler,\n private readonly lensFetchHandler: LensFetchHandler,\n private readonly lensSources: LensSources,\n private readonly lensAssetRepository: LensAssetRepository\n ) {}\n\n /**\n * Retrieve a single Lens.\n *\n * @param lensId Desired Lens's unique ID. Can be found in the CameraKit Portal.\n * @param groupId The ID of a group containing the desired Lens. Can be found in the CameraKit Portal.\n * @returns Resolves with the desired Lens, or rejects if an error occurred (including a missing Lens).\n */\n @validate\n @log\n async loadLens(@guard(isSafeString) lensId: string, @guard(isSafeString) groupId: string): Promise<Lens> {\n const envelopes = await this.lensSources.retrieveLenses({ lensId, groupId });\n let lens: LensProto;\n if (envelopes) {\n lens = decodeEnvelopes(envelopes)[0];\n if (!lens) {\n throw new Error(\"Expected non-empty envelope\");\n }\n } else {\n lens = await retrieveCameraKitLens(this.lensMetadataFetchHandler, lensId, groupId);\n }\n this.metadataCache.set(lens.id, lens);\n return toPublicLens(lens);\n }\n\n /**\n * Retrieve the Lenses contained in a list of Lens Groups.\n *\n * This may result in multiple requests to retrieve Lens data (e.g. one per desired group). If any constituent\n * requests fail, those errors will be reported in the response – but the returned Promise will not be rejected. Any\n * Lenses which could be successfully retrieved will be available in the response.\n *\n * @param groupIds A list of Lens Group IDs. Can be found in the CameraKit Portal.\n * @returns Resolves with a flattened list of all lenses in the desired groups. If any errors occurred during the\n * query operation, these will be included in a separate list. If errors are present, the list of Lenses may not\n * contain all the Lenses from the desired groups.\n */\n @validate\n @log\n async loadLensGroups(@guard(isSafeStringArray) groupIds: string[]): Promise<LensGroupsQueryResponse> {\n const responses = await Promise.all(\n groupIds.map(async (groupId) => {\n try {\n const envelopes = await this.lensSources.retrieveLenses({ groupId });\n const lenses = envelopes\n ? decodeEnvelopes(envelopes)\n : await retrieveCameraKitLensGroup(this.lensMetadataFetchHandler, groupId);\n lenses.forEach((lens) => this.metadataCache.set(lens.id, lens));\n return lenses.map(toPublicLens);\n } catch (error) {\n logger.error(new Error(`Failed to load lens group ${groupId}`, { cause: error }));\n return error as Error;\n }\n })\n );\n\n const errors: Error[] = [];\n const lenses: Lens[] = [];\n responses.forEach((response) => (Array.isArray(response) ? lenses.push(...response) : errors.push(response)));\n return { errors, lenses };\n }\n\n /**\n * Loads and caches lens content and dependencies to reduce latency when {@link CameraKitSession.applyLens} is later\n * called to apply the lens. This is an in-memory cache, it will not be persisted across page loads.\n *\n * This may useful if the application A) knows which lenses will be applied and B) has some opportunity to call\n * this method before a lens is applied. For example, if the user must perform some other actions before lenses\n * become active, this might be a good opportunity to cache lenses to improve applyLens latency.\n *\n * @example\n * ```ts\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * await cameraKit.lensRepository.cacheLensContent([lens])\n *\n * // sometime later -- this call will use the cached lens content, making lens application faster.\n * await cameraKitSession.applyLens(lens)\n * ```\n *\n * @param lenses Array of lenses to cache in memory.\n * @param assetTimingsToCache Lenses specify certain required assets that are necessary for the lens to render, and\n * other assets which may be needed by the lens. By default this method will cache all of those assets, but this\n * behavior can be modified to only load the required assets, only the \"onDemand\" assets, or neither (by passing\n * an empty array).\n */\n @validate\n @log\n async cacheLensContent(\n @guard(isLensArray) lenses: Lens[],\n @guard(isOptionalAssetTimingArray) assetTimingsToCache: AssetTiming[] = [\"required\", \"onDemand\"]\n ) {\n const assetTimingsToLoad = assetTimingsToCache.map((timing) => assetTimingMap[timing]);\n await Promise.all(\n lenses.map(async (lens) => {\n try {\n const { lensBuffer } = await this.getLensContent(lens);\n // Safety: getLensContent() call above ensures metadata to exist\n const { content } = this.metadataCache.get(lens.id)!;\n this.binariesCache.set(lens.id, lensBuffer);\n await this.lensAssetRepository.cacheAssets(content!.assetManifest, lens, assetTimingsToLoad);\n } catch (e) {\n logger.warn(new Error(`Failed to cache lens ${lens.id}.`, { cause: e }));\n }\n })\n );\n }\n\n /**\n * Returns loaded Lens metadata if available.\n */\n getLensMetadata(lensId: string): LensProto | undefined {\n return this.metadataCache.get(lensId);\n }\n\n /**\n * Removes Lens content from the in-memory cache.\n */\n removeCachedLenses(lenses: Lens[]) {\n lenses.forEach((lens) => this.binariesCache.delete(lens.id));\n }\n\n /**\n * Fetches lens content and assets. This may come from the cache, otherwise network requests will be made.\n *\n * @internal\n */\n async getLensContent(lens: Lens): Promise<LensBinary> {\n const { content } = this.metadataCache.get(lens.id) ?? {};\n if (!content) {\n throw new Error(`Cannot find metadata for lens ${lens.id}.`);\n }\n\n const cachedLensBuffer = this.binariesCache.get(lens.id);\n if (cachedLensBuffer) {\n return {\n lensBuffer: cachedLensBuffer,\n lensChecksum: content.lnsSha256,\n };\n }\n\n // Load required lens assets and the lens itself in parallel. We count both toward lens download time.\n const [lensBuffer] = await this.lensFetchHandler([\n // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed\n new Request(content.lnsUrlBolt, { cache: \"force-cache\" }),\n {\n requestType: \"lens_content\",\n lensId: lens.id,\n },\n ]);\n return { lensBuffer, lensChecksum: content.lnsSha256 };\n }\n}\n\n/**\n * @internal\n */\nexport const lensRepositoryFactory = Injectable(\n \"LensRepository\",\n [\n cameraKitServiceFetchHandlerFactory.token,\n defaultFetchHandlerFactory.token,\n lensSourcesFactory.token,\n lensAssetRepositoryFactory.token,\n ] as const,\n (\n lensMetadataFetchHandler: FetchHandler,\n defaultFetchHandler: FetchHandler,\n lensSources: LensSources,\n lensAssetRepository: LensAssetRepository\n ) => {\n const lensFetchHandler = new HandlerChainBuilder(defaultFetchHandler)\n .map(createRequestStateEmittingHandler<LensDownloadDimensions>())\n .map(createArrayBufferParsingHandler()).handler;\n return new LensRepository(lensMetadataFetchHandler, lensFetchHandler, lensSources, lensAssetRepository);\n }\n);\n"]}
|
|
1
|
+
{"version":3,"file":"LensRepository.js","sourceRoot":"","sources":["../../src/lens/LensRepository.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,mCAAmC,EAAE,MAAM,iDAAiD,CAAC;AACtG,OAAO,EAAE,0BAA0B,EAAgB,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EAAe,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAE5F,OAAO,EAAW,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAAE,mCAAmC,EAAE,MAAM,iDAAiD,CAAC;AACtG,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAmB,YAAY,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAuB,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE/F,MAAM,MAAM,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;AAC3C,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAQ1C,MAAM,cAAc,GAAG;IACnB,QAAQ,EAA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;IAEC,WAAA,KAAK,CAAC,WAAW,CAAC,CAAA;IAClB,WAAA,KAAK,CAAC,0BAA0B,CAAC,CAAA;;;;sDAgBrC;AAgDL;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAC3C,gBAAgB,EAChB;IACI,mCAAmC,CAAC,KAAK;IACzC,0BAA0B,CAAC,KAAK;IAChC,kBAAkB,CAAC,KAAK;IACxB,0BAA0B,CAAC,KAAK;CAC1B,EACV,CACI,wBAAsC,EACtC,mBAAiC,EACjC,WAAwB,EACxB,mBAAwC,EAC1C,EAAE;IACA,MAAM,gBAAgB,GAAG,IAAI,mBAAmB,CAAC,mBAAmB,CAAC;SAChE,GAAG,CAAC,iCAAiC,EAA0B,CAAC;SAChE,GAAG,CAAC,+BAA+B,EAAE,CAAC,CAAC,OAAO,CAAC;IACpD,OAAO,IAAI,cAAc,CAAC,wBAAwB,EAAE,gBAAgB,EAAE,WAAW,EAAE,mBAAmB,CAAC,CAAC;AAC5G,CAAC,CACJ,CAAC","sourcesContent":["import { guard, validate } from \"../common/validate\";\nimport { isArrayOfType, isSafeString, isSafeStringArray, isString, isUndefined } from \"../common/typeguards\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { cameraKitServiceFetchHandlerFactory } from \"../handlers/cameraKitServiceFetchHandlerFactory\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { LensSources, lensSourcesFactory } from \"../extensions/LensSources\";\nimport { createRequestStateEmittingHandler } from \"../handlers/requestStateEmittingHandler\";\nimport { LensDownloadDimensions } from \"../metrics/reporters/reportLensAndAssetDownload\";\nimport { Handler, HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport { createArrayBufferParsingHandler } from \"../handlers/arrayBufferParsingHandler\";\nimport { LensAssetManifestItem_RequestTiming } from \"../generated-proto/pb_schema/camera_kit/v3/lens\";\nimport { getLogger } from \"../logger/logger\";\nimport { errorLoggingDecorator } from \"../logger/errorLoggingDecorator\";\nimport { isLensArray, Lens, LensProto, toPublicLens } from \"./Lens\";\nimport { retrieveCameraKitLens, retrieveCameraKitLensGroup } from \"./lensHttpUtil\";\nimport { decodeEnvelopes } from \"./lensEnvelopeUtil\";\nimport { LensAssetRepository, lensAssetRepositoryFactory } from \"./assets/LensAssetRepository\";\n\nconst logger = getLogger(\"LensRepository\");\nconst log = errorLoggingDecorator(logger);\n\ntype LensFetchHandler = Handler<\n [RequestInfo, LensDownloadDimensions],\n [ArrayBuffer, Response],\n RequestInit | undefined\n>;\n\nconst assetTimingMap = {\n required: LensAssetManifestItem_RequestTiming.REQUIRED,\n onDemand: LensAssetManifestItem_RequestTiming.ON_DEMAND,\n};\n\nfunction isAssetTiming(value: unknown): value is AssetTiming {\n return isString(value) && assetTimingMap.hasOwnProperty(value);\n}\n\nfunction isOptionalAssetTimingArray(value: unknown): value is undefined | AssetTiming[] {\n return isUndefined(value) || isArrayOfType(isAssetTiming, value);\n}\n\n/**\n * Lens assets are included in a manifest, and each will indicate when that asset will be used by the lens.\n *\n * Assets can have the following timing values:\n * - `required`: the lens will definitely request this asset immediately when the lens is applied.\n * - `onDemand`: the lens may request this asset at some time while the lens is applied.\n *\n * Depending on the use-case, an application may want to cache both required and onDemand assets for\n * a particular lens, or may decide to only cache required assets (or cache no assets).\n *\n * @category Lenses\n */\nexport type AssetTiming = keyof typeof assetTimingMap;\n\nexport interface LensBinary {\n lensBuffer: ArrayBuffer;\n lensChecksum: string;\n}\n\n/**\n * The LensRepository is used to query for lenses from specific lens groups, or for a lens with a specific ID.\n *\n * Lens groups are configured in the CameraKit Portal -- that's where you'll find lens group IDs and lens IDs.\n *\n * Lenses must be loaded by the LensRepository before they can be applied to a {@link CameraKitSession}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(options)\n * const session = await cameraKit.createSession()\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * session.applyLens(lens)\n * ```\n *\n * @category Lenses\n */\nexport class LensRepository {\n private readonly metadataCache = new Map<string, LensProto>();\n private readonly binariesCache = new Map<string, ArrayBuffer>();\n\n /** @internal */\n constructor(\n private readonly lensMetadataFetchHandler: FetchHandler,\n private readonly lensFetchHandler: LensFetchHandler,\n private readonly lensSources: LensSources,\n private readonly lensAssetRepository: LensAssetRepository\n ) {}\n\n /**\n * Retrieve a single Lens.\n *\n * @param lensId Desired Lens's unique ID. Can be found in the CameraKit Portal.\n * @param groupId The ID of a group containing the desired Lens. Can be found in the CameraKit Portal.\n * @returns Resolves with the desired Lens, or rejects if an error occurred (including a missing Lens).\n */\n @validate\n @log\n async loadLens(@guard(isSafeString) lensId: string, @guard(isSafeString) groupId: string): Promise<Lens> {\n const envelopes = await this.lensSources.retrieveLenses({ lensId, groupId });\n let lens: LensProto;\n if (envelopes) {\n lens = decodeEnvelopes(envelopes)[0];\n if (!lens) {\n throw new Error(\"Expected non-empty envelope\");\n }\n } else {\n lens = await retrieveCameraKitLens(this.lensMetadataFetchHandler, lensId, groupId);\n }\n this.metadataCache.set(lens.id, lens);\n return toPublicLens(lens);\n }\n\n /**\n * Retrieve the Lenses contained in a list of Lens Groups.\n *\n * This may result in multiple requests to retrieve Lens data (e.g. one per desired group). If any constituent\n * requests fail, those errors will be reported in the response – but the returned Promise will not be rejected. Any\n * Lenses which could be successfully retrieved will be available in the response.\n *\n * @param groupIds A list of Lens Group IDs. Can be found in the CameraKit Portal.\n * @returns Resolves with a flattened list of all lenses in the desired groups. If any errors occurred during the\n * query operation, these will be included in a separate list. If errors are present, the list of Lenses may not\n * contain all the Lenses from the desired groups.\n */\n @validate\n @log\n async loadLensGroups(@guard(isSafeStringArray) groupIds: string[]): Promise<{\n errors: Error[];\n lenses: Lens[];\n }> {\n const responses = await Promise.all(\n groupIds.map(async (groupId) => {\n try {\n const envelopes = await this.lensSources.retrieveLenses({ groupId });\n const lenses = envelopes\n ? decodeEnvelopes(envelopes)\n : await retrieveCameraKitLensGroup(this.lensMetadataFetchHandler, groupId);\n lenses.forEach((lens) => this.metadataCache.set(lens.id, lens));\n return lenses.map(toPublicLens);\n } catch (error) {\n logger.error(new Error(`Failed to load lens group ${groupId}`, { cause: error }));\n return error as Error;\n }\n })\n );\n\n const errors: Error[] = [];\n const lenses: Lens[] = [];\n responses.forEach((response) => (Array.isArray(response) ? lenses.push(...response) : errors.push(response)));\n return { errors, lenses };\n }\n\n /**\n * Loads and caches lens content and dependencies to reduce latency when {@link CameraKitSession.applyLens} is later\n * called to apply the lens. This is an in-memory cache, it will not be persisted across page loads.\n *\n * This may useful if the application A) knows which lenses will be applied and B) has some opportunity to call\n * this method before a lens is applied. For example, if the user must perform some other actions before lenses\n * become active, this might be a good opportunity to cache lenses to improve applyLens latency.\n *\n * @example\n * ```ts\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * await cameraKit.lensRepository.cacheLensContent([lens])\n *\n * // sometime later -- this call will use the cached lens content, making lens application faster.\n * await cameraKitSession.applyLens(lens)\n * ```\n *\n * @param lenses Array of lenses to cache in memory.\n * @param assetTimingsToCache Lenses specify certain required assets that are necessary for the lens to render, and\n * other assets which may be needed by the lens. By default this method will cache all of those assets, but this\n * behavior can be modified to only load the required assets, only the \"onDemand\" assets, or neither (by passing\n * an empty array).\n */\n @validate\n @log\n async cacheLensContent(\n @guard(isLensArray) lenses: Lens[],\n @guard(isOptionalAssetTimingArray) assetTimingsToCache: AssetTiming[] = [\"required\", \"onDemand\"]\n ) {\n const assetTimingsToLoad = assetTimingsToCache.map((timing) => assetTimingMap[timing]);\n await Promise.all(\n lenses.map(async (lens) => {\n try {\n const { lensBuffer } = await this.getLensContent(lens);\n // Safety: getLensContent() call above ensures metadata to exist\n const { content } = this.metadataCache.get(lens.id)!;\n this.binariesCache.set(lens.id, lensBuffer);\n await this.lensAssetRepository.cacheAssets(content!.assetManifest, lens, assetTimingsToLoad);\n } catch (e) {\n logger.warn(new Error(`Failed to cache lens ${lens.id}.`, { cause: e }));\n }\n })\n );\n }\n\n /**\n * Returns loaded Lens metadata if available.\n */\n getLensMetadata(lensId: string): LensProto | undefined {\n return this.metadataCache.get(lensId);\n }\n\n /**\n * Removes Lens content from the in-memory cache.\n */\n removeCachedLenses(lenses: Lens[]) {\n lenses.forEach((lens) => this.binariesCache.delete(lens.id));\n }\n\n /**\n * Fetches lens content and assets. This may come from the cache, otherwise network requests will be made.\n *\n * @internal\n */\n async getLensContent(lens: Lens): Promise<LensBinary> {\n const { content } = this.metadataCache.get(lens.id) ?? {};\n if (!content) {\n throw new Error(`Cannot find metadata for lens ${lens.id}.`);\n }\n\n const cachedLensBuffer = this.binariesCache.get(lens.id);\n if (cachedLensBuffer) {\n return {\n lensBuffer: cachedLensBuffer,\n lensChecksum: content.lnsSha256,\n };\n }\n\n // Load required lens assets and the lens itself in parallel. We count both toward lens download time.\n const [lensBuffer] = await this.lensFetchHandler([\n // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed\n new Request(content.lnsUrlBolt, { cache: \"force-cache\" }),\n {\n requestType: \"lens_content\",\n lensId: lens.id,\n },\n ]);\n return { lensBuffer, lensChecksum: content.lnsSha256 };\n }\n}\n\n/**\n * @internal\n */\nexport const lensRepositoryFactory = Injectable(\n \"LensRepository\",\n [\n cameraKitServiceFetchHandlerFactory.token,\n defaultFetchHandlerFactory.token,\n lensSourcesFactory.token,\n lensAssetRepositoryFactory.token,\n ] as const,\n (\n lensMetadataFetchHandler: FetchHandler,\n defaultFetchHandler: FetchHandler,\n lensSources: LensSources,\n lensAssetRepository: LensAssetRepository\n ) => {\n const lensFetchHandler = new HandlerChainBuilder(defaultFetchHandler)\n .map(createRequestStateEmittingHandler<LensDownloadDimensions>())\n .map(createArrayBufferParsingHandler()).handler;\n return new LensRepository(lensMetadataFetchHandler, lensFetchHandler, lensSources, lensAssetRepository);\n }\n);\n"]}
|
|
@@ -9,7 +9,7 @@ export interface Asset {
|
|
|
9
9
|
assetType: AssetType;
|
|
10
10
|
assetChecksum: string | undefined;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
12
|
+
export type AssetResponse = ArrayBuffer | {
|
|
13
13
|
data: ArrayBuffer;
|
|
14
14
|
checksum?: string;
|
|
15
15
|
};
|
|
@@ -18,7 +18,7 @@ export declare type AssetResponse = ArrayBuffer | {
|
|
|
18
18
|
*
|
|
19
19
|
* @category Lenses
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
21
|
+
export type AssetLoader = (asset: AssetDescriptor, lens?: Lens, assetManifest?: LensAssetManifestItem[]) => Promise<AssetResponse> | AssetResponse;
|
|
22
22
|
/**
|
|
23
23
|
* Registers a remote asset provider function with a given instance of LensCore, and uses a provided mapping of asset
|
|
24
24
|
* types to loading functions to acquire remote asset data and pass it to LensCore.
|
|
@@ -5,7 +5,7 @@ import { LensAssetRepository } from "./LensAssetRepository";
|
|
|
5
5
|
/**
|
|
6
6
|
* The AssetValidationFailed metric reports every time we handle an asset checksum validation failure.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export type AssetValidationFailed = MakeTaggedBusinessEvent<"assetValidationFailed">;
|
|
9
9
|
/**
|
|
10
10
|
* Registers a remote asset provider function with a given instance of LensCore.
|
|
11
11
|
*
|
|
@@ -5,7 +5,7 @@ import { AssetLoader } from "./LensAssetRepository";
|
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
7
|
export declare const deviceDependentAssetLoaderFactory: {
|
|
8
|
-
(args_0: FetchHandler
|
|
8
|
+
(args_0: FetchHandler, args_1: RemoteConfiguration): AssetLoader;
|
|
9
9
|
token: "deviceDependentAssetLoader";
|
|
10
10
|
dependencies: readonly ["defaultFetchHandler", "remoteConfiguration"];
|
|
11
11
|
};
|
|
@@ -4,7 +4,7 @@ import { AssetLoader } from "./LensAssetRepository";
|
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export declare const remoteMediaAssetLoaderFactory: {
|
|
7
|
-
(args_0: FetchHandler
|
|
7
|
+
(args_0: FetchHandler): AssetLoader;
|
|
8
8
|
token: "remoteMediaAssetLoader";
|
|
9
9
|
dependencies: readonly ["defaultFetchHandler"];
|
|
10
10
|
};
|
|
@@ -4,7 +4,7 @@ import { AssetLoader } from "./LensAssetRepository";
|
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export declare const staticAssetLoaderFactory: {
|
|
7
|
-
(args_0: FetchHandler
|
|
7
|
+
(args_0: FetchHandler): AssetLoader;
|
|
8
8
|
token: "staticAssetLoader";
|
|
9
9
|
dependencies: readonly ["defaultFetchHandler"];
|
|
10
10
|
};
|
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
/// <reference types="dom-webcodecs" />
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export type DefaultEventHandler = (...data: any[]) => void;
|
|
3
|
+
export type DefaultErrorHandler = (err: LensCoreError) => void;
|
|
4
|
+
export type LensCoreEnumValue = {
|
|
5
5
|
value: number;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export
|
|
26
|
-
export
|
|
7
|
+
export type GetOutputCanvasesOutput = Record<number, HTMLCanvasElement>;
|
|
8
|
+
export type SetRenderSizeInput = SetRenderSizeMatchInputResolutionInput | SetRenderSizeExplicitInput;
|
|
9
|
+
export type SetRemoteAssetsProviderInput = (assetDescriptor: AssetDescriptor) => void;
|
|
10
|
+
export type ContentType = "text/plain" | "text/html" | "application/json" | "application/octet-stream" | "application/x-protobuf" | "application/grpc";
|
|
11
|
+
export type SavePersistentStoreCallback = (id: string, data: ArrayBuffer) => void;
|
|
12
|
+
export type ShowHintCallback = (effectId: string, hintId: string) => void;
|
|
13
|
+
export type HideHintCallback = (effectId: string) => void;
|
|
14
|
+
export type ReceiveInstanceCallback = (instance: WebAssembly.Instance, module: WebAssembly.Module) => void;
|
|
15
|
+
export type AssetType = LensCoreEnumValue;
|
|
16
|
+
export type CanvasType = LensCoreEnumValue;
|
|
17
|
+
export type RenderLoopMode = LensCoreEnumValue;
|
|
18
|
+
export type LensApiVisibility = LensCoreEnumValue;
|
|
19
|
+
export type DeviceClass = LensCoreEnumValue;
|
|
20
|
+
export type UserDataAccess = LensCoreEnumValue;
|
|
21
|
+
export type InterfaceControl = LensCoreEnumValue;
|
|
22
|
+
export type InterfaceAction = LensCoreEnumValue;
|
|
23
|
+
export type ExternalMediaOrientation = LensCoreEnumValue;
|
|
24
|
+
export type ErrorType = LensCoreEnumValue;
|
|
25
|
+
export type Uri = `${string}://${string}`;
|
|
26
|
+
export type Dimensions = {
|
|
27
27
|
width: number;
|
|
28
28
|
height: number;
|
|
29
29
|
};
|
|
30
|
-
export
|
|
30
|
+
export type Size2D = {
|
|
31
31
|
width: number;
|
|
32
32
|
height: number;
|
|
33
33
|
};
|
|
34
|
-
export
|
|
34
|
+
export type Vec2D = {
|
|
35
35
|
x: number;
|
|
36
36
|
y: number;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export type Rect = {
|
|
39
39
|
origin: Vec2D;
|
|
40
40
|
size: Size2D;
|
|
41
41
|
};
|
|
@@ -238,7 +238,7 @@ export interface ScreenDimmingRequestInput {
|
|
|
238
238
|
effectId: string;
|
|
239
239
|
enabled: boolean;
|
|
240
240
|
}
|
|
241
|
-
export
|
|
241
|
+
export type ScreenDimmingRequestHandler = (config: ScreenDimmingRequestInput) => void;
|
|
242
242
|
export interface ClientInterfaceData {
|
|
243
243
|
HeaderId?: string;
|
|
244
244
|
DescriptionId?: string;
|
|
@@ -253,7 +253,7 @@ export interface ClientInterfaceRequestInput {
|
|
|
253
253
|
interfaceAction: InterfaceAction;
|
|
254
254
|
data: ClientInterfaceData;
|
|
255
255
|
}
|
|
256
|
-
export
|
|
256
|
+
export type ClientInterfaceRequestHandler = (config: ClientInterfaceRequestInput) => void;
|
|
257
257
|
export interface LensCoreConfig {
|
|
258
258
|
configId: string;
|
|
259
259
|
value: {
|
|
@@ -273,7 +273,7 @@ export interface LensCoreConfig {
|
|
|
273
273
|
};
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
|
-
export
|
|
276
|
+
export type SetPreloadedConfigurationInput = Array<LensCoreConfig>;
|
|
277
277
|
export interface SetAllSoundsMutedInput {
|
|
278
278
|
muted: boolean;
|
|
279
279
|
fade: boolean;
|
|
@@ -24,7 +24,7 @@ export declare function getRequiredBootstrapURLs(endpointOverride?: string): Pro
|
|
|
24
24
|
* @internal
|
|
25
25
|
*/
|
|
26
26
|
export declare const lensCoreFactory: {
|
|
27
|
-
(args_0: FetchHandler
|
|
27
|
+
(args_0: FetchHandler, args_1: CameraKitConfiguration): Promise<InitialEmscriptenModule & LensCoreModule>;
|
|
28
28
|
token: "lensCore";
|
|
29
29
|
dependencies: readonly ["defaultFetchHandler", "configuration"];
|
|
30
30
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
3
|
-
"buildNumber": "
|
|
4
|
-
"baseUrl": "https://cf-st.sc-cdn.net/d/
|
|
2
|
+
"version": "209",
|
|
3
|
+
"buildNumber": "8",
|
|
4
|
+
"baseUrl": "https://cf-st.sc-cdn.net/d/MkroAjRWoH1TVgTCn9VZV?go=IgsKCTIBBEgBUFxgAQ%3D%3D&uc=92"
|
|
5
5
|
}
|
package/lib/logger/logger.d.ts
CHANGED
|
@@ -22,8 +22,8 @@ export interface LogEntry {
|
|
|
22
22
|
level: keyof Logger;
|
|
23
23
|
messages: any[];
|
|
24
24
|
}
|
|
25
|
-
export
|
|
26
|
-
export
|
|
25
|
+
export type LogLevelName = keyof typeof logLevelMap;
|
|
26
|
+
export type Logger = Record<LogLevelName, (message?: any, ...optionalParams: any[]) => void>;
|
|
27
27
|
/**
|
|
28
28
|
* Gets logger for a given module.
|
|
29
29
|
*
|
|
@@ -11,13 +11,13 @@ export interface CameraKitSourceSubscriber {
|
|
|
11
11
|
readonly onDetach?: (reportError: (error: Error) => void) => void | Promise<void>;
|
|
12
12
|
}
|
|
13
13
|
/** @category Rendering */
|
|
14
|
-
export
|
|
14
|
+
export type CameraKitDeviceInfo = {
|
|
15
15
|
cameraType: "front" | "back";
|
|
16
16
|
fpsLimit: number;
|
|
17
17
|
};
|
|
18
|
-
export
|
|
18
|
+
export type CameraKitSourceInfo = Pick<UseMediaElementInput, "media" | "replayTrackingData" | "useManualFrameProcessing">;
|
|
19
19
|
/** @category Rendering */
|
|
20
|
-
export
|
|
20
|
+
export type CameraKitSourceOptions<T = {}> = Partial<T> & Partial<CameraKitDeviceInfo>;
|
|
21
21
|
/**
|
|
22
22
|
* This general-purpose class represents a source of media for a {@link CameraKitSession}.
|
|
23
23
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CameraKitSource.js","sourceRoot":"","sources":["../../src/media-sources/CameraKitSource.ts"],"names":[],"mappings":"AAAA,uDAAuD;;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,iBAAiB,GAAwB;IAC3C,UAAU,EAAE,OAAO;IACnB,QAAQ,EAAE,MAAM,CAAC,iBAAiB;CACrC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,OAAe,EAAE,EAAE,CAC/C,IAAI,KAAK,CAAC,GAAG,OAAO,+DAA+D,CAAC,CAAC;AA+BzF;;;;;;;;;;GAUG;AACH,MAAM,OAAO,eAAe;IAIxB,YACqB,UAA+B,EAC/B,aAAwC,EAAE,EAC3D,aAA2C,EAAE;QAF5B,eAAU,GAAV,UAAU,CAAqB;QAC/B,eAAU,GAAV,UAAU,CAAgC;QAG3D,IAAI,C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AAM,CAAC,CAAC;YAClD,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAtBG;IAAC,QAAQ;;;;oDAOR;AAOD;IAAC,QAAQ;;qCACe,WAAW;;mDAMlC","sourcesContent":["/* eslint-disable @typescript-eslint/member-ordering */\n\nimport { validate } from \"../common/validate\";\nimport { LensCoreModule, UseMediaElementInput } from \"../lens-core-module/generated-types\";\nimport { Transform2D } from \"../transforms\";\n\nconst defaultDeviceInfo: CameraKitDeviceInfo = {\n cameraType: \"front\",\n fpsLimit: Number.POSITIVE_INFINITY,\n};\n\nconst createNotAttachedError = (message: string) =>\n new Error(`${message}. This CameraKitSource is not attached to a CameraKitSession.`);\n\n/**\n * When creating a {@link CameraKitSource}, passing a CameraKitSourceSubscriber allows logic to implemented which will\n * run whenever that source is attached/detached from a CameraKitSession.\n *\n * @category Rendering\n */\nexport interface CameraKitSourceSubscriber {\n readonly onAttach?: (\n source: CameraKitSource,\n lensCore: LensCoreModule,\n reportError: (error: Error) => void\n ) => void | Promise<void>;\n readonly onDetach?: (reportError: (error: Error) => void) => void | Promise<void>;\n}\n\n/** @category Rendering */\nexport type CameraKitDeviceInfo = {\n cameraType: \"front\" | \"back\";\n fpsLimit: number;\n};\n\nexport type CameraKitSourceInfo = Pick<\n UseMediaElementInput,\n \"media\" | \"replayTrackingData\" | \"useManualFrameProcessing\"\n>;\n\n/** @category Rendering */\nexport type CameraKitSourceOptions<T = {}> = Partial<T> & Partial<CameraKitDeviceInfo>;\n\n/**\n * This general-purpose class represents a source of media for a {@link CameraKitSession}.\n *\n * When an instance is passed to {@link CameraKitSession.setSource | CameraKitSession.setSource}, it will be \"attached\"\n * to the session. Later it may be \"detached\" from the session.\n *\n * Passing a {@link CameraKitSourceSubscriber} to the constructor allows callers to specify behavior\n * that will occur when the source is attached and detached. This can be used to e.g. update the render size.\n *\n * @category Rendering\n */\nexport class CameraKitSource {\n private lensCore?: LensCoreModule;\n private readonly deviceInfo: CameraKitDeviceInfo;\n\n constructor(\n private readonly sourceInfo: CameraKitSourceInfo,\n private readonly subscriber: CameraKitSourceSubscriber = {},\n deviceInfo: Partial<CameraKitDeviceInfo> = {}\n ) {\n this.deviceInfo = { ...defaultDeviceInfo, ...deviceInfo };\n }\n\n /**\n * Called by {@link CameraKitSession} when this source is set as that session's source.\n *\n * @param lensCore\n * @param reportError Calling this function will report an error back to the session.\n * @returns Rejects if any calls to LensCore or CameraKitSource.subscriber.onAttach fail.\n * @internal\n */\n async attach(lensCore: LensCoreModule, reportError: (error: Error) => void): Promise<void> {\n if (this.lensCore) {\n throw new Error(\n \"Cannot attach. This CameraKitCustomSource has already been attached to \" +\n \"a CameraKitSession. To re-attach, create a copy of this CameraKitCustomSource.\"\n );\n }\n\n this.lensCore = lensCore;\n\n await new Promise((onSuccess, onFailure) => {\n lensCore.useMediaElement({\n autoplayNewMedia: false,\n autoplayPreviewCanvas: false,\n media: this.sourceInfo.media,\n pauseExistingMedia: false,\n replayTrackingData: this.sourceInfo.replayTrackingData,\n requestWebcam: false,\n startOnFrontCamera: this.deviceInfo.cameraType === \"front\",\n useManualFrameProcessing: this.sourceInfo.useManualFrameProcessing,\n onSuccess,\n onFailure,\n });\n });\n\n await new Promise<void>((onSuccess, onFailure) => {\n // LensCore uses 0 to remove the limit.\n const fps = this.deviceInfo.fpsLimit < Number.POSITIVE_INFINITY ? this.deviceInfo.fpsLimit : 0;\n lensCore.setFPSLimit({ fps, onSuccess, onFailure });\n });\n\n if (this.subscriber.onAttach) await this.subscriber.onAttach(this, lensCore, reportError);\n }\n\n /**\n * Make a copy of the source, sharing the same {@link CameraKitSourceSubscriber}.\n *\n * @param deviceInfo Optionally provide new device info for the copy (e.g. to change the camera type).\n * @returns The new {@link CameraKitSource}\n */\n copy(deviceInfo: Partial<CameraKitDeviceInfo> = {}): CameraKitSource {\n return new CameraKitSource(this.sourceInfo, this.subscriber, { ...this.deviceInfo, ...deviceInfo });\n }\n\n /**\n * Called by {@link CameraKitSession} when it must remove this source.\n *\n * @param reportError Calling this function will report an error back to the session.\n * @returns\n * @internal\n */\n detach(reportError: (error: Error) => void): void | Promise<void> {\n if (!this.lensCore) return Promise.reject(createNotAttachedError(\"Cannot detach\"));\n if (this.subscriber.onDetach) return this.subscriber.onDetach(reportError);\n }\n\n /**\n * Set the resolution used to render this source.\n *\n * It’s important to distinguish render size from display size. The size at which the output canvases are displayed\n * on a web page is determined by the CSS of the page. It is distinct from the size at which LensCore renders\n * Lenses. Performance is dominated by render size, while any display scaling can most often be thought of as free.\n *\n * If greater performance is required, a smaller render size may boost frame-rate. It does come at a cost, including\n * loss of accuracy in various tracking and computer-vision algorithms (since they'll be operating on fewer pixels).\n *\n * The size of the Live and Capture {@link RenderTarget} is always the same.\n *\n * @todo Currently it's only valid to call `setRenderSize` after `CameraKitSession.play` has been called. This\n * constraint should be removed, so callers don't have to understand the underlying LensCore state machine.\n *\n * @param width pixels\n * @param height pixels\n * @returns Promise resolves when the render size has been successfully updated.\n */\n @validate\n setRenderSize(width: number, height: number): Promise<void> {\n return new Promise((onSuccess, onFailure) => {\n if (!this.lensCore) return onFailure(createNotAttachedError(\"Cannot setRenderSize\"));\n const target = { width, height };\n this.lensCore.setRenderSize({ mode: \"explicit\", target, onSuccess, onFailure });\n });\n }\n\n /**\n * Apply a 2D transformation to the source (e.g. translation, rotation, scale).\n *\n * @param transform Specifies the 3x3 matrix describing the transformation.\n */\n @validate\n setTransform(transform: Transform2D): Promise<void> {\n return new Promise((onSuccess, onFailure) => {\n if (!this.lensCore) return onFailure(createNotAttachedError(\"Cannot setTransform\"));\n const matrix = new Float32Array(transform.matrix);\n this.lensCore.setInputTransform({ matrix, onSuccess, onFailure });\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CameraKitSource.js","sourceRoot":"","sources":["../../src/media-sources/CameraKitSource.ts"],"names":[],"mapp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,sBAAsB,CAAC,sBAAsB,CAAC,CAAC,CAAC;YACrF,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IAEH,YAAY,CAAC,SAAsB;QAC/B,OAAO,IAAI,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE;YACxC,IAAI,CAAC,IAAI,CAAC,QAAQ;gBAAE,OAAO,SAAS,CAAC,sBAAsB,CAAC,qBAAqB,CAAC,CAAC,CAAC;YACpF,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAClD,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AArBG;IADC,QAAQ;;;;oDAOR;AAQD;IADC,QAAQ;;qCACe,WAAW;;mDAMlC","sourcesContent":["/* eslint-disable @typescript-eslint/member-ordering */\n\nimport { validate } from \"../common/validate\";\nimport { LensCoreModule, UseMediaElementInput } from \"../lens-core-module/generated-types\";\nimport { Transform2D } from \"../transforms\";\n\nconst defaultDeviceInfo: CameraKitDeviceInfo = {\n cameraType: \"front\",\n fpsLimit: Number.POSITIVE_INFINITY,\n};\n\nconst createNotAttachedError = (message: string) =>\n new Error(`${message}. This CameraKitSource is not attached to a CameraKitSession.`);\n\n/**\n * When creating a {@link CameraKitSource}, passing a CameraKitSourceSubscriber allows logic to implemented which will\n * run whenever that source is attached/detached from a CameraKitSession.\n *\n * @category Rendering\n */\nexport interface CameraKitSourceSubscriber {\n readonly onAttach?: (\n source: CameraKitSource,\n lensCore: LensCoreModule,\n reportError: (error: Error) => void\n ) => void | Promise<void>;\n readonly onDetach?: (reportError: (error: Error) => void) => void | Promise<void>;\n}\n\n/** @category Rendering */\nexport type CameraKitDeviceInfo = {\n cameraType: \"front\" | \"back\";\n fpsLimit: number;\n};\n\nexport type CameraKitSourceInfo = Pick<\n UseMediaElementInput,\n \"media\" | \"replayTrackingData\" | \"useManualFrameProcessing\"\n>;\n\n/** @category Rendering */\nexport type CameraKitSourceOptions<T = {}> = Partial<T> & Partial<CameraKitDeviceInfo>;\n\n/**\n * This general-purpose class represents a source of media for a {@link CameraKitSession}.\n *\n * When an instance is passed to {@link CameraKitSession.setSource | CameraKitSession.setSource}, it will be \"attached\"\n * to the session. Later it may be \"detached\" from the session.\n *\n * Passing a {@link CameraKitSourceSubscriber} to the constructor allows callers to specify behavior\n * that will occur when the source is attached and detached. This can be used to e.g. update the render size.\n *\n * @category Rendering\n */\nexport class CameraKitSource {\n private lensCore?: LensCoreModule;\n private readonly deviceInfo: CameraKitDeviceInfo;\n\n constructor(\n private readonly sourceInfo: CameraKitSourceInfo,\n private readonly subscriber: CameraKitSourceSubscriber = {},\n deviceInfo: Partial<CameraKitDeviceInfo> = {}\n ) {\n this.deviceInfo = { ...defaultDeviceInfo, ...deviceInfo };\n }\n\n /**\n * Called by {@link CameraKitSession} when this source is set as that session's source.\n *\n * @param lensCore\n * @param reportError Calling this function will report an error back to the session.\n * @returns Rejects if any calls to LensCore or CameraKitSource.subscriber.onAttach fail.\n * @internal\n */\n async attach(lensCore: LensCoreModule, reportError: (error: Error) => void): Promise<void> {\n if (this.lensCore) {\n throw new Error(\n \"Cannot attach. This CameraKitCustomSource has already been attached to \" +\n \"a CameraKitSession. To re-attach, create a copy of this CameraKitCustomSource.\"\n );\n }\n\n this.lensCore = lensCore;\n\n await new Promise((onSuccess, onFailure) => {\n lensCore.useMediaElement({\n autoplayNewMedia: false,\n autoplayPreviewCanvas: false,\n media: this.sourceInfo.media,\n pauseExistingMedia: false,\n replayTrackingData: this.sourceInfo.replayTrackingData,\n requestWebcam: false,\n startOnFrontCamera: this.deviceInfo.cameraType === \"front\",\n useManualFrameProcessing: this.sourceInfo.useManualFrameProcessing,\n onSuccess,\n onFailure,\n });\n });\n\n await new Promise<void>((onSuccess, onFailure) => {\n // LensCore uses 0 to remove the limit.\n const fps = this.deviceInfo.fpsLimit < Number.POSITIVE_INFINITY ? this.deviceInfo.fpsLimit : 0;\n lensCore.setFPSLimit({ fps, onSuccess, onFailure });\n });\n\n if (this.subscriber.onAttach) await this.subscriber.onAttach(this, lensCore, reportError);\n }\n\n /**\n * Make a copy of the source, sharing the same {@link CameraKitSourceSubscriber}.\n *\n * @param deviceInfo Optionally provide new device info for the copy (e.g. to change the camera type).\n * @returns The new {@link CameraKitSource}\n */\n copy(deviceInfo: Partial<CameraKitDeviceInfo> = {}): CameraKitSource {\n return new CameraKitSource(this.sourceInfo, this.subscriber, { ...this.deviceInfo, ...deviceInfo });\n }\n\n /**\n * Called by {@link CameraKitSession} when it must remove this source.\n *\n * @param reportError Calling this function will report an error back to the session.\n * @returns\n * @internal\n */\n detach(reportError: (error: Error) => void): void | Promise<void> {\n if (!this.lensCore) return Promise.reject(createNotAttachedError(\"Cannot detach\"));\n if (this.subscriber.onDetach) return this.subscriber.onDetach(reportError);\n }\n\n /**\n * Set the resolution used to render this source.\n *\n * It’s important to distinguish render size from display size. The size at which the output canvases are displayed\n * on a web page is determined by the CSS of the page. It is distinct from the size at which LensCore renders\n * Lenses. Performance is dominated by render size, while any display scaling can most often be thought of as free.\n *\n * If greater performance is required, a smaller render size may boost frame-rate. It does come at a cost, including\n * loss of accuracy in various tracking and computer-vision algorithms (since they'll be operating on fewer pixels).\n *\n * The size of the Live and Capture {@link RenderTarget} is always the same.\n *\n * @todo Currently it's only valid to call `setRenderSize` after `CameraKitSession.play` has been called. This\n * constraint should be removed, so callers don't have to understand the underlying LensCore state machine.\n *\n * @param width pixels\n * @param height pixels\n * @returns Promise resolves when the render size has been successfully updated.\n */\n @validate\n setRenderSize(width: number, height: number): Promise<void> {\n return new Promise((onSuccess, onFailure) => {\n if (!this.lensCore) return onFailure(createNotAttachedError(\"Cannot setRenderSize\"));\n const target = { width, height };\n this.lensCore.setRenderSize({ mode: \"explicit\", target, onSuccess, onFailure });\n });\n }\n\n /**\n * Apply a 2D transformation to the source (e.g. translation, rotation, scale).\n *\n * @param transform Specifies the 3x3 matrix describing the transformation.\n */\n @validate\n setTransform(transform: Transform2D): Promise<void> {\n return new Promise((onSuccess, onFailure) => {\n if (!this.lensCore) return onFailure(createNotAttachedError(\"Cannot setTransform\"));\n const matrix = new Float32Array(transform.matrix);\n this.lensCore.setInputTransform({ matrix, onSuccess, onFailure });\n });\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CameraKitSource, CameraKitSourceOptions } from "./CameraKitSource";
|
|
2
2
|
/** @internal */
|
|
3
|
-
export
|
|
3
|
+
export type FrameFormat = "rgb" | "yuv" | "nv12";
|
|
4
4
|
/** @internal */
|
|
5
5
|
export interface FrameInput {
|
|
6
6
|
format?: FrameFormat;
|
|
@@ -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
|
|
@@ -51,6 +58,7 @@ export function createMediaStreamSource(stream, options = {}) {
|
|
|
51
58
|
const sampleRate = 44100;
|
|
52
59
|
let audioContext = undefined;
|
|
53
60
|
let audioSource = undefined;
|
|
61
|
+
let worklet = undefined;
|
|
54
62
|
let microphoneRecorderUrl;
|
|
55
63
|
if (enableSourceAudio) {
|
|
56
64
|
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_AudioWorklet
|
|
@@ -86,8 +94,16 @@ export function createMediaStreamSource(stream, options = {}) {
|
|
|
86
94
|
reportError(error);
|
|
87
95
|
},
|
|
88
96
|
});
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
try {
|
|
98
|
+
// There is a possibility of the onAttach method being called twice in a row due to a bug.
|
|
99
|
+
// To ensure there are not leaks, it is better to close any existing connections.
|
|
100
|
+
closeWorklet(worklet);
|
|
101
|
+
audioSource === null || audioSource === void 0 ? void 0 : audioSource.disconnect();
|
|
102
|
+
yield (audioContext === null || audioContext === void 0 ? void 0 : audioContext.close());
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
// We still want to continue if anything above failed
|
|
106
|
+
reportError(ensureError(error));
|
|
91
107
|
}
|
|
92
108
|
audioContext = new AudioContext();
|
|
93
109
|
audioSource = audioContext.createMediaStreamSource(stream);
|
|
@@ -96,13 +112,13 @@ export function createMediaStreamSource(stream, options = {}) {
|
|
|
96
112
|
.addModule(microphoneRecorderUrl)
|
|
97
113
|
.then(() => {
|
|
98
114
|
if (audioContext) {
|
|
99
|
-
|
|
115
|
+
worklet = new AudioWorkletNode(audioContext, "microphone-worklet");
|
|
100
116
|
scopedAudioSource.connect(worklet);
|
|
101
117
|
worklet.connect(audioContext.destination);
|
|
102
118
|
// NOTE: We subscribe to messages here, and they will continue to arrive
|
|
103
119
|
// even after audioContext.close() is called. To disconnect the audio worklets
|
|
104
|
-
// created here, we need to track
|
|
105
|
-
// By calling
|
|
120
|
+
// created here, we need to track two variables - worklet and audioSource.
|
|
121
|
+
// By calling disconnect() on them, we can properly
|
|
106
122
|
// disconnect the audio worklets.
|
|
107
123
|
worklet.port.onmessage = (e) => {
|
|
108
124
|
if (e.data.eventType === "data") {
|
|
@@ -130,6 +146,10 @@ export function createMediaStreamSource(stream, options = {}) {
|
|
|
130
146
|
}
|
|
131
147
|
}),
|
|
132
148
|
onDetach: (reportError) => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
if (worklet) {
|
|
150
|
+
closeWorklet(worklet);
|
|
151
|
+
worklet = undefined;
|
|
152
|
+
}
|
|
133
153
|
if (audioSource) {
|
|
134
154
|
audioSource.disconnect();
|
|
135
155
|
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,UAA4D,EAAE;;QAE9D,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QACtE,OAAO,uBAAuB,CAAC,MAAM,kBAAI,SAAS,EAAE,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,IAAK,OAAO,EAAG,CAAC;IAChH,CAAC;CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,uBAAuB,CACnC,MAAmB,EACnB,UAA4D,EAAE;IAE9D,MAAM,cAAc,mCACb,cAAc,GACd,OAAO,CACb,CAAC;IAEF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GACnB,MAAM,CA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C,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;oCAC5E,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iCACnC;gCAED,QAAQ,CAAC,wBAAwB,CAAC;oCAC9B,KAAK,EAAE,YAAY;oCACnB,SAAS,EAAE,CAAC,KAAY,EAAE,EAAE;wCACxB,WAAW,CAAC,KAAK,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,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 { 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,OAAO;IACrB,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,UAAU,EAAE,CAAC;AACzB,CAAC;AAQD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAgB,qBAAqB,CACvC,cAAsC,EAAE,KAAK,EAAE,IAAI,EAAE,EACrD,UAA4D,EAAE;;QAE9D,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QACtE,OAAO,uBAAuB,CAAC,MAAM,kBAAI,SAAS,EAAE,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,IAAK,OAAO,EAAG,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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 */\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 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"]}
|
|
@@ -11,7 +11,7 @@ import { MetricsEventTarget } from "./metricsEventTarget";
|
|
|
11
11
|
* For a full list of business events (using their internal names), see:
|
|
12
12
|
* https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
type CameraKitBusinessEventMap = {
|
|
15
15
|
assetDownload: MakeBusinessEvent<blizzard.CameraKitAssetDownload>;
|
|
16
16
|
assetValidationFailed: MakeBusinessEvent<blizzard.CameraKitAssetValidationFailed>;
|
|
17
17
|
benchmarkComplete: MakeBusinessEvent<blizzard.CameraKitWebBenchmarkComplete>;
|
|
@@ -23,14 +23,14 @@ declare type CameraKitBusinessEventMap = {
|
|
|
23
23
|
lensContentValidationFailed: MakeBusinessEvent<blizzard.CameraKitLensContentValidationFailed>;
|
|
24
24
|
session: MakeBusinessEvent<blizzard.CameraKitSession>;
|
|
25
25
|
};
|
|
26
|
-
export
|
|
26
|
+
export type MakeBusinessEvent<E> = Omit<{
|
|
27
27
|
[K in keyof E]: Exclude<E[K], undefined> extends Record<keyof any, any> ? MakeBusinessEvent<Exclude<E[K], undefined>> : E[K];
|
|
28
28
|
}, "cameraKitEventBase">;
|
|
29
|
-
export
|
|
29
|
+
export type MakeTaggedBusinessEvent<K extends keyof CameraKitBusinessEventMap> = {
|
|
30
30
|
name: K;
|
|
31
31
|
} & CameraKitBusinessEventMap[K];
|
|
32
32
|
export declare const businessEventsReporterFactory: {
|
|
33
|
-
(args_0: MetricsEventTarget, args_1: FetchHandler
|
|
33
|
+
(args_0: MetricsEventTarget, args_1: FetchHandler): void;
|
|
34
34
|
token: "businessEventsReporter";
|
|
35
35
|
dependencies: readonly ["metricsEventTarget", "metricsHandler"];
|
|
36
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
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EAAE,EAAE,CAAC;YACjB,sBAAsB;YACtB,EAAE,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SACvE;QACD,2BAA2B,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACpC,2CAA2C;YAC3C;gBACI,oCAAoC,EAAE,QAAQ,CAAC,oCAAoC,CAAC,WAAW,CAC3F,KAAK,CACR;aACJ;SACJ;QACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YAChB,oBAAoB;YACpB,EAAE,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SACrE;KACJ,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { v4 } from \"uuid\";\nimport { cameraKitUserAgent as userAgent } from \"../common/cameraKitUserAgent\";\nimport { entries } from \"../common/entries\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { EventOfType } from \"../events/TypedCustomEvent\";\nimport { EventsFromTarget } from \"../events/TypedEventTarget\";\nimport { FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { createBatchingHandler } from \"../handlers/batchingHandler\";\nimport { HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport { createMappingHandler } from \"../handlers/mappingHandler\";\nimport * as blizzard from \"../generated-proto/blizzard/cameraKitEvents\";\nimport { getLogger } from \"../logger/logger\";\nimport { metricsHandlerFactory } from \"./metricsHandler\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"./metricsEventTarget\";\n\nconst logger = getLogger(\"BusinessEventsReporter\");\n\ntype Nullables<T> = { [K in keyof T]-?: undefined extends T[K] ? K : never }[keyof T];\ntype UndefinedToOptional<T> = Partial<Pick<T, Nullables<T>>> & Omit<T, Nullables<T>>;\n\ntype CameraKitBusinessEvents = EventsFromTarget<MetricsEventTarget>[\"detail\"];\n\ntype MakeBlizzardEvent<E> = Omit<E, \"name\"> & { cameraKitEventBase: blizzard.CameraKitEventBase };\n\ntype CreateEventData<EventType extends EventsFromTarget<MetricsEventTarget>[\"type\"]> = (\n event: MakeBlizzardEvent<EventOfType<EventType, EventsFromTarget<MetricsEventTarget>>[\"detail\"]>\n) => [string, UndefinedToOptional<blizzard.ServerEventData>];\n\ntype EventHandlers = {\n [EventType in EventsFromTarget<MetricsEventTarget>[\"type\"]]: CreateEventData<EventType>;\n};\n\n/**\n * Translate between an external metric name, which is exposed to SDK users, and an internal Blizzard event name,\n * property name, and constructor.\n *\n * It is very important that we do this, since the naming of these internal business events are unintuitive and will\n * not make sense to SDK users.\n *\n * For a full list of business events (using their internal names), see:\n * https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/\n */\ntype CameraKitBusinessEventMap = {\n assetDownload: MakeBusinessEvent<blizzard.CameraKitAssetDownload>;\n assetValidationFailed: MakeBusinessEvent<blizzard.CameraKitAssetValidationFailed>;\n benchmarkComplete: MakeBusinessEvent<blizzard.CameraKitWebBenchmarkComplete>;\n exception: MakeBusinessEvent<blizzard.CameraKitException>;\n legalPrompt: MakeBusinessEvent<blizzard.CameraKitLegalPrompt>;\n lensDownload: MakeBusinessEvent<blizzard.CameraKitLensDownload>;\n lensView: MakeBusinessEvent<blizzard.CameraKitWebLensSwipe>;\n lensWait: MakeBusinessEvent<blizzard.CameraKitLensSpin>;\n lensContentValidationFailed: MakeBusinessEvent<blizzard.CameraKitLensContentValidationFailed>;\n session: MakeBusinessEvent<blizzard.CameraKitSession>;\n};\n\n/**\n * This interface is defined in the CameraKit pb_schema proto definition – but the generated TypeScript does not handle\n * the `Any` type properly. It does not conform to the Proto3 canonical JSON mapping scheme, as defined here:\n * https://developers.google.com/protocol-buffers/docs/proto3#json\n *\n * To solve this (since we only need one message from the CameraKit schema), we'll just manually define the correct\n * interface here.\n */\ninterface SetBusinessEventsRequest {\n batchEvents: {\n \"@type\": \"com.snapchat.analytics.blizzard.ServerEventBatch\";\n serverEvents: blizzard.ServerEvent[];\n };\n}\n\n// CameraKit's prod metrics endpoint.\n// See: https://github.sc-corp.net/Snapchat/pb_schema/blob/2a966db/proto/camera_kit/v3/service.proto#L133\nconst BUSINESS_EVENTS_ENDPOINT = \"https://api-kit.snapchat.com/com.snap.camerakit.v3.Metrics/metrics/business_events\";\n\n// These values are (currently) arbitrarily selected.\n// TODO: Once we have gathered a sufficient quantity of metrics data, we should tune these numbers to ensure we're\n// operating with the right cost vs. staying under the `keepalive` request body limit of 64 kibibytes.\nconst BUSINESS_EVENT_BATCH_MAX_SIZE = 100;\nconst BUSINESS_EVENT_BATCH_MAX_AGE_MS = 5000;\n\nfunction listenAndReport(\n metricsEventTarget: MetricsEventTarget,\n metricsHandler: FetchHandler,\n eventHandlers: EventHandlers\n): void {\n const sessionId = v4();\n logger.log(`Session ID: ${sessionId}`);\n\n const handler = new HandlerChainBuilder(metricsHandler)\n .map(\n createMappingHandler((events: blizzard.ServerEvent[]) => {\n const body: SetBusinessEventsRequest = {\n batchEvents: {\n \"@type\": \"com.snapchat.analytics.blizzard.ServerEventBatch\",\n serverEvents: events,\n },\n };\n return new Request(BUSINESS_EVENTS_ENDPOINT, {\n method: \"POST\",\n body: JSON.stringify(body),\n credentials: \"include\",\n\n // Setting this to true makes fetch behave like `Navigator.sendBeacon` – that is, the request\n // will still be made even if the page terminates.\n // https://developer.mozilla.org/en-US/docs/Web/API/fetch\n keepalive: true,\n });\n })\n )\n .map(\n createBatchingHandler({\n batchReduce: (\n previousBundle: blizzard.ServerEvent[] | undefined,\n businessEvent: blizzard.ServerEvent\n ) => {\n const bundle = previousBundle ?? [];\n bundle.push(businessEvent);\n return bundle;\n },\n isBatchComplete: (bundle) => bundle.length >= BUSINESS_EVENT_BATCH_MAX_SIZE,\n maxBatchAge: BUSINESS_EVENT_BATCH_MAX_AGE_MS,\n })\n ).handler;\n\n const makeBlizzardEvent = <E extends CameraKitBusinessEvents>(event: E): MakeBlizzardEvent<E> => {\n return {\n ...event,\n cameraKitEventBase: blizzard.CameraKitEventBase.fromPartial({\n kitEventBase: blizzard.KitEventBase.fromPartial({\n locale: userAgent.locale,\n kitVariant: blizzard.KitType.CAMERA_KIT_WEB,\n kitVariantVersion: userAgent.sdkShortVersion,\n kitClientTimestampMillis: Date.now(),\n }),\n deviceCluster: 0,\n cameraKitVersion: userAgent.sdkLongVersion,\n lensCoreVersion: userAgent.lensCoreVersion,\n deviceModel: userAgent.deviceModel,\n cameraKitVariant: blizzard.CameraKitVariant.CAMERA_KIT_VARIANT_PARTNER,\n cameraKitFlavor: blizzard.CameraKitFlavor.CAMERA_KIT_FLAVOR_DEBUG,\n // We overload appId, using the origin instead because it's nice and human-readable (our backed adds\n // the true appId as oauth_client_id before forwarding events to Blizzard).\n appId: userAgent.origin,\n deviceConnectivity: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_WIFI,\n sessionId: sessionId,\n }),\n };\n };\n\n const sendServerEvent = (\n eventName: string,\n eventData: UndefinedToOptional<blizzard.ServerEventData>\n ): Promise<void> => {\n return handler(\n blizzard.ServerEvent.fromPartial({\n eventName,\n osType: userAgent.osType,\n osVersion: userAgent.osVersion,\n maxSequenceIdOnInstance: 0,\n sequenceId: 0,\n eventData,\n })\n );\n };\n\n entries(eventHandlers).forEach(([eventType, createEventData]) => {\n metricsEventTarget.addEventListener(eventType, ({ detail }) => {\n // Safety: When iterating over object keys in a mapped type, we lose the association between the key type\n // and the value type – at each iteration, the key type is a union of all possible keys and the value type\n // is a union of all possible values. When the value is a function with an argument, and that argument\n // depends on the key type (which is a union), the contravariance of the argument type means that the union\n // becomes an intersection. In our case here, this means the compiler expects each argument to contain all\n // properties from all event types. The cast is safe because the mapped `EventHandlers` type ensures that\n // `createEventData` takes an argument of the type corresponding its key's `eventType`'s event detail.\n const [eventName, eventData] = createEventData(makeBlizzardEvent(detail) as any);\n sendServerEvent(eventName, eventData);\n });\n });\n}\n\nexport type MakeBusinessEvent<E> = Omit<\n {\n [K in keyof E]: Exclude<E[K], undefined> extends Record<keyof any, any>\n ? MakeBusinessEvent<Exclude<E[K], undefined>>\n : E[K];\n },\n \"cameraKitEventBase\"\n>;\n\nexport type MakeTaggedBusinessEvent<K extends keyof CameraKitBusinessEventMap> = {\n name: K;\n} & CameraKitBusinessEventMap[K];\n\nexport const businessEventsReporterFactory = Injectable(\n \"businessEventsReporter\",\n [metricsEventTargetFactory.token, metricsHandlerFactory.token] as const,\n (metricsEventTarget: MetricsEventTarget, metricsHandler: FetchHandler) => {\n /**\n * This defines a mapping from a business event's external name (the name we document in public API docs), to\n * its internal representation as a Blizzard ServerEvent.\n *\n * It is important that we do this, since the naming of these internal business events are unintuitive and will\n * not make sense to SDK users.\n *\n * To specify the internal event, we must give the ServerEvent's eventName, the specific property name which\n * contains the event data (this is a \"oneof\" property on ServerEvent), and use the correct event type's\n * `fromPartial` method (this is generated from the ServerEvent protobuf).\n *\n * These events are documented here:\n * https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/\n *\n * They are defined in code here:\n * https://github.sc-corp.net/Snapchat/snapchat/tree/master/blizzard/schema/blizzard-schema/\n * codeGen/src/main/java/com/snapchat/analytics/schema/events/cameraKit\n */\n listenAndReport(metricsEventTarget, metricsHandler, {\n assetDownload: (event) => [\n \"CAMERA_KIT_ASSET_DOWNLOAD\",\n { cameraKitAssetDownload: blizzard.CameraKitAssetDownload.fromPartial(event) },\n ],\n assetValidationFailed: (event) => [\n \"CAMERA_KIT_ASSET_VALIDATION_FAILED\",\n { cameraKitAssetValidationFailed: blizzard.CameraKitAssetValidationFailed.fromPartial(event) },\n ],\n benchmarkComplete: (event) => [\n \"CAMERA_KIT_WEB_BENCHMARK_COMPLETE\",\n { cameraKitWebBenchmarkComplete: blizzard.CameraKitWebBenchmarkComplete.fromPartial(event) },\n ],\n exception: (event) => [\n \"CAMERA_KIT_EXCEPTION\",\n { cameraKitException: blizzard.CameraKitException.fromPartial(event) },\n ],\n legalPrompt: (event) => [\n \"CAMERA_KIT_LEGAL_PROMPT\",\n { cameraKitLegalPrompt: blizzard.CameraKitLegalPrompt.fromPartial(event) },\n ],\n lensDownload: (event) => [\n \"CAMERA_KIT_LENS_DOWNLOAD\",\n { cameraKitLensDownload: blizzard.CameraKitLensDownload.fromPartial(event) },\n ],\n lensView: (event) => [\n \"CAMERA_KIT_WEB_LENS_SWIPE\",\n { cameraKitWebLensSwipe: blizzard.CameraKitWebLensSwipe.fromPartial(event) },\n ],\n lensWait: (event) => [\n \"CAMERA_KIT_LENS_SPIN\",\n { cameraKitLensSpin: blizzard.CameraKitLensSpin.fromPartial(event) },\n ],\n lensContentValidationFailed: (event) => [\n \"CAMERA_KIT_LENS_CONTENT_VALIDATION_FAILED\",\n {\n cameraKitLensContentValidationFailed: blizzard.CameraKitLensContentValidationFailed.fromPartial(\n event\n ),\n },\n ],\n session: (event) => [\n \"CAMERA_KIT_SESSION\",\n { cameraKitSession: blizzard.CameraKitSession.fromPartial(event) },\n ],\n });\n }\n);\n"]}
|
|
1
|
+
{"version":3,"file":"businessEventsReporter.js","sourceRoot":"","sources":["../../src/metrics/businessEventsReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAE,kBAAkB,IAAI,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAIhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,QAAQ,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,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AE;SAC/F;QACD,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YAClB,sBAAsB;YACtB,EAAE,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SACzE;QACD,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACpB,yBAAyB;YACzB,EAAE,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SAC7E;QACD,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACrB,0BAA0B;YAC1B,EAAE,qBAAqB,EAAE,QAAQ,CAAC,qBAAqB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SAC/E;QACD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACjB,2BAA2B;YAC3B,EAAE,qBAAqB,EAAE,QAAQ,CAAC,qBAAqB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SAC/E;QACD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACjB,sBAAsB;YACtB,EAAE,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SACvE;QACD,2BAA2B,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACpC,2CAA2C;YAC3C;gBACI,oCAAoC,EAChC,QAAQ,CAAC,oCAAoC,CAAC,WAAW,CAAC,KAAK,CAAC;aACvE;SACJ;QACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YAChB,oBAAoB;YACpB,EAAE,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SACrE;KACJ,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { v4 } from \"uuid\";\nimport { cameraKitUserAgent as userAgent } from \"../common/cameraKitUserAgent\";\nimport { entries } from \"../common/entries\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { EventOfType } from \"../events/TypedCustomEvent\";\nimport { EventsFromTarget } from \"../events/TypedEventTarget\";\nimport { FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { createBatchingHandler } from \"../handlers/batchingHandler\";\nimport { HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport { createMappingHandler } from \"../handlers/mappingHandler\";\nimport * as blizzard from \"../generated-proto/blizzard/cameraKitEvents\";\nimport { getLogger } from \"../logger/logger\";\nimport { metricsHandlerFactory } from \"./metricsHandler\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"./metricsEventTarget\";\n\nconst logger = getLogger(\"BusinessEventsReporter\");\n\ntype Nullables<T> = { [K in keyof T]-?: undefined extends T[K] ? K : never }[keyof T];\ntype UndefinedToOptional<T> = Partial<Pick<T, Nullables<T>>> & Omit<T, Nullables<T>>;\n\ntype CameraKitBusinessEvents = EventsFromTarget<MetricsEventTarget>[\"detail\"];\n\ntype MakeBlizzardEvent<E> = Omit<E, \"name\"> & { cameraKitEventBase: blizzard.CameraKitEventBase };\n\ntype CreateEventData<EventType extends EventsFromTarget<MetricsEventTarget>[\"type\"]> = (\n event: MakeBlizzardEvent<EventOfType<EventType, EventsFromTarget<MetricsEventTarget>>[\"detail\"]>\n) => [string, UndefinedToOptional<blizzard.ServerEventData>];\n\ntype EventHandlers = {\n [EventType in EventsFromTarget<MetricsEventTarget>[\"type\"]]: CreateEventData<EventType>;\n};\n\n/**\n * Translate between an external metric name, which is exposed to SDK users, and an internal Blizzard event name,\n * property name, and constructor.\n *\n * It is very important that we do this, since the naming of these internal business events are unintuitive and will\n * not make sense to SDK users.\n *\n * For a full list of business events (using their internal names), see:\n * https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/\n */\ntype CameraKitBusinessEventMap = {\n assetDownload: MakeBusinessEvent<blizzard.CameraKitAssetDownload>;\n assetValidationFailed: MakeBusinessEvent<blizzard.CameraKitAssetValidationFailed>;\n benchmarkComplete: MakeBusinessEvent<blizzard.CameraKitWebBenchmarkComplete>;\n exception: MakeBusinessEvent<blizzard.CameraKitException>;\n legalPrompt: MakeBusinessEvent<blizzard.CameraKitLegalPrompt>;\n lensDownload: MakeBusinessEvent<blizzard.CameraKitLensDownload>;\n lensView: MakeBusinessEvent<blizzard.CameraKitWebLensSwipe>;\n lensWait: MakeBusinessEvent<blizzard.CameraKitLensSpin>;\n lensContentValidationFailed: MakeBusinessEvent<blizzard.CameraKitLensContentValidationFailed>;\n session: MakeBusinessEvent<blizzard.CameraKitSession>;\n};\n\n/**\n * This interface is defined in the CameraKit pb_schema proto definition – but the generated TypeScript does not handle\n * the `Any` type properly. It does not conform to the Proto3 canonical JSON mapping scheme, as defined here:\n * https://developers.google.com/protocol-buffers/docs/proto3#json\n *\n * To solve this (since we only need one message from the CameraKit schema), we'll just manually define the correct\n * interface here.\n */\ninterface SetBusinessEventsRequest {\n batchEvents: {\n \"@type\": \"com.snapchat.analytics.blizzard.ServerEventBatch\";\n serverEvents: blizzard.ServerEvent[];\n };\n}\n\n// CameraKit's prod metrics endpoint.\n// See: https://github.sc-corp.net/Snapchat/pb_schema/blob/2a966db/proto/camera_kit/v3/service.proto#L133\nconst BUSINESS_EVENTS_ENDPOINT = \"https://api-kit.snapchat.com/com.snap.camerakit.v3.Metrics/metrics/business_events\";\n\n// These values are (currently) arbitrarily selected.\n// TODO: Once we have gathered a sufficient quantity of metrics data, we should tune these numbers to ensure we're\n// operating with the right cost vs. staying under the `keepalive` request body limit of 64 kibibytes.\nconst BUSINESS_EVENT_BATCH_MAX_SIZE = 100;\nconst BUSINESS_EVENT_BATCH_MAX_AGE_MS = 5000;\n\nfunction listenAndReport(\n metricsEventTarget: MetricsEventTarget,\n metricsHandler: FetchHandler,\n eventHandlers: EventHandlers\n): void {\n const sessionId = v4();\n logger.log(`Session ID: ${sessionId}`);\n\n const handler = new HandlerChainBuilder(metricsHandler)\n .map(\n createMappingHandler((events: blizzard.ServerEvent[]) => {\n const body: SetBusinessEventsRequest = {\n batchEvents: {\n \"@type\": \"com.snapchat.analytics.blizzard.ServerEventBatch\",\n serverEvents: events,\n },\n };\n return new Request(BUSINESS_EVENTS_ENDPOINT, {\n method: \"POST\",\n body: JSON.stringify(body),\n credentials: \"include\",\n\n // Setting this to true makes fetch behave like `Navigator.sendBeacon` – that is, the request\n // will still be made even if the page terminates.\n // https://developer.mozilla.org/en-US/docs/Web/API/fetch\n keepalive: true,\n });\n })\n )\n .map(\n createBatchingHandler({\n batchReduce: (\n previousBundle: blizzard.ServerEvent[] | undefined,\n businessEvent: blizzard.ServerEvent\n ) => {\n const bundle = previousBundle ?? [];\n bundle.push(businessEvent);\n return bundle;\n },\n isBatchComplete: (bundle) => bundle.length >= BUSINESS_EVENT_BATCH_MAX_SIZE,\n maxBatchAge: BUSINESS_EVENT_BATCH_MAX_AGE_MS,\n })\n ).handler;\n\n const makeBlizzardEvent = <E extends CameraKitBusinessEvents>(event: E): MakeBlizzardEvent<E> => {\n return {\n ...event,\n cameraKitEventBase: blizzard.CameraKitEventBase.fromPartial({\n kitEventBase: blizzard.KitEventBase.fromPartial({\n locale: userAgent.locale,\n kitVariant: blizzard.KitType.CAMERA_KIT_WEB,\n kitVariantVersion: userAgent.sdkShortVersion,\n kitClientTimestampMillis: Date.now(),\n }),\n deviceCluster: 0,\n cameraKitVersion: userAgent.sdkLongVersion,\n lensCoreVersion: userAgent.lensCoreVersion,\n deviceModel: userAgent.deviceModel,\n cameraKitVariant: blizzard.CameraKitVariant.CAMERA_KIT_VARIANT_PARTNER,\n cameraKitFlavor: blizzard.CameraKitFlavor.CAMERA_KIT_FLAVOR_DEBUG,\n // We overload appId, using the origin instead because it's nice and human-readable (our backed adds\n // the true appId as oauth_client_id before forwarding events to Blizzard).\n appId: userAgent.origin,\n deviceConnectivity: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_WIFI,\n sessionId: sessionId,\n }),\n };\n };\n\n const sendServerEvent = (\n eventName: string,\n eventData: UndefinedToOptional<blizzard.ServerEventData>\n ): Promise<void> => {\n return handler(\n blizzard.ServerEvent.fromPartial({\n eventName,\n osType: userAgent.osType,\n osVersion: userAgent.osVersion,\n maxSequenceIdOnInstance: 0,\n sequenceId: 0,\n eventData,\n })\n );\n };\n\n entries(eventHandlers).forEach(([eventType, createEventData]) => {\n metricsEventTarget.addEventListener(eventType, ({ detail }) => {\n // Safety: When iterating over object keys in a mapped type, we lose the association between the key type\n // and the value type – at each iteration, the key type is a union of all possible keys and the value type\n // is a union of all possible values. When the value is a function with an argument, and that argument\n // depends on the key type (which is a union), the contravariance of the argument type means that the union\n // becomes an intersection. In our case here, this means the compiler expects each argument to contain all\n // properties from all event types. The cast is safe because the mapped `EventHandlers` type ensures that\n // `createEventData` takes an argument of the type corresponding its key's `eventType`'s event detail.\n const [eventName, eventData] = createEventData(makeBlizzardEvent(detail) as any);\n sendServerEvent(eventName, eventData);\n });\n });\n}\n\nexport type MakeBusinessEvent<E> = Omit<\n {\n [K in keyof E]: Exclude<E[K], undefined> extends Record<keyof any, any>\n ? MakeBusinessEvent<Exclude<E[K], undefined>>\n : E[K];\n },\n \"cameraKitEventBase\"\n>;\n\nexport type MakeTaggedBusinessEvent<K extends keyof CameraKitBusinessEventMap> = {\n name: K;\n} & CameraKitBusinessEventMap[K];\n\nexport const businessEventsReporterFactory = Injectable(\n \"businessEventsReporter\",\n [metricsEventTargetFactory.token, metricsHandlerFactory.token] as const,\n (metricsEventTarget: MetricsEventTarget, metricsHandler: FetchHandler) => {\n /**\n * This defines a mapping from a business event's external name (the name we document in public API docs), to\n * its internal representation as a Blizzard ServerEvent.\n *\n * It is important that we do this, since the naming of these internal business events are unintuitive and will\n * not make sense to SDK users.\n *\n * To specify the internal event, we must give the ServerEvent's eventName, the specific property name which\n * contains the event data (this is a \"oneof\" property on ServerEvent), and use the correct event type's\n * `fromPartial` method (this is generated from the ServerEvent protobuf).\n *\n * These events are documented here:\n * https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/\n *\n * They are defined in code here:\n * https://github.sc-corp.net/Snapchat/snapchat/tree/master/blizzard/schema/blizzard-schema/\n * codeGen/src/main/java/com/snapchat/analytics/schema/events/cameraKit\n */\n listenAndReport(metricsEventTarget, metricsHandler, {\n assetDownload: (event) => [\n \"CAMERA_KIT_ASSET_DOWNLOAD\",\n { cameraKitAssetDownload: blizzard.CameraKitAssetDownload.fromPartial(event) },\n ],\n assetValidationFailed: (event) => [\n \"CAMERA_KIT_ASSET_VALIDATION_FAILED\",\n { cameraKitAssetValidationFailed: blizzard.CameraKitAssetValidationFailed.fromPartial(event) },\n ],\n benchmarkComplete: (event) => [\n \"CAMERA_KIT_WEB_BENCHMARK_COMPLETE\",\n { cameraKitWebBenchmarkComplete: blizzard.CameraKitWebBenchmarkComplete.fromPartial(event) },\n ],\n exception: (event) => [\n \"CAMERA_KIT_EXCEPTION\",\n { cameraKitException: blizzard.CameraKitException.fromPartial(event) },\n ],\n legalPrompt: (event) => [\n \"CAMERA_KIT_LEGAL_PROMPT\",\n { cameraKitLegalPrompt: blizzard.CameraKitLegalPrompt.fromPartial(event) },\n ],\n lensDownload: (event) => [\n \"CAMERA_KIT_LENS_DOWNLOAD\",\n { cameraKitLensDownload: blizzard.CameraKitLensDownload.fromPartial(event) },\n ],\n lensView: (event) => [\n \"CAMERA_KIT_WEB_LENS_SWIPE\",\n { cameraKitWebLensSwipe: blizzard.CameraKitWebLensSwipe.fromPartial(event) },\n ],\n lensWait: (event) => [\n \"CAMERA_KIT_LENS_SPIN\",\n { cameraKitLensSpin: blizzard.CameraKitLensSpin.fromPartial(event) },\n ],\n lensContentValidationFailed: (event) => [\n \"CAMERA_KIT_LENS_CONTENT_VALIDATION_FAILED\",\n {\n cameraKitLensContentValidationFailed:\n blizzard.CameraKitLensContentValidationFailed.fromPartial(event),\n },\n ],\n session: (event) => [\n \"CAMERA_KIT_SESSION\",\n { cameraKitSession: blizzard.CameraKitSession.fromPartial(event) },\n ],\n });\n }\n);\n"]}
|