@snap/camera-kit 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +6247 -0
- package/README.md +166 -0
- package/docs/html/.nojekyll +1 -0
- package/docs/html/assets/highlight.css +106 -0
- package/docs/html/assets/main.js +54 -0
- package/docs/html/assets/search.js +1 -0
- package/docs/html/assets/style.css +1225 -0
- package/docs/html/assets/widgets.png +0 -0
- package/docs/html/assets/widgets@2x.png +0 -0
- package/docs/html/classes/CameraKit.html +121 -0
- package/docs/html/classes/CameraKitSession.html +347 -0
- package/docs/html/classes/CameraKitSource.html +152 -0
- package/docs/html/classes/LensPerformanceMeasurement.html +115 -0
- package/docs/html/classes/LensPerformanceMetrics.html +76 -0
- package/docs/html/classes/LensRepository.html +171 -0
- package/docs/html/classes/LensSources.html +82 -0
- package/docs/html/classes/Transform2D.html +99 -0
- package/docs/html/classes/TypedCustomEvent.html +109 -0
- package/docs/html/classes/TypedEventTarget.html +146 -0
- package/docs/html/functions/Injectable.html +193 -0
- package/docs/html/functions/bootstrapCameraKit.html +158 -0
- package/docs/html/functions/createExtension.html +127 -0
- package/docs/html/functions/createImageSource.html +123 -0
- package/docs/html/functions/createMediaStreamSource.html +123 -0
- package/docs/html/functions/createUserMediaSource.html +127 -0
- package/docs/html/functions/createVideoSource.html +124 -0
- package/docs/html/functions/estimateLensPerformance.html +116 -0
- package/docs/html/functions/getRequiredBootstrapURLs.html +124 -0
- package/docs/html/functions/lensSourcesFactory.html +116 -0
- package/docs/html/functions/uriHandlersFactory.html +118 -0
- package/docs/html/index.html +208 -0
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +132 -0
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +121 -0
- package/docs/html/interfaces/ComputedFrameMetrics.html +70 -0
- package/docs/html/interfaces/CreateSessionOptions.html +77 -0
- package/docs/html/interfaces/EstimatedLensPerformance.html +78 -0
- package/docs/html/interfaces/Lens.html +115 -0
- package/docs/html/interfaces/LensSource.html +113 -0
- package/docs/html/interfaces/MediaStreamSourceOptions.html +65 -0
- package/docs/html/interfaces/UriCancelRequest.html +65 -0
- package/docs/html/interfaces/UriHandler.html +128 -0
- package/docs/html/interfaces/UriRequest.html +80 -0
- package/docs/html/interfaces/UriResponse.html +80 -0
- package/docs/html/interfaces/VideoSourceOptions.html +60 -0
- package/docs/html/modules.html +198 -0
- package/docs/html/types/AssetLoader.html +126 -0
- package/docs/html/types/AssetTiming.html +116 -0
- package/docs/html/types/BenchmarkError.html +107 -0
- package/docs/html/types/BootstrapError.html +110 -0
- package/docs/html/types/CacheKeyNotFoundError.html +107 -0
- package/docs/html/types/CameraKitDeviceInfo.html +114 -0
- package/docs/html/types/CameraKitSessionEventListener.html +109 -0
- package/docs/html/types/CameraKitSessionEvents.html +118 -0
- package/docs/html/types/CameraKitSourceError.html +107 -0
- package/docs/html/types/CameraKitSourceInfo.html +107 -0
- package/docs/html/types/CameraKitSourceOptions.html +113 -0
- package/docs/html/types/ConfigurationError.html +109 -0
- package/docs/html/types/Keyboard.html +196 -0
- package/docs/html/types/KeyboardEvents.html +109 -0
- package/docs/html/types/LegalError.html +107 -0
- package/docs/html/types/LensAssetError.html +109 -0
- package/docs/html/types/LensContentValidationError.html +107 -0
- package/docs/html/types/LensError.html +107 -0
- package/docs/html/types/LensExecutionError.html +114 -0
- package/docs/html/types/LensImagePickerError.html +110 -0
- package/docs/html/types/LensLaunchParams.html +109 -0
- package/docs/html/types/LensMetricsEvents.html +110 -0
- package/docs/html/types/LensPerformanceCluster.html +107 -0
- package/docs/html/types/LensView.html +119 -0
- package/docs/html/types/LensWait.html +111 -0
- package/docs/html/types/PersistentStoreError.html +109 -0
- package/docs/html/types/PlatformNotSupportedError.html +110 -0
- package/docs/html/types/PublicContainer.html +110 -0
- package/docs/html/types/RenderTarget.html +111 -0
- package/docs/html/types/Uri.html +107 -0
- package/docs/html/types/UriHandlers.html +109 -0
- package/docs/html/types/WebGLError.html +107 -0
- package/docs/html/variables/extensionRequestContext.html +109 -0
- package/docs/md/.nojekyll +1 -0
- package/docs/md/README.md +168 -0
- package/docs/md/classes/CameraKit.md +94 -0
- package/docs/md/classes/CameraKitSession.md +359 -0
- package/docs/md/classes/CameraKitSource.md +110 -0
- package/docs/md/classes/LensPerformanceMeasurement.md +77 -0
- package/docs/md/classes/LensPerformanceMetrics.md +37 -0
- package/docs/md/classes/LensRepository.md +145 -0
- package/docs/md/classes/LensSources.md +29 -0
- package/docs/md/classes/Transform2D.md +55 -0
- package/docs/md/classes/TypedCustomEvent.md +65 -0
- package/docs/md/classes/TypedEventTarget.md +103 -0
- package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +106 -0
- package/docs/md/interfaces/CameraKitSourceSubscriber.md +55 -0
- package/docs/md/interfaces/ComputedFrameMetrics.md +29 -0
- package/docs/md/interfaces/CreateSessionOptions.md +35 -0
- package/docs/md/interfaces/EstimatedLensPerformance.md +38 -0
- package/docs/md/interfaces/Lens.md +84 -0
- package/docs/md/interfaces/LensSource.md +68 -0
- package/docs/md/interfaces/MediaStreamSourceOptions.md +22 -0
- package/docs/md/interfaces/UriCancelRequest.md +22 -0
- package/docs/md/interfaces/UriHandler.md +63 -0
- package/docs/md/interfaces/UriRequest.md +43 -0
- package/docs/md/interfaces/UriResponse.md +43 -0
- package/docs/md/interfaces/VideoSourceOptions.md +15 -0
- package/docs/md/modules.md +827 -0
- package/lib/CameraKit.d.ts +170 -0
- package/lib/CameraKit.js +145 -0
- package/lib/CameraKit.js.map +1 -0
- package/lib/__tests__/data.d.ts +9 -0
- package/lib/__tests__/data.js +50 -0
- package/lib/__tests__/data.js.map +1 -0
- package/lib/__tests__/deferred.d.ts +16 -0
- package/lib/__tests__/deferred.js +29 -0
- package/lib/__tests__/deferred.js.map +1 -0
- package/lib/__tests__/jest.matchers.d.ts +17 -0
- package/lib/__tests__/jest.matchers.js +67 -0
- package/lib/__tests__/jest.matchers.js.map +1 -0
- package/lib/assertPlatformSupported.d.ts +4 -0
- package/lib/assertPlatformSupported.js +10 -0
- package/lib/assertPlatformSupported.js.map +1 -0
- package/lib/benchmark/benchmarkGflops.d.ts +16 -0
- package/lib/benchmark/benchmarkGflops.js +129 -0
- package/lib/benchmark/benchmarkGflops.js.map +1 -0
- package/lib/benchmark/estimateLensPerformanceCluster.d.ts +33 -0
- package/lib/benchmark/estimateLensPerformanceCluster.js +48 -0
- package/lib/benchmark/estimateLensPerformanceCluster.js.map +1 -0
- package/lib/benchmark/webglUtils.d.ts +7 -0
- package/lib/benchmark/webglUtils.js +87 -0
- package/lib/benchmark/webglUtils.js.map +1 -0
- package/lib/bootstrapCameraKit.d.ts +96 -0
- package/lib/bootstrapCameraKit.js +204 -0
- package/lib/bootstrapCameraKit.js.map +1 -0
- package/lib/common/__mocks__/loadScript.d.ts +1 -0
- package/lib/common/__mocks__/loadScript.js +10 -0
- package/lib/common/__mocks__/loadScript.js.map +1 -0
- package/lib/common/assertions.d.ts +27 -0
- package/lib/common/assertions.js +39 -0
- package/lib/common/assertions.js.map +1 -0
- package/lib/common/cameraKitUserAgent.d.ts +34 -0
- package/lib/common/cameraKitUserAgent.js +216 -0
- package/lib/common/cameraKitUserAgent.js.map +1 -0
- package/lib/common/copyDefinedProperties.d.ts +13 -0
- package/lib/common/copyDefinedProperties.js +16 -0
- package/lib/common/copyDefinedProperties.js.map +1 -0
- package/lib/common/entries.d.ts +3 -0
- package/lib/common/entries.js +3 -0
- package/lib/common/entries.js.map +1 -0
- package/lib/common/errorHelpers.d.ts +10 -0
- package/lib/common/errorHelpers.js +24 -0
- package/lib/common/errorHelpers.js.map +1 -0
- package/lib/common/getFilename.d.ts +1 -0
- package/lib/common/getFilename.js +4 -0
- package/lib/common/getFilename.js.map +1 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +3 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/loadScript.d.ts +1 -0
- package/lib/common/loadScript.js +11 -0
- package/lib/common/loadScript.js.map +1 -0
- package/lib/common/locale.d.ts +2 -0
- package/lib/common/locale.js +11 -0
- package/lib/common/locale.js.map +1 -0
- package/lib/common/localization.d.ts +43 -0
- package/lib/common/localization.js +43 -0
- package/lib/common/localization.js.map +1 -0
- package/lib/common/memoize.d.ts +8 -0
- package/lib/common/memoize.js +15 -0
- package/lib/common/memoize.js.map +1 -0
- package/lib/common/pageVisibility.d.ts +20 -0
- package/lib/common/pageVisibility.js +62 -0
- package/lib/common/pageVisibility.js.map +1 -0
- package/lib/common/time.d.ts +1 -0
- package/lib/common/time.js +2 -0
- package/lib/common/time.js.map +1 -0
- package/lib/common/typeguards.d.ts +53 -0
- package/lib/common/typeguards.js +92 -0
- package/lib/common/typeguards.js.map +1 -0
- package/lib/common/types.d.ts +10 -0
- package/lib/common/types.js +2 -0
- package/lib/common/types.js.map +1 -0
- package/lib/common/validate.d.ts +14 -0
- package/lib/common/validate.js +104 -0
- package/lib/common/validate.js.map +1 -0
- package/lib/configuration.d.ts +92 -0
- package/lib/configuration.js +36 -0
- package/lib/configuration.js.map +1 -0
- package/lib/configurationOverrides.d.ts +12 -0
- package/lib/configurationOverrides.js +41 -0
- package/lib/configurationOverrides.js.map +1 -0
- package/lib/dependency-injection/Container.d.ts +177 -0
- package/lib/dependency-injection/Container.js +160 -0
- package/lib/dependency-injection/Container.js.map +1 -0
- package/lib/dependency-injection/Injectable.d.ts +39 -0
- package/lib/dependency-injection/Injectable.js +18 -0
- package/lib/dependency-injection/Injectable.js.map +1 -0
- package/lib/dependency-injection/PartialContainer.d.ts +81 -0
- package/lib/dependency-injection/PartialContainer.js +85 -0
- package/lib/dependency-injection/PartialContainer.js.map +1 -0
- package/lib/dependency-injection/RootServices.d.ts +62 -0
- package/lib/dependency-injection/RootServices.js +2 -0
- package/lib/dependency-injection/RootServices.js.map +1 -0
- package/lib/dependency-injection/types.d.ts +56 -0
- package/lib/dependency-injection/types.js +2 -0
- package/lib/dependency-injection/types.js.map +1 -0
- package/lib/environment.json +1 -0
- package/lib/events/TypedCustomEvent.d.ts +10 -0
- package/lib/events/TypedCustomEvent.js +11 -0
- package/lib/events/TypedCustomEvent.js.map +1 -0
- package/lib/events/TypedEventTarget.d.ts +25 -0
- package/lib/events/TypedEventTarget.js +57 -0
- package/lib/events/TypedEventTarget.js.map +1 -0
- package/lib/events/scan.d.ts +15 -0
- package/lib/events/scan.js +46 -0
- package/lib/events/scan.js.map +1 -0
- package/lib/extensions/LensSources.d.ts +58 -0
- package/lib/extensions/LensSources.js +50 -0
- package/lib/extensions/LensSources.js.map +1 -0
- package/lib/extensions/UriHandlers.d.ts +54 -0
- package/lib/extensions/UriHandlers.js +93 -0
- package/lib/extensions/UriHandlers.js.map +1 -0
- package/lib/extensions/extensionRequestContext.d.ts +4 -0
- package/lib/extensions/extensionRequestContext.js +14 -0
- package/lib/extensions/extensionRequestContext.js.map +1 -0
- package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +5603 -0
- package/lib/generated-proto/blizzard/cameraKitEvents.js +522 -0
- package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +98 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +260 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +543 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +429 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +100 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +164 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +395 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +644 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +185 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +172 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +86 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +234 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +854 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +629 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +86 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js +185 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.d.ts +95 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js +104 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +10212 -0
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +1300 -0
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +401 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js +525 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +1287 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.js +135 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4208 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +1053 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.d.ts +102 -0
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js +165 -0
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.d.ts +8 -0
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.js +17 -0
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.js.map +1 -0
- package/lib/generated-proto/pb_schema/common/ruid.d.ts +75 -0
- package/lib/generated-proto/pb_schema/common/ruid.js +96 -0
- package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -0
- package/lib/generated-proto/pb_schema/common/value.d.ts +131 -0
- package/lib/generated-proto/pb_schema/common/value.js +204 -0
- package/lib/generated-proto/pb_schema/common/value.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/api/annotations.d.ts +1 -0
- package/lib/generated-proto/pb_schema/google/api/annotations.js +9 -0
- package/lib/generated-proto/pb_schema/google/api/annotations.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/api/http.d.ts +3636 -0
- package/lib/generated-proto/pb_schema/google/api/http.js +271 -0
- package/lib/generated-proto/pb_schema/google/api/http.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +139 -0
- package/lib/generated-proto/pb_schema/google/protobuf/any.js +94 -0
- package/lib/generated-proto/pb_schema/google/protobuf/any.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +50968 -0
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +2962 -0
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +98 -0
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js +82 -0
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +173 -0
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js +332 -0
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/geocircle.d.ts +42 -0
- package/lib/generated-proto/pb_schema/lenses/geocircle.js +52 -0
- package/lib/generated-proto/pb_schema/lenses/geocircle.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/geopoint.d.ts +32 -0
- package/lib/generated-proto/pb_schema/lenses/geopoint.js +50 -0
- package/lib/generated-proto/pb_schema/lenses/geopoint.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/launch_params.d.ts +29 -0
- package/lib/generated-proto/pb_schema/lenses/launch_params.js +43 -0
- package/lib/generated-proto/pb_schema/lenses/launch_params.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +365 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.js +216 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/lures.d.ts +113 -0
- package/lib/generated-proto/pb_schema/lenses/lures.js +64 -0
- package/lib/generated-proto/pb_schema/lenses/lures.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/persistent_store.d.ts +29 -0
- package/lib/generated-proto/pb_schema/lenses/persistent_store.js +43 -0
- package/lib/generated-proto/pb_schema/lenses/persistent_store.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +921 -0
- package/lib/generated-proto/pb_schema/lenses/snappable.js +954 -0
- package/lib/generated-proto/pb_schema/lenses/snappable.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +247 -0
- package/lib/generated-proto/pb_schema/lenses/user_data.js +362 -0
- package/lib/generated-proto/pb_schema/lenses/user_data.js.map +1 -0
- package/lib/handlers/HandlerChainBuilder.d.ts +95 -0
- package/lib/handlers/HandlerChainBuilder.js +187 -0
- package/lib/handlers/HandlerChainBuilder.js.map +1 -0
- package/lib/handlers/arrayBufferParsingHandler.d.ts +10 -0
- package/lib/handlers/arrayBufferParsingHandler.js +18 -0
- package/lib/handlers/arrayBufferParsingHandler.js.map +1 -0
- package/lib/handlers/batchingHandler.d.ts +25 -0
- package/lib/handlers/batchingHandler.js +79 -0
- package/lib/handlers/batchingHandler.js.map +1 -0
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.d.ts +12 -0
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.js +19 -0
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.js.map +1 -0
- package/lib/handlers/debugHandler.d.ts +8 -0
- package/lib/handlers/debugHandler.js +27 -0
- package/lib/handlers/debugHandler.js.map +1 -0
- package/lib/handlers/defaultFetchHandler.d.ts +15 -0
- package/lib/handlers/defaultFetchHandler.js +29 -0
- package/lib/handlers/defaultFetchHandler.js.map +1 -0
- package/lib/handlers/headersModifyingFetchHandler.d.ts +8 -0
- package/lib/handlers/headersModifyingFetchHandler.js +13 -0
- package/lib/handlers/headersModifyingFetchHandler.js.map +1 -0
- package/lib/handlers/index.d.ts +2 -0
- package/lib/handlers/index.js +3 -0
- package/lib/handlers/index.js.map +1 -0
- package/lib/handlers/mappingHandler.d.ts +15 -0
- package/lib/handlers/mappingHandler.js +65 -0
- package/lib/handlers/mappingHandler.js.map +1 -0
- package/lib/handlers/noCorsRetryingFetchHandler.d.ts +48 -0
- package/lib/handlers/noCorsRetryingFetchHandler.js +94 -0
- package/lib/handlers/noCorsRetryingFetchHandler.js.map +1 -0
- package/lib/handlers/persistingHandler.d.ts +14 -0
- package/lib/handlers/persistingHandler.js +71 -0
- package/lib/handlers/persistingHandler.js.map +1 -0
- package/lib/handlers/rateLimitingHandler.d.ts +20 -0
- package/lib/handlers/rateLimitingHandler.js +43 -0
- package/lib/handlers/rateLimitingHandler.js.map +1 -0
- package/lib/handlers/requestStateEmittingHandler.d.ts +29 -0
- package/lib/handlers/requestStateEmittingHandler.js +43 -0
- package/lib/handlers/requestStateEmittingHandler.js.map +1 -0
- package/lib/handlers/responseCachingHandler.d.ts +27 -0
- package/lib/handlers/responseCachingHandler.js +94 -0
- package/lib/handlers/responseCachingHandler.js.map +1 -0
- package/lib/handlers/retryingHandler.d.ts +37 -0
- package/lib/handlers/retryingHandler.js +73 -0
- package/lib/handlers/retryingHandler.js.map +1 -0
- package/lib/handlers/timeoutHandler.d.ts +18 -0
- package/lib/handlers/timeoutHandler.js +30 -0
- package/lib/handlers/timeoutHandler.js.map +1 -0
- package/lib/index.d.ts +33 -0
- package/lib/index.js +32 -0
- package/lib/index.js.map +1 -0
- package/lib/legal/legalPrompt.d.ts +17 -0
- package/lib/legal/legalPrompt.js +144 -0
- package/lib/legal/legalPrompt.js.map +1 -0
- package/lib/legal/legalState.d.ts +50 -0
- package/lib/legal/legalState.js +149 -0
- package/lib/legal/legalState.js.map +1 -0
- package/lib/lens/Lens.d.ts +71 -0
- package/lib/lens/Lens.js +63 -0
- package/lib/lens/Lens.js.map +1 -0
- package/lib/lens/LensLaunchParams.d.ts +19 -0
- package/lib/lens/LensLaunchParams.js +38 -0
- package/lib/lens/LensLaunchParams.js.map +1 -0
- package/lib/lens/LensPersistenceStore.d.ts +7 -0
- package/lib/lens/LensPersistenceStore.js +20 -0
- package/lib/lens/LensPersistenceStore.js.map +1 -0
- package/lib/lens/LensRepository.d.ts +134 -0
- package/lib/lens/LensRepository.js +239 -0
- package/lib/lens/LensRepository.js.map +1 -0
- package/lib/lens/assets/LensAssetRepository.d.ts +66 -0
- package/lib/lens/assets/LensAssetRepository.js +179 -0
- package/lib/lens/assets/LensAssetRepository.js.map +1 -0
- package/lib/lens/assets/LensAssetsProvider.d.ts +21 -0
- package/lib/lens/assets/LensAssetsProvider.js +41 -0
- package/lib/lens/assets/LensAssetsProvider.js.map +1 -0
- package/lib/lens/assets/deviceDependentAssetLoader.d.ts +11 -0
- package/lib/lens/assets/deviceDependentAssetLoader.js +58 -0
- package/lib/lens/assets/deviceDependentAssetLoader.js.map +1 -0
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.d.ts +10 -0
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.js +26 -0
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.js.map +1 -0
- package/lib/lens/assets/staticAssetLoader.d.ts +10 -0
- package/lib/lens/assets/staticAssetLoader.js +24 -0
- package/lib/lens/assets/staticAssetLoader.js.map +1 -0
- package/lib/lens/index.d.ts +7 -0
- package/lib/lens/index.js +7 -0
- package/lib/lens/index.js.map +1 -0
- package/lib/lens/lensEnvelopeUtil.d.ts +5 -0
- package/lib/lens/lensEnvelopeUtil.js +19 -0
- package/lib/lens/lensEnvelopeUtil.js.map +1 -0
- package/lib/lens/lensHttpUtil.d.ts +4 -0
- package/lib/lens/lensHttpUtil.js +30 -0
- package/lib/lens/lensHttpUtil.js.map +1 -0
- package/lib/lens-client-interface/exif.d.ts +20 -0
- package/lib/lens-client-interface/exif.js +61 -0
- package/lib/lens-client-interface/exif.js.map +1 -0
- package/lib/lens-client-interface/imagePicker.d.ts +7 -0
- package/lib/lens-client-interface/imagePicker.js +128 -0
- package/lib/lens-client-interface/imagePicker.js.map +1 -0
- package/lib/lens-client-interface/lensClientInterface.d.ts +13 -0
- package/lib/lens-client-interface/lensClientInterface.js +30 -0
- package/lib/lens-client-interface/lensClientInterface.js.map +1 -0
- package/lib/lens-core-module/generated-types.d.ts +426 -0
- package/lib/lens-core-module/generated-types.js +2 -0
- package/lib/lens-core-module/generated-types.js.map +1 -0
- package/lib/lens-core-module/index.d.ts +2 -0
- package/lib/lens-core-module/index.js +3 -0
- package/lib/lens-core-module/index.js.map +1 -0
- package/lib/lens-core-module/loader/index.d.ts +1 -0
- package/lib/lens-core-module/loader/index.js +2 -0
- package/lib/lens-core-module/loader/index.js.map +1 -0
- package/lib/lens-core-module/loader/lensCoreFactory.d.ts +30 -0
- package/lib/lens-core-module/loader/lensCoreFactory.js +121 -0
- package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -0
- package/lib/lensCoreWasmVersions.json +5 -0
- package/lib/logger/errorLoggingDecorator.d.ts +9 -0
- package/lib/logger/errorLoggingDecorator.js +32 -0
- package/lib/logger/errorLoggingDecorator.js.map +1 -0
- package/lib/logger/logEntries.d.ts +15 -0
- package/lib/logger/logEntries.js +14 -0
- package/lib/logger/logEntries.js.map +1 -0
- package/lib/logger/logger.d.ts +35 -0
- package/lib/logger/logger.js +48 -0
- package/lib/logger/logger.js.map +1 -0
- package/lib/logger/registerLogEntriesSubscriber.d.ts +14 -0
- package/lib/logger/registerLogEntriesSubscriber.js +23 -0
- package/lib/logger/registerLogEntriesSubscriber.js.map +1 -0
- package/lib/media-sources/CameraKitSource.d.ts +88 -0
- package/lib/media-sources/CameraKitSource.js +140 -0
- package/lib/media-sources/CameraKitSource.js.map +1 -0
- package/lib/media-sources/FunctionSource.d.ts +30 -0
- package/lib/media-sources/FunctionSource.js +132 -0
- package/lib/media-sources/FunctionSource.js.map +1 -0
- package/lib/media-sources/ImageSource.d.ts +13 -0
- package/lib/media-sources/ImageSource.js +28 -0
- package/lib/media-sources/ImageSource.js.map +1 -0
- package/lib/media-sources/MediaStreamSource.d.ts +41 -0
- package/lib/media-sources/MediaStreamSource.js +146 -0
- package/lib/media-sources/MediaStreamSource.js.map +1 -0
- package/lib/media-sources/VideoSource.d.ts +21 -0
- package/lib/media-sources/VideoSource.js +38 -0
- package/lib/media-sources/VideoSource.js.map +1 -0
- package/lib/metrics/businessEventsReporter.d.ts +37 -0
- package/lib/metrics/businessEventsReporter.js +160 -0
- package/lib/metrics/businessEventsReporter.js.map +1 -0
- package/lib/metrics/metricsEventTarget.d.ts +41 -0
- package/lib/metrics/metricsEventTarget.js +11 -0
- package/lib/metrics/metricsEventTarget.js.map +1 -0
- package/lib/metrics/metricsHandler.d.ts +9 -0
- package/lib/metrics/metricsHandler.js +13 -0
- package/lib/metrics/metricsHandler.js.map +1 -0
- package/lib/metrics/operationalMetricsReporter.d.ts +52 -0
- package/lib/metrics/operationalMetricsReporter.js +108 -0
- package/lib/metrics/operationalMetricsReporter.js.map +1 -0
- package/lib/metrics/reporters/reportBenchmarks.d.ts +10 -0
- package/lib/metrics/reporters/reportBenchmarks.js +29 -0
- package/lib/metrics/reporters/reportBenchmarks.js.map +1 -0
- package/lib/metrics/reporters/reportGlobalException.d.ts +19 -0
- package/lib/metrics/reporters/reportGlobalException.js +68 -0
- package/lib/metrics/reporters/reportGlobalException.js.map +1 -0
- package/lib/metrics/reporters/reportHttpMetrics.d.ts +17 -0
- package/lib/metrics/reporters/reportHttpMetrics.js +92 -0
- package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -0
- package/lib/metrics/reporters/reportLegalState.d.ts +15 -0
- package/lib/metrics/reporters/reportLegalState.js +34 -0
- package/lib/metrics/reporters/reportLegalState.js.map +1 -0
- package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +38 -0
- package/lib/metrics/reporters/reportLensAndAssetDownload.js +88 -0
- package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -0
- package/lib/metrics/reporters/reportLensValidationFailed.d.ts +20 -0
- package/lib/metrics/reporters/reportLensValidationFailed.js +24 -0
- package/lib/metrics/reporters/reportLensValidationFailed.js.map +1 -0
- package/lib/metrics/reporters/reportLensView.d.ts +36 -0
- package/lib/metrics/reporters/reportLensView.js +101 -0
- package/lib/metrics/reporters/reportLensView.js.map +1 -0
- package/lib/metrics/reporters/reportLensWait.d.ts +33 -0
- package/lib/metrics/reporters/reportLensWait.js +56 -0
- package/lib/metrics/reporters/reportLensWait.js.map +1 -0
- package/lib/metrics/reporters/reportSessionException.d.ts +17 -0
- package/lib/metrics/reporters/reportSessionException.js +12 -0
- package/lib/metrics/reporters/reportSessionException.js.map +1 -0
- package/lib/metrics/reporters/reportUserSession.d.ts +14 -0
- package/lib/metrics/reporters/reportUserSession.js +67 -0
- package/lib/metrics/reporters/reportUserSession.js.map +1 -0
- package/lib/metrics/reporters/reporters.d.ts +44 -0
- package/lib/metrics/reporters/reporters.js +33 -0
- package/lib/metrics/reporters/reporters.js.map +1 -0
- package/lib/namedErrors.d.ts +107 -0
- package/lib/namedErrors.js +56 -0
- package/lib/namedErrors.js.map +1 -0
- package/lib/persistence/ExpiringPersistence.d.ts +20 -0
- package/lib/persistence/ExpiringPersistence.js +58 -0
- package/lib/persistence/ExpiringPersistence.js.map +1 -0
- package/lib/persistence/IndexedDBPersistence.d.ts +47 -0
- package/lib/persistence/IndexedDBPersistence.js +180 -0
- package/lib/persistence/IndexedDBPersistence.js.map +1 -0
- package/lib/persistence/Persistence.d.ts +25 -0
- package/lib/persistence/Persistence.js +10 -0
- package/lib/persistence/Persistence.js.map +1 -0
- package/lib/remote-configuration/cofHandler.d.ts +21 -0
- package/lib/remote-configuration/cofHandler.js +75 -0
- package/lib/remote-configuration/cofHandler.js.map +1 -0
- package/lib/remote-configuration/remoteConfiguration.d.ts +13 -0
- package/lib/remote-configuration/remoteConfiguration.js +43 -0
- package/lib/remote-configuration/remoteConfiguration.js.map +1 -0
- package/lib/session/CameraKitSession.d.ts +252 -0
- package/lib/session/CameraKitSession.js +439 -0
- package/lib/session/CameraKitSession.js.map +1 -0
- package/lib/session/CameraKitSessionEvents.d.ts +33 -0
- package/lib/session/CameraKitSessionEvents.js +21 -0
- package/lib/session/CameraKitSessionEvents.js.map +1 -0
- package/lib/session/LensKeyboard.d.ts +89 -0
- package/lib/session/LensKeyboard.js +95 -0
- package/lib/session/LensKeyboard.js.map +1 -0
- package/lib/session/LensPerformanceMeasurement.d.ts +55 -0
- package/lib/session/LensPerformanceMeasurement.js +91 -0
- package/lib/session/LensPerformanceMeasurement.js.map +1 -0
- package/lib/session/LensPerformanceMetrics.d.ts +31 -0
- package/lib/session/LensPerformanceMetrics.js +58 -0
- package/lib/session/LensPerformanceMetrics.js.map +1 -0
- package/lib/session/index.d.ts +1 -0
- package/lib/session/index.js +2 -0
- package/lib/session/index.js.map +1 -0
- package/lib/session/lensState.d.ts +29 -0
- package/lib/session/lensState.js +160 -0
- package/lib/session/lensState.js.map +1 -0
- package/lib/session/sessionState.d.ts +10 -0
- package/lib/session/sessionState.js +12 -0
- package/lib/session/sessionState.js.map +1 -0
- package/lib/transforms/Transform2D.d.ts +17 -0
- package/lib/transforms/Transform2D.js +18 -0
- package/lib/transforms/Transform2D.js.map +1 -0
- package/lib/transforms/index.d.ts +1 -0
- package/lib/transforms/index.js +2 -0
- package/lib/transforms/index.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FunctionSource.js","sourceRoot":"","sources":["../../src/media-sources/FunctionSource.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAqD,MAAM,mBAAmB,CAAC;AAEvG,MAAM,eAAe,GAAG,CAAO,MAAyB,EAAE,QAAwB,EAAsB,EAAE;IACtG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACjC,0FAA0F;IAC1F,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,MAAM,IAAI,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE;QACvC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACpG,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACnD,OAAO,IAAI,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC,CAAA,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,MAAyB,EAAE,aAA8C,EAAa,EAAE;IAC7G,IAAI,aAAa,KAAK,IAAI;QAAE,OAAO,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;I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BACvB,CAAC,CAAC,CAAC;iBACN;gBAAC,OAAO,KAAK,EAAE;oBACZ,WAAW,CACP,IAAI,KAAK,CACL,kEAAkE;wBAC9D,uBAAuB,MAAA,cAAc,CAAC,IAAI,mCAAI,WAAW,GAAG,EAChE,EAAE,KAAK,EAAE,KAAK,EAAE,CACnB,CACJ,CAAC;iBACL;YACL,CAAC,CAAA,CAAC,CAAC;YACP,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;QAChD,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE;YACX,kBAAkB,GAAG,KAAK,CAAC;QAC/B,CAAC;KACJ,CAAC;IAEF,OAAO,IAAI,eAAe,CAAC,EAAE,wBAAwB,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACxF,CAAC,CAAC","sourcesContent":["import { LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { CameraKitSource, CameraKitSourceOptions, CameraKitSourceSubscriber } from \"./CameraKitSource\";\n\nconst getYUVImageData = async (canvas: HTMLCanvasElement, lensCore: LensCoreModule): Promise<ImageData> => {\n const { width, height } = canvas;\n // A YUV buffer has lower-res UV channels, so the total number of bytes works out like so:\n const outputBuffer = new ArrayBuffer((width * height * 3) / 2);\n await new Promise((onSuccess, onFailure) => {\n lensCore.imageToYuvBuffer({ image: canvas, width, height, outputBuffer, onSuccess, onFailure });\n });\n const pixels = new Uint8ClampedArray(outputBuffer);\n return new ImageData(pixels, width, height);\n};\n\nconst getRGBImageData = (output: HTMLCanvasElement, imageReader2D: CanvasRenderingContext2D | null): ImageData => {\n if (imageReader2D === null) return new ImageData(0, 0);\n imageReader2D.drawImage(output, 0, 0);\n return imageReader2D.getImageData(0, 0, output.width, output.height);\n};\n\nconst getImageBitmap = async (imageData: ImageData, format: FrameFormat): Promise<ImageBitmap> => {\n switch (format) {\n case \"nv12\":\n case \"yuv\":\n if (!window.VideoFrame)\n return Promise.reject(\n new Error(`Cannot process frame. ImageData in ${format} ` + `is not supported by this browser.`)\n );\n const frame = new VideoFrame(imageData.data.buffer, {\n format: \"NV12\",\n codedWidth: imageData.width,\n codedHeight: imageData.height,\n timestamp: 0,\n });\n return createImageBitmap(frame);\n case \"rgb\":\n return createImageBitmap(imageData);\n }\n};\n\n/** @internal */\nexport type FrameFormat = \"rgb\" | \"yuv\" | \"nv12\";\n\n/** @internal */\nexport interface FrameInput {\n format?: FrameFormat;\n imageData: ImageData;\n timestampMillis: number;\n}\n\n/** @internal */\nexport interface FrameOutput {\n live: ImageData;\n capture: ImageData;\n}\n\n/** @internal */\nexport interface MediaSourceFunction {\n (render: (frame: FrameInput) => Promise<FrameOutput>): Promise<void>;\n}\n\n/**\n * Creates a {@link CameraKitSource} from a function which provides per-frame pixel data to CameraKit.\n *\n * @param sourceFunction This function will be called in a requestAnimationFrame loop. Each time it is called, it is\n * passed a `render` function. It may call `render` and CameraKit will process the pixel data passed to `render` and\n * return a Promise of the processed pixels (along with rendering them to the normal output canvases).\n * @param options\n * @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.\n *\n * @internal\n */\nexport const createFunctionSource = (\n sourceFunction: MediaSourceFunction,\n options: Omit<CameraKitSourceOptions, \"fpsLimit\"> = {}\n): CameraKitSource => {\n let width = 0;\n let height = 0;\n let shouldProcessFrame = true;\n\n // We require an auxiliary canvas that we can use to read back pixel data (unless we're in YUV mode, in which case\n // we use LensCore to convert between formats and we don't need this canvas).\n const imageReaderCanvas = document.createElement(\"canvas\");\n const imageReader2D = imageReaderCanvas.getContext(\"2d\");\n\n const subscriber: CameraKitSourceSubscriber = {\n onAttach: (source, lensCore, reportError) => {\n const outputs = lensCore.getOutputCanvases();\n const output = {\n live: outputs[lensCore.CanvasType.Preview.value],\n capture: outputs[lensCore.CanvasType.Capture.value],\n };\n\n const processFrame = (\n source: CameraKitSource,\n lensCore: LensCoreModule,\n reportError: (error: Error) => void\n ) =>\n requestAnimationFrame(async () => {\n if (!shouldProcessFrame) return;\n try {\n await sourceFunction(({ format, imageData, timestampMillis }) => {\n const frameOutput = new Promise<FrameOutput>(async (resolve, reject) => {\n const inputFrame = await getImageBitmap(imageData, format ?? \"rgb\");\n if (inputFrame.width !== width || inputFrame.height !== height) {\n width = imageReaderCanvas.width = inputFrame.width;\n height = imageReaderCanvas.height = inputFrame.height;\n // We don't await this promise, because we want to continue to process frames and\n // let LensCore manage the concurrency between setting resolution and processing a\n // frame.\n source.setRenderSize(width, height);\n }\n lensCore.processFrame({\n inputFrame,\n timestampMillis,\n onSuccess: async () => {\n // Closing releases graphics resources associated with the frame, now that is\n // has been processed.\n inputFrame.close();\n\n switch (format ?? \"rgb\") {\n case \"nv12\":\n case \"yuv\":\n const [live, capture] = await Promise.all([\n getYUVImageData(output.live, lensCore),\n getYUVImageData(output.capture, lensCore),\n ]).catch((error) => {\n reject(error);\n return [undefined, undefined] as const;\n });\n // if either of these is undefined, we'll have already rejected\n // the promise, so we can return.\n if (!live || !capture) return;\n return resolve({ live, capture });\n case \"rgb\":\n return resolve({\n live: getRGBImageData(output.live, imageReader2D),\n capture: getRGBImageData(output.capture, imageReader2D),\n });\n }\n },\n onFailure: (error) => {\n inputFrame.close();\n reject(error);\n },\n });\n });\n // Even if there's an error processing the frame, we do want to attempt to process the next\n // frame. We expect `sourceFunction` to handle a rejected `frameOutput` Promise.\n frameOutput.finally(() => processFrame(source, lensCore, reportError));\n return frameOutput;\n });\n } catch (error) {\n reportError(\n new Error(\n \"Failure to process frame, which was not handled by the provided \" +\n `MediaSourceFunction ${sourceFunction.name ?? \"anonymous\"}.`,\n { cause: error }\n )\n );\n }\n });\n processFrame(source, lensCore, reportError);\n },\n onDetach: () => {\n shouldProcessFrame = false;\n },\n };\n\n return new CameraKitSource({ useManualFrameProcessing: true }, subscriber, options);\n};\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CameraKitSource, CameraKitSourceOptions } from "./CameraKitSource";
|
|
2
|
+
/**
|
|
3
|
+
* Create a {@link CameraKitSource} from an
|
|
4
|
+
* [HTMLImageElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement).
|
|
5
|
+
*
|
|
6
|
+
* @param image Image element.
|
|
7
|
+
* @param options
|
|
8
|
+
* @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.
|
|
9
|
+
* @param options.fpsLimit By default we set no limit on FPS.
|
|
10
|
+
*
|
|
11
|
+
* @category Rendering
|
|
12
|
+
*/
|
|
13
|
+
export declare function createImageSource(image: HTMLImageElement, options?: CameraKitSourceOptions): CameraKitSource;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CameraKitSource } from "./CameraKitSource";
|
|
2
|
+
/**
|
|
3
|
+
* Create a {@link CameraKitSource} from an
|
|
4
|
+
* [HTMLImageElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement).
|
|
5
|
+
*
|
|
6
|
+
* @param image Image element.
|
|
7
|
+
* @param options
|
|
8
|
+
* @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.
|
|
9
|
+
* @param options.fpsLimit By default we set no limit on FPS.
|
|
10
|
+
*
|
|
11
|
+
* @category Rendering
|
|
12
|
+
*/
|
|
13
|
+
export function createImageSource(image, options = {}) {
|
|
14
|
+
return new CameraKitSource({
|
|
15
|
+
media: image,
|
|
16
|
+
}, {
|
|
17
|
+
onAttach: (source) => {
|
|
18
|
+
// If the image element has no explicit width/height (which may be the case for elements that have not
|
|
19
|
+
// been added to the DOM or had their size set explicitly), we'll render at the image's native
|
|
20
|
+
// resolution.
|
|
21
|
+
const [width, height] = image.width === 0 || image.height === 0
|
|
22
|
+
? [image.naturalWidth, image.naturalHeight]
|
|
23
|
+
: [image.width, image.height];
|
|
24
|
+
return source.setRenderSize(width, height);
|
|
25
|
+
},
|
|
26
|
+
}, options);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=ImageSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImageSource.js","sourceRoot":"","sources":["../../src/media-sources/ImageSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAE5E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAuB,EAAE,UAAkC,EAAE;IAC3F,OAAO,IAAI,eAAe,CACtB;QACI,KAAK,EAAE,KAAK;KACf,EACD;QACI,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;YACjB,sGAAsG;YACtG,8FAA8F;YAC9F,cAAc;YACd,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GACjB,KAAK,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBACnC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,aAAa,CAAC;gBAC3C,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YAEtC,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;KACJ,EACD,OAAO,CACV,CAAC;AACN,CAAC","sourcesContent":["import { CameraKitSource, CameraKitSourceOptions } from \"./CameraKitSource\";\n\n/**\n * Create a {@link CameraKitSource} from an\n * [HTMLImageElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement).\n *\n * @param image Image element.\n * @param options\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.\n *\n * @category Rendering\n */\nexport function createImageSource(image: HTMLImageElement, options: CameraKitSourceOptions = {}): CameraKitSource {\n return new CameraKitSource(\n {\n media: image,\n },\n {\n onAttach: (source) => {\n // If the image element has no explicit width/height (which may be the case for elements that have not\n // been added to the DOM or had their size set explicitly), we'll render at the image's native\n // resolution.\n const [width, height] =\n image.width === 0 || image.height === 0\n ? [image.naturalWidth, image.naturalHeight]\n : [image.width, image.height];\n\n return source.setRenderSize(width, height);\n },\n },\n options\n );\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Transform2D } from "../transforms";
|
|
2
|
+
import { CameraKitSource, CameraKitSourceOptions } from "./CameraKitSource";
|
|
3
|
+
/** @category Rendering */
|
|
4
|
+
export interface MediaStreamSourceOptions {
|
|
5
|
+
transform: Transform2D;
|
|
6
|
+
disableSourceAudio: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Create a {@link CameraKitSource} from a user's media device -- this calls
|
|
10
|
+
* [MediaDevices.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) to get a
|
|
11
|
+
* MediaStream and then calls {@link createMediaStreamSource}.
|
|
12
|
+
*
|
|
13
|
+
* @param constraints Specify contraints used to get a MediaStream from a media device. By default we simply request
|
|
14
|
+
* a video stream.
|
|
15
|
+
* @param options
|
|
16
|
+
* @param options.transform By default we horizontally mirror the video stream. The most common use-case is to obtain a
|
|
17
|
+
* stream from a front-facing web cam, which requires mirroring to be viewed naturally.
|
|
18
|
+
* @param options.cameraType By default we set this to 'front' to indicate a camera pointed at the user (e.g. a webcam).
|
|
19
|
+
* @param options.fpsLimit By default we set no limit on FPS – if the source device has a known FPS setting this limit
|
|
20
|
+
* may prevent CameraKit from using more compute resources than strictly necessary.
|
|
21
|
+
* @returns A Promise, resolving to {@link CameraKitSource}
|
|
22
|
+
*
|
|
23
|
+
* @category Rendering
|
|
24
|
+
*/
|
|
25
|
+
export declare function createUserMediaSource(constraints?: MediaStreamConstraints, options?: CameraKitSourceOptions<MediaStreamSourceOptions>): Promise<CameraKitSource>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a {@link CameraKitSource} from any
|
|
28
|
+
* [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).
|
|
29
|
+
*
|
|
30
|
+
* @param stream Any MediaStream, such as obtained via `canvas.captureStream()`
|
|
31
|
+
* @param options
|
|
32
|
+
* @param options.transform We apply no transformation by default.
|
|
33
|
+
* @param options.disableSourceAudio By default we pass audio to lens. Settings this to true will disable sending audio
|
|
34
|
+
* to the lens.
|
|
35
|
+
* @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.
|
|
36
|
+
* @param options.fpsLimit By default we set no limit on FPS – if the MediaStream has a known FPS setting this limit
|
|
37
|
+
* may prevent CameraKit from using more compute resources than strictly necessary.
|
|
38
|
+
*
|
|
39
|
+
* @category Rendering
|
|
40
|
+
*/
|
|
41
|
+
export declare function createMediaStreamSource(stream: MediaStream, options?: CameraKitSourceOptions<MediaStreamSourceOptions>): CameraKitSource;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { Transform2D } from "../transforms";
|
|
3
|
+
import { CameraKitSource } from "./CameraKitSource";
|
|
4
|
+
const defaultOptions = {
|
|
5
|
+
transform: Transform2D.Identity,
|
|
6
|
+
disableSourceAudio: false,
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Create a {@link CameraKitSource} from a user's media device -- this calls
|
|
10
|
+
* [MediaDevices.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) to get a
|
|
11
|
+
* MediaStream and then calls {@link createMediaStreamSource}.
|
|
12
|
+
*
|
|
13
|
+
* @param constraints Specify contraints used to get a MediaStream from a media device. By default we simply request
|
|
14
|
+
* a video stream.
|
|
15
|
+
* @param options
|
|
16
|
+
* @param options.transform By default we horizontally mirror the video stream. The most common use-case is to obtain a
|
|
17
|
+
* stream from a front-facing web cam, which requires mirroring to be viewed naturally.
|
|
18
|
+
* @param options.cameraType By default we set this to 'front' to indicate a camera pointed at the user (e.g. a webcam).
|
|
19
|
+
* @param options.fpsLimit By default we set no limit on FPS – if the source device has a known FPS setting this limit
|
|
20
|
+
* may prevent CameraKit from using more compute resources than strictly necessary.
|
|
21
|
+
* @returns A Promise, resolving to {@link CameraKitSource}
|
|
22
|
+
*
|
|
23
|
+
* @category Rendering
|
|
24
|
+
*/
|
|
25
|
+
export function createUserMediaSource(constraints = { video: true }, options = {}) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const stream = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
28
|
+
return createMediaStreamSource(stream, Object.assign({ transform: Transform2D.MirrorX, cameraType: "front" }, options));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a {@link CameraKitSource} from any
|
|
33
|
+
* [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).
|
|
34
|
+
*
|
|
35
|
+
* @param stream Any MediaStream, such as obtained via `canvas.captureStream()`
|
|
36
|
+
* @param options
|
|
37
|
+
* @param options.transform We apply no transformation by default.
|
|
38
|
+
* @param options.disableSourceAudio By default we pass audio to lens. Settings this to true will disable sending audio
|
|
39
|
+
* to the lens.
|
|
40
|
+
* @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.
|
|
41
|
+
* @param options.fpsLimit By default we set no limit on FPS – if the MediaStream has a known FPS setting this limit
|
|
42
|
+
* may prevent CameraKit from using more compute resources than strictly necessary.
|
|
43
|
+
*
|
|
44
|
+
* @category Rendering
|
|
45
|
+
*/
|
|
46
|
+
export function createMediaStreamSource(stream, options = {}) {
|
|
47
|
+
const optionsNotNull = Object.assign(Object.assign({}, defaultOptions), options);
|
|
48
|
+
const { width, height } = stream.getVideoTracks().length > 0 ? stream.getVideoTracks()[0].getSettings() : { width: 0, height: 0 };
|
|
49
|
+
const enableSourceAudio = stream.getAudioTracks().length > 0 && !optionsNotNull.disableSourceAudio;
|
|
50
|
+
const simulateStereoAudio = true;
|
|
51
|
+
const sampleRate = 44100;
|
|
52
|
+
let audioContext = undefined;
|
|
53
|
+
let audioSource = undefined;
|
|
54
|
+
let microphoneRecorderUrl;
|
|
55
|
+
if (enableSourceAudio) {
|
|
56
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_AudioWorklet
|
|
57
|
+
const microphoneRecorderWorklet = `
|
|
58
|
+
class MicrophoneWorkletProcessor extends AudioWorkletProcessor {
|
|
59
|
+
process(inputs, outputs, parameters) {
|
|
60
|
+
this.port.postMessage({
|
|
61
|
+
eventType: 'data',
|
|
62
|
+
buffer: inputs
|
|
63
|
+
});
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
registerProcessor('microphone-worklet', MicrophoneWorkletProcessor);`;
|
|
68
|
+
const microphoneRecorderBlob = new Blob([microphoneRecorderWorklet], {
|
|
69
|
+
type: "application/javascript",
|
|
70
|
+
});
|
|
71
|
+
microphoneRecorderUrl = URL.createObjectURL(microphoneRecorderBlob);
|
|
72
|
+
}
|
|
73
|
+
return new CameraKitSource({ media: stream }, {
|
|
74
|
+
onAttach: (source, lensCore, reportError) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
if (width !== undefined && height !== undefined)
|
|
76
|
+
yield source.setRenderSize(width, height);
|
|
77
|
+
yield source.setTransform(optionsNotNull.transform);
|
|
78
|
+
if (enableSourceAudio) {
|
|
79
|
+
// Audio paramters set has to be called before lens is applied
|
|
80
|
+
lensCore.setAudioParameters({
|
|
81
|
+
parameters: {
|
|
82
|
+
numChannels: simulateStereoAudio ? 2 : 1,
|
|
83
|
+
sampleRate,
|
|
84
|
+
},
|
|
85
|
+
onFailure: (error) => {
|
|
86
|
+
reportError(error);
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
if (audioContext) {
|
|
90
|
+
yield audioContext.close();
|
|
91
|
+
}
|
|
92
|
+
audioContext = new AudioContext();
|
|
93
|
+
audioSource = audioContext.createMediaStreamSource(stream);
|
|
94
|
+
const scopedAudioSource = audioSource;
|
|
95
|
+
audioContext.audioWorklet
|
|
96
|
+
.addModule(microphoneRecorderUrl)
|
|
97
|
+
.then(() => {
|
|
98
|
+
if (audioContext) {
|
|
99
|
+
const worklet = new AudioWorkletNode(audioContext, "microphone-worklet");
|
|
100
|
+
scopedAudioSource.connect(worklet);
|
|
101
|
+
worklet.connect(audioContext.destination);
|
|
102
|
+
// NOTE: We subscribe to messages here, and they will continue to arrive
|
|
103
|
+
// even after audioContext.close() is called. To disconnect the audio worklets
|
|
104
|
+
// created here, we need to track another variable - audioSource.
|
|
105
|
+
// By calling audioSource.disconnect(), we can properly
|
|
106
|
+
// disconnect the audio worklets.
|
|
107
|
+
worklet.port.onmessage = (e) => {
|
|
108
|
+
if (e.data.eventType === "data") {
|
|
109
|
+
// developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor/process
|
|
110
|
+
// inputs[n][m] is the list of samples in the n-th input at the m-th channel.
|
|
111
|
+
const leftSamples = e.data.buffer[0][0];
|
|
112
|
+
let inputBuffers = [leftSamples];
|
|
113
|
+
if (simulateStereoAudio) {
|
|
114
|
+
const rightSamples = e.data.buffer[0].length > 1 ? e.data.buffer[0][1] : leftSamples.slice();
|
|
115
|
+
inputBuffers.push(rightSamples);
|
|
116
|
+
}
|
|
117
|
+
lensCore.processAudioSampleBuffer({
|
|
118
|
+
input: inputBuffers,
|
|
119
|
+
onFailure: (error) => {
|
|
120
|
+
reportError(error);
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
.catch((error) => {
|
|
128
|
+
reportError(error);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}),
|
|
132
|
+
onDetach: (reportError) => __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
if (audioSource) {
|
|
134
|
+
audioSource.disconnect();
|
|
135
|
+
audioSource = undefined;
|
|
136
|
+
}
|
|
137
|
+
if (audioContext) {
|
|
138
|
+
yield audioContext.close().catch((error) => {
|
|
139
|
+
reportError(error);
|
|
140
|
+
});
|
|
141
|
+
audioContext = undefined;
|
|
142
|
+
}
|
|
143
|
+
}),
|
|
144
|
+
}, options);
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=MediaStreamSource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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"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CameraKitSource, CameraKitSourceOptions } from "./CameraKitSource";
|
|
2
|
+
/** @category Rendering */
|
|
3
|
+
export interface VideoSourceOptions {
|
|
4
|
+
trackingData: ArrayBuffer;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Create a {@link CameraKitSource} from an
|
|
8
|
+
* [HTMLVideoElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement).
|
|
9
|
+
*
|
|
10
|
+
* @param video CameraKit performs best when the source video is 720p – arbitrary resolutions are supported, but very
|
|
11
|
+
* high resolutions may not perform well.
|
|
12
|
+
* @param options
|
|
13
|
+
* @param options.trackingData If pre-computed tracking data exists for this video, it may be provided in order to boost
|
|
14
|
+
* rendering performance (it is not typical or expected for this to be provided).
|
|
15
|
+
* @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.
|
|
16
|
+
* @param options.fpsLimit By default we set no limit on FPS – if the video has a known FPS setting this limit
|
|
17
|
+
* may prevent CameraKit from using more compute resources than strictly necessary.
|
|
18
|
+
*
|
|
19
|
+
* @category Rendering
|
|
20
|
+
*/
|
|
21
|
+
export declare function createVideoSource(video: HTMLVideoElement, options?: CameraKitSourceOptions<VideoSourceOptions>): CameraKitSource;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CameraKitSource } from "./CameraKitSource";
|
|
2
|
+
const defaultOptions = {
|
|
3
|
+
trackingData: new ArrayBuffer(0),
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Create a {@link CameraKitSource} from an
|
|
7
|
+
* [HTMLVideoElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement).
|
|
8
|
+
*
|
|
9
|
+
* @param video CameraKit performs best when the source video is 720p – arbitrary resolutions are supported, but very
|
|
10
|
+
* high resolutions may not perform well.
|
|
11
|
+
* @param options
|
|
12
|
+
* @param options.trackingData If pre-computed tracking data exists for this video, it may be provided in order to boost
|
|
13
|
+
* rendering performance (it is not typical or expected for this to be provided).
|
|
14
|
+
* @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.
|
|
15
|
+
* @param options.fpsLimit By default we set no limit on FPS – if the video has a known FPS setting this limit
|
|
16
|
+
* may prevent CameraKit from using more compute resources than strictly necessary.
|
|
17
|
+
*
|
|
18
|
+
* @category Rendering
|
|
19
|
+
*/
|
|
20
|
+
export function createVideoSource(video, options = {}) {
|
|
21
|
+
const { trackingData } = Object.assign(Object.assign({}, defaultOptions), options);
|
|
22
|
+
const replayTrackingData = trackingData.byteLength > 0 ? { buffer: trackingData } : undefined;
|
|
23
|
+
return new CameraKitSource({
|
|
24
|
+
media: video,
|
|
25
|
+
replayTrackingData,
|
|
26
|
+
}, {
|
|
27
|
+
onAttach: (source) => {
|
|
28
|
+
// If the video element has no explicit width/height (which may be the case for elements that have not
|
|
29
|
+
// been added to the DOM or had their size set explicitly), we'll render at the video's native
|
|
30
|
+
// resolution.
|
|
31
|
+
const [width, height] = video.width === 0 || video.height === 0
|
|
32
|
+
? [video.videoWidth, video.videoHeight]
|
|
33
|
+
: [video.width, video.height];
|
|
34
|
+
return source.setRenderSize(width, height);
|
|
35
|
+
},
|
|
36
|
+
}, options);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=VideoSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VideoSource.js","sourceRoot":"","sources":["../../src/media-sources/VideoSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAE5E,MAAM,cAAc,GAAuB;IACvC,YAAY,EAAE,IAAI,WAAW,CAAC,CAAC,CAAC;CACnC,CAAC;AAOF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAC7B,KAAuB,EACvB,UAAsD,EAAE;IAExD,MAAM,EAAE,YAAY,EAAE,mCAAQ,cAAc,GAAK,OAAO,CAAE,CAAC;IAC3D,MAAM,kBAAkB,GAAG,YAAY,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9F,OAAO,IAAI,eAAe,CACtB;QACI,KAAK,EAAE,KAAK;QACZ,kBAAkB;KACrB,EACD;QACI,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;YACjB,sGAAsG;YACtG,8FAA8F;YAC9F,cAAc;YACd,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GACjB,KAAK,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBACnC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,WAAW,CAAC;gBACvC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YAEtC,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;KACJ,EACD,OAAO,CACV,CAAC;AACN,CAAC","sourcesContent":["import { CameraKitSource, CameraKitSourceOptions } from \"./CameraKitSource\";\n\nconst defaultOptions: VideoSourceOptions = {\n trackingData: new ArrayBuffer(0),\n};\n\n/** @category Rendering */\nexport interface VideoSourceOptions {\n trackingData: ArrayBuffer;\n}\n\n/**\n * Create a {@link CameraKitSource} from an\n * [HTMLVideoElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement).\n *\n * @param video CameraKit performs best when the source video is 720p – arbitrary resolutions are supported, but very\n * high resolutions may not perform well.\n * @param options\n * @param options.trackingData If pre-computed tracking data exists for this video, it may be provided in order to boost\n * rendering performance (it is not typical or expected for this to be provided).\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 video 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 createVideoSource(\n video: HTMLVideoElement,\n options: CameraKitSourceOptions<VideoSourceOptions> = {}\n): CameraKitSource {\n const { trackingData } = { ...defaultOptions, ...options };\n const replayTrackingData = trackingData.byteLength > 0 ? { buffer: trackingData } : undefined;\n\n return new CameraKitSource(\n {\n media: video,\n replayTrackingData,\n },\n {\n onAttach: (source) => {\n // If the video element has no explicit width/height (which may be the case for elements that have not\n // been added to the DOM or had their size set explicitly), we'll render at the video's native\n // resolution.\n const [width, height] =\n video.width === 0 || video.height === 0\n ? [video.videoWidth, video.videoHeight]\n : [video.width, video.height];\n\n return source.setRenderSize(width, height);\n },\n },\n options\n );\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { FetchHandler } from "../handlers/defaultFetchHandler";
|
|
2
|
+
import * as blizzard from "../generated-proto/blizzard/cameraKitEvents";
|
|
3
|
+
import { MetricsEventTarget } from "./metricsEventTarget";
|
|
4
|
+
/**
|
|
5
|
+
* Translate between an external metric name, which is exposed to SDK users, and an internal Blizzard event name,
|
|
6
|
+
* property name, and constructor.
|
|
7
|
+
*
|
|
8
|
+
* It is very important that we do this, since the naming of these internal business events are unintuitive and will
|
|
9
|
+
* not make sense to SDK users.
|
|
10
|
+
*
|
|
11
|
+
* For a full list of business events (using their internal names), see:
|
|
12
|
+
* https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/
|
|
13
|
+
*/
|
|
14
|
+
declare type CameraKitBusinessEventMap = {
|
|
15
|
+
assetDownload: MakeBusinessEvent<blizzard.CameraKitAssetDownload>;
|
|
16
|
+
assetValidationFailed: MakeBusinessEvent<blizzard.CameraKitAssetValidationFailed>;
|
|
17
|
+
benchmarkComplete: MakeBusinessEvent<blizzard.CameraKitWebBenchmarkComplete>;
|
|
18
|
+
exception: MakeBusinessEvent<blizzard.CameraKitException>;
|
|
19
|
+
legalPrompt: MakeBusinessEvent<blizzard.CameraKitLegalPrompt>;
|
|
20
|
+
lensDownload: MakeBusinessEvent<blizzard.CameraKitLensDownload>;
|
|
21
|
+
lensView: MakeBusinessEvent<blizzard.CameraKitWebLensSwipe>;
|
|
22
|
+
lensWait: MakeBusinessEvent<blizzard.CameraKitLensSpin>;
|
|
23
|
+
lensContentValidationFailed: MakeBusinessEvent<blizzard.CameraKitLensContentValidationFailed>;
|
|
24
|
+
session: MakeBusinessEvent<blizzard.CameraKitSession>;
|
|
25
|
+
};
|
|
26
|
+
export declare type MakeBusinessEvent<E> = Omit<{
|
|
27
|
+
[K in keyof E]: Exclude<E[K], undefined> extends Record<keyof any, any> ? MakeBusinessEvent<Exclude<E[K], undefined>> : E[K];
|
|
28
|
+
}, "cameraKitEventBase">;
|
|
29
|
+
export declare type MakeTaggedBusinessEvent<K extends keyof CameraKitBusinessEventMap> = {
|
|
30
|
+
name: K;
|
|
31
|
+
} & CameraKitBusinessEventMap[K];
|
|
32
|
+
export declare const businessEventsReporterFactory: {
|
|
33
|
+
(args_0: MetricsEventTarget, args_1: FetchHandler<Response>): void;
|
|
34
|
+
token: "businessEventsReporter";
|
|
35
|
+
dependencies: readonly ["metricsEventTarget", "metricsHandler"];
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { v4 } from "uuid";
|
|
2
|
+
import { cameraKitUserAgent as userAgent } from "../common/cameraKitUserAgent";
|
|
3
|
+
import { entries } from "../common/entries";
|
|
4
|
+
import { Injectable } from "../dependency-injection/Injectable";
|
|
5
|
+
import { createBatchingHandler } from "../handlers/batchingHandler";
|
|
6
|
+
import { HandlerChainBuilder } from "../handlers/HandlerChainBuilder";
|
|
7
|
+
import { createMappingHandler } from "../handlers/mappingHandler";
|
|
8
|
+
import * as blizzard from "../generated-proto/blizzard/cameraKitEvents";
|
|
9
|
+
import { getLogger } from "../logger/logger";
|
|
10
|
+
import { metricsHandlerFactory } from "./metricsHandler";
|
|
11
|
+
import { metricsEventTargetFactory } from "./metricsEventTarget";
|
|
12
|
+
const logger = getLogger("BusinessEventsReporter");
|
|
13
|
+
// CameraKit's prod metrics endpoint.
|
|
14
|
+
// See: https://github.sc-corp.net/Snapchat/pb_schema/blob/2a966db/proto/camera_kit/v3/service.proto#L133
|
|
15
|
+
const BUSINESS_EVENTS_ENDPOINT = "https://api-kit.snapchat.com/com.snap.camerakit.v3.Metrics/metrics/business_events";
|
|
16
|
+
// These values are (currently) arbitrarily selected.
|
|
17
|
+
// TODO: Once we have gathered a sufficient quantity of metrics data, we should tune these numbers to ensure we're
|
|
18
|
+
// operating with the right cost vs. staying under the `keepalive` request body limit of 64 kibibytes.
|
|
19
|
+
const BUSINESS_EVENT_BATCH_MAX_SIZE = 100;
|
|
20
|
+
const BUSINESS_EVENT_BATCH_MAX_AGE_MS = 5000;
|
|
21
|
+
function listenAndReport(metricsEventTarget, metricsHandler, eventHandlers) {
|
|
22
|
+
const sessionId = v4();
|
|
23
|
+
logger.log(`Session ID: ${sessionId}`);
|
|
24
|
+
const handler = new HandlerChainBuilder(metricsHandler)
|
|
25
|
+
.map(createMappingHandler((events) => {
|
|
26
|
+
const body = {
|
|
27
|
+
batchEvents: {
|
|
28
|
+
"@type": "com.snapchat.analytics.blizzard.ServerEventBatch",
|
|
29
|
+
serverEvents: events,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
return new Request(BUSINESS_EVENTS_ENDPOINT, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
body: JSON.stringify(body),
|
|
35
|
+
credentials: "include",
|
|
36
|
+
// Setting this to true makes fetch behave like `Navigator.sendBeacon` – that is, the request
|
|
37
|
+
// will still be made even if the page terminates.
|
|
38
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
|
39
|
+
keepalive: true,
|
|
40
|
+
});
|
|
41
|
+
}))
|
|
42
|
+
.map(createBatchingHandler({
|
|
43
|
+
batchReduce: (previousBundle, businessEvent) => {
|
|
44
|
+
const bundle = previousBundle !== null && previousBundle !== void 0 ? previousBundle : [];
|
|
45
|
+
bundle.push(businessEvent);
|
|
46
|
+
return bundle;
|
|
47
|
+
},
|
|
48
|
+
isBatchComplete: (bundle) => bundle.length >= BUSINESS_EVENT_BATCH_MAX_SIZE,
|
|
49
|
+
maxBatchAge: BUSINESS_EVENT_BATCH_MAX_AGE_MS,
|
|
50
|
+
})).handler;
|
|
51
|
+
const makeBlizzardEvent = (event) => {
|
|
52
|
+
return Object.assign(Object.assign({}, event), { cameraKitEventBase: blizzard.CameraKitEventBase.fromPartial({
|
|
53
|
+
kitEventBase: blizzard.KitEventBase.fromPartial({
|
|
54
|
+
locale: userAgent.locale,
|
|
55
|
+
kitVariant: blizzard.KitType.CAMERA_KIT_WEB,
|
|
56
|
+
kitVariantVersion: userAgent.sdkShortVersion,
|
|
57
|
+
kitClientTimestampMillis: Date.now(),
|
|
58
|
+
}),
|
|
59
|
+
deviceCluster: 0,
|
|
60
|
+
cameraKitVersion: userAgent.sdkLongVersion,
|
|
61
|
+
lensCoreVersion: userAgent.lensCoreVersion,
|
|
62
|
+
deviceModel: userAgent.deviceModel,
|
|
63
|
+
cameraKitVariant: blizzard.CameraKitVariant.CAMERA_KIT_VARIANT_PARTNER,
|
|
64
|
+
cameraKitFlavor: blizzard.CameraKitFlavor.CAMERA_KIT_FLAVOR_DEBUG,
|
|
65
|
+
// We overload appId, using the origin instead because it's nice and human-readable (our backed adds
|
|
66
|
+
// the true appId as oauth_client_id before forwarding events to Blizzard).
|
|
67
|
+
appId: userAgent.origin,
|
|
68
|
+
deviceConnectivity: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_WIFI,
|
|
69
|
+
sessionId: sessionId,
|
|
70
|
+
}) });
|
|
71
|
+
};
|
|
72
|
+
const sendServerEvent = (eventName, eventData) => {
|
|
73
|
+
return handler(blizzard.ServerEvent.fromPartial({
|
|
74
|
+
eventName,
|
|
75
|
+
osType: userAgent.osType,
|
|
76
|
+
osVersion: userAgent.osVersion,
|
|
77
|
+
maxSequenceIdOnInstance: 0,
|
|
78
|
+
sequenceId: 0,
|
|
79
|
+
eventData,
|
|
80
|
+
}));
|
|
81
|
+
};
|
|
82
|
+
entries(eventHandlers).forEach(([eventType, createEventData]) => {
|
|
83
|
+
metricsEventTarget.addEventListener(eventType, ({ detail }) => {
|
|
84
|
+
// Safety: When iterating over object keys in a mapped type, we lose the association between the key type
|
|
85
|
+
// and the value type – at each iteration, the key type is a union of all possible keys and the value type
|
|
86
|
+
// is a union of all possible values. When the value is a function with an argument, and that argument
|
|
87
|
+
// depends on the key type (which is a union), the contravariance of the argument type means that the union
|
|
88
|
+
// becomes an intersection. In our case here, this means the compiler expects each argument to contain all
|
|
89
|
+
// properties from all event types. The cast is safe because the mapped `EventHandlers` type ensures that
|
|
90
|
+
// `createEventData` takes an argument of the type corresponding its key's `eventType`'s event detail.
|
|
91
|
+
const [eventName, eventData] = createEventData(makeBlizzardEvent(detail));
|
|
92
|
+
sendServerEvent(eventName, eventData);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
export const businessEventsReporterFactory = Injectable("businessEventsReporter", [metricsEventTargetFactory.token, metricsHandlerFactory.token], (metricsEventTarget, metricsHandler) => {
|
|
97
|
+
/**
|
|
98
|
+
* This defines a mapping from a business event's external name (the name we document in public API docs), to
|
|
99
|
+
* its internal representation as a Blizzard ServerEvent.
|
|
100
|
+
*
|
|
101
|
+
* It is important that we do this, since the naming of these internal business events are unintuitive and will
|
|
102
|
+
* not make sense to SDK users.
|
|
103
|
+
*
|
|
104
|
+
* To specify the internal event, we must give the ServerEvent's eventName, the specific property name which
|
|
105
|
+
* contains the event data (this is a "oneof" property on ServerEvent), and use the correct event type's
|
|
106
|
+
* `fromPartial` method (this is generated from the ServerEvent protobuf).
|
|
107
|
+
*
|
|
108
|
+
* These events are documented here:
|
|
109
|
+
* https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/
|
|
110
|
+
*
|
|
111
|
+
* They are defined in code here:
|
|
112
|
+
* https://github.sc-corp.net/Snapchat/snapchat/tree/master/blizzard/schema/blizzard-schema/
|
|
113
|
+
* codeGen/src/main/java/com/snapchat/analytics/schema/events/cameraKit
|
|
114
|
+
*/
|
|
115
|
+
listenAndReport(metricsEventTarget, metricsHandler, {
|
|
116
|
+
assetDownload: (event) => [
|
|
117
|
+
"CAMERA_KIT_ASSET_DOWNLOAD",
|
|
118
|
+
{ cameraKitAssetDownload: blizzard.CameraKitAssetDownload.fromPartial(event) },
|
|
119
|
+
],
|
|
120
|
+
assetValidationFailed: (event) => [
|
|
121
|
+
"CAMERA_KIT_ASSET_VALIDATION_FAILED",
|
|
122
|
+
{ cameraKitAssetValidationFailed: blizzard.CameraKitAssetValidationFailed.fromPartial(event) },
|
|
123
|
+
],
|
|
124
|
+
benchmarkComplete: (event) => [
|
|
125
|
+
"CAMERA_KIT_WEB_BENCHMARK_COMPLETE",
|
|
126
|
+
{ cameraKitWebBenchmarkComplete: blizzard.CameraKitWebBenchmarkComplete.fromPartial(event) },
|
|
127
|
+
],
|
|
128
|
+
exception: (event) => [
|
|
129
|
+
"CAMERA_KIT_EXCEPTION",
|
|
130
|
+
{ cameraKitException: blizzard.CameraKitException.fromPartial(event) },
|
|
131
|
+
],
|
|
132
|
+
legalPrompt: (event) => [
|
|
133
|
+
"CAMERA_KIT_LEGAL_PROMPT",
|
|
134
|
+
{ cameraKitLegalPrompt: blizzard.CameraKitLegalPrompt.fromPartial(event) },
|
|
135
|
+
],
|
|
136
|
+
lensDownload: (event) => [
|
|
137
|
+
"CAMERA_KIT_LENS_DOWNLOAD",
|
|
138
|
+
{ cameraKitLensDownload: blizzard.CameraKitLensDownload.fromPartial(event) },
|
|
139
|
+
],
|
|
140
|
+
lensView: (event) => [
|
|
141
|
+
"CAMERA_KIT_WEB_LENS_SWIPE",
|
|
142
|
+
{ cameraKitWebLensSwipe: blizzard.CameraKitWebLensSwipe.fromPartial(event) },
|
|
143
|
+
],
|
|
144
|
+
lensWait: (event) => [
|
|
145
|
+
"CAMERA_KIT_LENS_SPIN",
|
|
146
|
+
{ cameraKitLensSpin: blizzard.CameraKitLensSpin.fromPartial(event) },
|
|
147
|
+
],
|
|
148
|
+
lensContentValidationFailed: (event) => [
|
|
149
|
+
"CAMERA_KIT_LENS_CONTENT_VALIDATION_FAILED",
|
|
150
|
+
{
|
|
151
|
+
cameraKitLensContentValidationFailed: blizzard.CameraKitLensContentValidationFailed.fromPartial(event),
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
session: (event) => [
|
|
155
|
+
"CAMERA_KIT_SESSION",
|
|
156
|
+
{ cameraKitSession: blizzard.CameraKitSession.fromPartial(event) },
|
|
157
|
+
],
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
//# sourceMappingURL=businessEventsReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAsB,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAErF,MAAM,MAAM,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AAC,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,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"]}
|