@snap/camera-kit 0.15.1 → 0.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/docs/html/assets/main.js +4 -3
- package/docs/html/assets/navigation.js +1 -0
- package/docs/html/assets/search.js +1 -1
- package/docs/html/assets/style.css +72 -25
- package/docs/html/classes/CameraKit.html +11 -196
- package/docs/html/classes/CameraKitSession.html +43 -366
- package/docs/html/classes/CameraKitSource.html +14 -223
- package/docs/html/classes/LensPerformanceMeasurement.html +9 -184
- package/docs/html/classes/LensPerformanceMetrics.html +7 -148
- package/docs/html/classes/LensRepository.html +17 -234
- package/docs/html/classes/Transform2D.html +7 -176
- package/docs/html/classes/TypedCustomEvent.html +4 -178
- package/docs/html/classes/TypedEventTarget.html +4 -209
- package/docs/html/enums/Lens_CameraFacing.html +5 -0
- package/docs/html/enums/UserData_Zodiac.html +15 -0
- package/docs/html/functions/ConcatInjectable.html +10 -193
- package/docs/html/functions/Injectable.html +9 -192
- package/docs/html/functions/bootstrapCameraKit.html +6 -147
- package/docs/html/functions/createExtension.html +6 -123
- package/docs/html/functions/createImageSource.html +4 -130
- package/docs/html/functions/createMediaStreamSource.html +4 -130
- package/docs/html/functions/createVideoSource.html +4 -130
- package/docs/html/functions/estimateLensPerformance.html +3 -120
- package/docs/html/functions/lensSourcesFactory.html +6 -127
- package/docs/html/functions/remoteApiServicesFactory.html +3 -121
- package/docs/html/hierarchy.html +1 -0
- package/docs/html/index.html +8 -165
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +11 -192
- package/docs/html/interfaces/CameraKitDeviceOptions.html +11 -0
- package/docs/html/interfaces/CameraKitSourceInfo.html +9 -0
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +3 -194
- package/docs/html/interfaces/ComputedFrameMetrics.html +2 -150
- package/docs/html/interfaces/CreateSessionOptions.html +5 -148
- package/docs/html/interfaces/EstimatedLensPerformance.html +3 -146
- package/docs/html/interfaces/FunctionSourceOptions.html +7 -0
- package/docs/html/interfaces/Lens.html +12 -205
- package/docs/html/interfaces/LensCreator.html +3 -0
- package/docs/html/interfaces/LensLaunchData.html +3 -179
- package/docs/html/interfaces/LensSource.html +3 -172
- package/docs/html/interfaces/LoadAssetRequest.html +13 -0
- package/docs/html/interfaces/MediaStreamSourceOptions.html +16 -138
- package/docs/html/interfaces/Preview.html +4 -141
- package/docs/html/interfaces/RemoteApiRequest.html +7 -162
- package/docs/html/interfaces/RemoteApiResponse.html +6 -155
- package/docs/html/interfaces/RemoteApiService.html +9 -171
- package/docs/html/interfaces/Snapcode.html +5 -148
- package/docs/html/interfaces/UriCancelRequest.html +2 -138
- package/docs/html/interfaces/UriRequest.html +2 -154
- package/docs/html/interfaces/UriResponse.html +2 -150
- package/docs/html/interfaces/VideoSourceOptions.html +15 -134
- package/docs/html/modules.html +57 -175
- package/docs/html/types/AssetLoader.html +5 -132
- package/docs/html/types/AssetResponse.html +1 -0
- package/docs/html/types/AssetTiming.html +2 -115
- package/docs/html/types/BenchmarkError.html +1 -112
- package/docs/html/types/BootstrapError.html +2 -115
- package/docs/html/types/CacheKeyNotFoundError.html +1 -112
- package/docs/html/types/CameraKitSessionEventListener.html +2 -115
- package/docs/html/types/CameraKitSessionEvents.html +2 -122
- package/docs/html/types/CameraKitSourceError.html +1 -112
- package/docs/html/types/ConfigurationError.html +2 -115
- package/docs/html/types/FetchHandler.html +1 -0
- package/docs/html/types/Keyboard.html +14 -194
- package/docs/html/types/KeyboardEvents.html +2 -124
- package/docs/html/types/LegalError.html +1 -112
- package/docs/html/types/LensAbortError.html +2 -115
- package/docs/html/types/LensAssetError.html +2 -115
- package/docs/html/types/LensContentValidationError.html +1 -112
- package/docs/html/types/LensError.html +1 -112
- package/docs/html/types/LensExecutionError.html +2 -115
- package/docs/html/types/LensImagePickerError.html +2 -115
- package/docs/html/types/LensLaunchParams.html +2 -0
- package/docs/html/types/LensMetricsEvents.html +2 -115
- package/docs/html/types/LensPerformanceCluster.html +1 -113
- package/docs/html/types/LensView.html +2 -115
- package/docs/html/types/LensWait.html +2 -115
- package/docs/html/types/Matrix.html +3 -0
- package/docs/html/types/PersistentStoreError.html +2 -115
- package/docs/html/types/PlatformNotSupportedError.html +2 -115
- package/docs/html/types/PublicContainer.html +2 -115
- package/docs/html/types/PublicServices.html +2 -0
- package/docs/html/types/RemoteApiCancelRequestHandler.html +2 -0
- package/docs/html/types/RemoteApiRequestHandler.html +2 -139
- package/docs/html/types/RemoteApiServices.html +1 -112
- package/docs/html/types/RemoteApiStatus.html +2 -115
- package/docs/html/types/RenderTarget.html +2 -115
- package/docs/html/types/Uri.html +1 -112
- package/docs/html/types/WebGLError.html +1 -112
- package/docs/html/variables/extensionRequestContext.html +2 -115
- package/docs/md/README.md +3 -3
- package/docs/md/classes/CameraKit.md +15 -15
- package/docs/md/classes/CameraKitSession.md +38 -38
- package/docs/md/classes/CameraKitSource.md +22 -30
- package/docs/md/classes/LensPerformanceMeasurement.md +10 -6
- package/docs/md/classes/LensPerformanceMetrics.md +2 -2
- package/docs/md/classes/LensRepository.md +18 -18
- package/docs/md/classes/Transform2D.md +7 -3
- package/docs/md/classes/TypedCustomEvent.md +10 -6
- package/docs/md/classes/TypedEventTarget.md +12 -8
- package/docs/md/enums/Lens_CameraFacing.md +36 -0
- package/docs/md/enums/UserData_Zodiac.md +106 -0
- package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +2 -2
- package/docs/md/interfaces/CameraKitDeviceOptions.md +41 -0
- package/docs/md/interfaces/CameraKitSourceInfo.md +43 -0
- package/docs/md/interfaces/CameraKitSourceSubscriber.md +7 -7
- 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/FunctionSourceOptions.md +22 -0
- package/docs/md/interfaces/Lens.md +4 -4
- package/docs/md/interfaces/LensCreator.md +17 -0
- package/docs/md/interfaces/LensLaunchData.md +6 -6
- package/docs/md/interfaces/LensSource.md +5 -5
- package/docs/md/interfaces/LoadAssetRequest.md +49 -0
- package/docs/md/interfaces/MediaStreamSourceOptions.md +46 -1
- package/docs/md/interfaces/Preview.md +1 -1
- package/docs/md/interfaces/RemoteApiRequest.md +2 -2
- package/docs/md/interfaces/RemoteApiResponse.md +2 -2
- package/docs/md/interfaces/RemoteApiService.md +1 -1
- package/docs/md/interfaces/Snapcode.md +1 -1
- package/docs/md/interfaces/UriCancelRequest.md +2 -2
- package/docs/md/interfaces/UriRequest.md +3 -3
- package/docs/md/interfaces/UriResponse.md +2 -2
- package/docs/md/interfaces/VideoSourceOptions.md +44 -1
- package/docs/md/modules.md +183 -201
- package/lib/CameraKit.d.ts +108 -108
- package/lib/CameraKit.js +1 -1
- package/lib/CameraKit.js.map +1 -1
- package/lib/bootstrapCameraKit.d.ts +4 -4
- package/lib/bootstrapCameraKit.js +18 -19
- package/lib/bootstrapCameraKit.js.map +1 -1
- package/lib/clients/createTsProtoClient.d.ts +5 -12
- package/lib/clients/createTsProtoClient.js +1 -2
- package/lib/clients/createTsProtoClient.js.map +1 -1
- package/lib/clients/grpcHandler.d.ts +7 -4
- package/lib/clients/grpcHandler.js +8 -5
- package/lib/clients/grpcHandler.js.map +1 -1
- package/lib/clients/lensesClient.d.ts +3 -3
- package/lib/clients/lensesClient.js +2 -2
- package/lib/clients/lensesClient.js.map +1 -1
- package/lib/clients/metricsClient.d.ts +26 -0
- package/lib/clients/metricsClient.js +120 -0
- package/lib/clients/metricsClient.js.map +1 -0
- package/lib/configuration.js +1 -1
- package/lib/configuration.js.map +1 -1
- package/lib/dependency-injection/Container.d.ts +1 -1
- package/lib/dependency-injection/Container.js +1 -1
- package/lib/dependency-injection/Container.js.map +1 -1
- package/lib/dependency-injection/Injectable.d.ts +6 -6
- package/lib/dependency-injection/Injectable.js.map +1 -1
- package/lib/dependency-injection/RootServices.d.ts +7 -8
- package/lib/dependency-injection/RootServices.js.map +1 -1
- package/lib/environment.d.ts +4 -0
- package/lib/environment.js +2 -0
- package/lib/environment.js.map +1 -0
- package/lib/extensions/RemoteApiServices.d.ts +2 -2
- package/lib/extensions/RemoteApiServices.js +11 -6
- package/lib/extensions/RemoteApiServices.js.map +1 -1
- package/lib/extensions/uriHandlersRegister.d.ts +4 -4
- package/lib/extensions/uriHandlersRegister.js +6 -6
- package/lib/extensions/uriHandlersRegister.js.map +1 -1
- package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +4330 -678
- package/lib/generated-proto/blizzard/cameraKitEvents.js +515 -72
- package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +3 -11
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +6 -156
- 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 +19 -19
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +13 -27
- 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 +0 -6
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +2 -83
- 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 +0 -22
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +0 -263
- 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 +30 -34
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +7 -73
- 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 +0 -6
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +0 -110
- 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 +48 -114
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +0 -225
- 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 +6 -6
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js +5 -19
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +1422 -1422
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +12 -12
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js +10 -24
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +207 -207
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +530 -530
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +10 -24
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
- package/lib/generated-proto/pb_schema/common/value.d.ts +6 -6
- package/lib/generated-proto/pb_schema/common/value.js +4 -18
- package/lib/generated-proto/pb_schema/common/value.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/api/http.d.ts +0 -6
- package/lib/generated-proto/pb_schema/google/api/http.js +0 -77
- package/lib/generated-proto/pb_schema/google/api/http.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +0 -2
- package/lib/generated-proto/pb_schema/google/protobuf/any.js +0 -44
- package/lib/generated-proto/pb_schema/google/protobuf/any.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +4830 -4896
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +10 -997
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +3 -5
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js +6 -35
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +6 -6
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js +10 -24
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +9 -9
- package/lib/generated-proto/pb_schema/lenses/remote_api/remote_api_service.d.ts +11 -11
- package/lib/generated-proto/pb_schema/lenses/remote_api/remote_api_service.js +6 -20
- package/lib/generated-proto/pb_schema/lenses/remote_api/remote_api_service.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +42 -42
- package/lib/generated-proto/pb_schema/lenses/snappable.js +14 -28
- package/lib/generated-proto/pb_schema/lenses/snappable.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +8 -8
- package/lib/generated-proto/pb_schema/lenses/user_data.js +8 -22
- package/lib/generated-proto/pb_schema/lenses/user_data.js.map +1 -1
- package/lib/handlers/defaultFetchHandler.d.ts +1 -1
- package/lib/handlers/defaultFetchHandler.js.map +1 -1
- package/lib/handlers/requestStateEmittingHandler.d.ts +5 -6
- package/lib/handlers/requestStateEmittingHandler.js +6 -8
- package/lib/handlers/requestStateEmittingHandler.js.map +1 -1
- package/lib/handlers/responseCachingHandler.d.ts +9 -10
- package/lib/handlers/responseCachingHandler.js +9 -3
- package/lib/handlers/responseCachingHandler.js.map +1 -1
- package/lib/handlers/utils.d.ts +12 -0
- package/lib/handlers/utils.js +19 -0
- package/lib/handlers/utils.js.map +1 -0
- package/lib/index.d.ts +21 -15
- package/lib/index.js +17 -12
- package/lib/index.js.map +1 -1
- package/lib/lens/Lens.d.ts +12 -2
- package/lib/lens/Lens.js +5 -0
- package/lib/lens/Lens.js.map +1 -1
- package/lib/lens/LensLaunchData.d.ts +6 -3
- package/lib/lens/LensLaunchData.js +2 -0
- package/lib/lens/LensLaunchData.js.map +1 -1
- package/lib/lens/LensPersistenceStore.d.ts +1 -1
- package/lib/lens/LensPersistenceStore.js +1 -1
- package/lib/lens/LensPersistenceStore.js.map +1 -1
- package/lib/lens/LensRepository.d.ts +5 -1
- package/lib/lens/LensRepository.js +9 -5
- package/lib/lens/LensRepository.js.map +1 -1
- package/lib/lens/LensSource.d.ts +2 -2
- package/lib/lens/LensSource.js +2 -2
- package/lib/lens/LensSource.js.map +1 -1
- package/lib/lens/assets/LensAssetRepository.d.ts +35 -4
- package/lib/lens/assets/LensAssetRepository.js +9 -9
- package/lib/lens/assets/LensAssetRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetsProvider.d.ts +1 -1
- package/lib/lens/assets/LensAssetsProvider.js +9 -4
- package/lib/lens/assets/LensAssetsProvider.js.map +1 -1
- package/lib/lens/assets/deviceDependentAssetLoader.js +3 -2
- package/lib/lens/assets/deviceDependentAssetLoader.js.map +1 -1
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.js +4 -3
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.js.map +1 -1
- package/lib/lens/assets/staticAssetLoader.js +5 -4
- package/lib/lens/assets/staticAssetLoader.js.map +1 -1
- package/lib/lens/cameraKitLensSource.js.map +1 -1
- package/lib/lens-client-interface/imagePicker.d.ts +2 -1
- package/lib/lens-client-interface/imagePicker.js.map +1 -1
- package/lib/lens-client-interface/lensClientInterface.d.ts +1 -1
- package/lib/lens-client-interface/lensClientInterface.js +1 -1
- package/lib/lens-client-interface/lensClientInterface.js.map +1 -1
- package/lib/lens-core-module/lensCore.d.ts +2 -1
- package/lib/lens-core-module/lensCore.js.map +1 -1
- package/lib/lens-core-module/loader/bootstrapURLs.d.ts +12 -0
- package/lib/lens-core-module/loader/bootstrapURLs.js +48 -0
- package/lib/lens-core-module/loader/bootstrapURLs.js.map +1 -0
- package/lib/lens-core-module/loader/lensCoreFactory.d.ts +0 -12
- package/lib/lens-core-module/loader/lensCoreFactory.js +4 -49
- package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -1
- package/lib/lensCoreWasmVersions.d.ts +6 -0
- package/lib/lensCoreWasmVersions.js +6 -0
- package/lib/lensCoreWasmVersions.js.map +1 -0
- package/lib/media-sources/CameraKitSource.d.ts +39 -17
- package/lib/media-sources/CameraKitSource.js +8 -2
- package/lib/media-sources/CameraKitSource.js.map +1 -1
- package/lib/media-sources/FunctionSource.d.ts +15 -4
- package/lib/media-sources/FunctionSource.js +1 -2
- package/lib/media-sources/FunctionSource.js.map +1 -1
- package/lib/media-sources/ImageSource.d.ts +3 -5
- package/lib/media-sources/ImageSource.js +1 -3
- package/lib/media-sources/ImageSource.js.map +1 -1
- package/lib/media-sources/MediaStreamSource.d.ts +17 -33
- package/lib/media-sources/MediaStreamSource.js +6 -41
- package/lib/media-sources/MediaStreamSource.js.map +1 -1
- package/lib/media-sources/VideoSource.d.ts +14 -10
- package/lib/media-sources/VideoSource.js +5 -11
- package/lib/media-sources/VideoSource.js.map +1 -1
- package/lib/metrics/businessEventsReporter.d.ts +3 -4
- package/lib/metrics/businessEventsReporter.js +11 -55
- package/lib/metrics/businessEventsReporter.js.map +1 -1
- package/lib/metrics/operational/Count.d.ts +2 -0
- package/lib/metrics/operational/Count.js +6 -1
- package/lib/metrics/operational/Count.js.map +1 -1
- package/lib/metrics/operational/Histogram.d.ts +1 -1
- package/lib/metrics/operational/Histogram.js +7 -3
- package/lib/metrics/operational/Histogram.js.map +1 -1
- package/lib/metrics/operational/Metric.js +2 -0
- package/lib/metrics/operational/Metric.js.map +1 -1
- package/lib/metrics/operational/Timer.d.ts +9 -6
- package/lib/metrics/operational/Timer.js +12 -26
- package/lib/metrics/operational/Timer.js.map +1 -1
- package/lib/metrics/reporters/reportBenchmarks.d.ts +3 -3
- package/lib/metrics/reporters/reportBenchmarks.js +6 -5
- package/lib/metrics/reporters/reportBenchmarks.js.map +1 -1
- package/lib/metrics/reporters/reportGlobalException.d.ts +4 -4
- package/lib/metrics/reporters/reportGlobalException.js +13 -11
- package/lib/metrics/reporters/reportGlobalException.js.map +1 -1
- package/lib/metrics/reporters/reportHttpMetrics.d.ts +3 -3
- package/lib/metrics/reporters/reportHttpMetrics.js +19 -16
- package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
- package/lib/metrics/reporters/reportLegalState.d.ts +3 -3
- package/lib/metrics/reporters/reportLegalState.js +7 -9
- package/lib/metrics/reporters/reportLegalState.js.map +1 -1
- package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +3 -3
- package/lib/metrics/reporters/reportLensAndAssetDownload.js +12 -12
- package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -1
- package/lib/metrics/reporters/reportLensView.d.ts +3 -3
- package/lib/metrics/reporters/reportLensView.js +6 -6
- package/lib/metrics/reporters/reportLensView.js.map +1 -1
- package/lib/metrics/reporters/reportLensWait.d.ts +2 -3
- package/lib/metrics/reporters/reportLensWait.js +1 -3
- package/lib/metrics/reporters/reportLensWait.js.map +1 -1
- package/lib/metrics/reporters/reportPlatformCapabilities.d.ts +3 -3
- package/lib/metrics/reporters/reportPlatformCapabilities.js +6 -5
- package/lib/metrics/reporters/reportPlatformCapabilities.js.map +1 -1
- package/lib/metrics/reporters/reportUserSession.js +3 -3
- package/lib/metrics/reporters/reportUserSession.js.map +1 -1
- package/lib/metrics/reporters/reporters.d.ts +2 -2
- package/lib/namedErrors.d.ts +1 -1
- package/lib/namedErrors.js +1 -1
- package/lib/namedErrors.js.map +1 -1
- package/lib/observable-operators/unsubscribed.d.ts +1 -1
- package/lib/observable-operators/unsubscribed.js +1 -1
- package/lib/observable-operators/unsubscribed.js.map +1 -1
- package/lib/platform/platformCapabilities.d.ts +1 -1
- package/lib/platform/platformCapabilities.js +9 -3
- package/lib/platform/platformCapabilities.js.map +1 -1
- package/lib/platform/platformInfo.d.ts +1 -0
- package/lib/platform/platformInfo.js +3 -3
- package/lib/platform/platformInfo.js.map +1 -1
- package/lib/remote-configuration/cofHandler.d.ts +3 -3
- package/lib/remote-configuration/cofHandler.js +6 -4
- package/lib/remote-configuration/cofHandler.js.map +1 -1
- package/lib/remote-configuration/preloadConfiguration.d.ts +1 -1
- package/lib/remote-configuration/preloadConfiguration.js +1 -1
- package/lib/remote-configuration/preloadConfiguration.js.map +1 -1
- package/lib/remote-configuration/remoteConfiguration.d.ts +7 -6
- package/lib/remote-configuration/remoteConfiguration.js +18 -15
- package/lib/remote-configuration/remoteConfiguration.js.map +1 -1
- package/lib/session/CameraKitSession.d.ts +8 -8
- package/lib/session/CameraKitSession.js +11 -9
- package/lib/session/CameraKitSession.js.map +1 -1
- package/lib/session/LensKeyboard.d.ts +2 -3
- package/lib/session/LensKeyboard.js.map +1 -1
- package/lib/session/LensPerformanceMeasurement.d.ts +1 -1
- package/lib/session/LensPerformanceMeasurement.js +3 -3
- package/lib/session/LensPerformanceMeasurement.js.map +1 -1
- package/lib/session/LensPerformanceMetrics.d.ts +1 -1
- package/lib/session/LensPerformanceMetrics.js.map +1 -1
- package/lib/session/lensState.d.ts +4 -4
- package/lib/session/lensState.js +10 -10
- package/lib/session/lensState.js.map +1 -1
- package/lib/transforms/Transform2D.d.ts +8 -3
- package/lib/transforms/Transform2D.js +1 -1
- package/lib/transforms/Transform2D.js.map +1 -1
- package/lib/utils.d.ts +3 -0
- package/lib/utils.js +4 -0
- package/lib/utils.js.map +1 -0
- package/package.json +27 -6
- package/docs/html/functions/createUserMediaSource.html +0 -138
- package/docs/html/functions/getRequiredBootstrapURLs.html +0 -130
- package/docs/html/types/CameraKitDeviceInfo.html +0 -125
- package/docs/html/types/CameraKitDeviceOptions.html +0 -120
- package/docs/html/types/CameraKitSourceInfo.html +0 -112
- package/docs/html/types/CameraKitSourceOptions.html +0 -118
- package/lib/common/index.d.ts +0 -2
- package/lib/common/index.js +0 -3
- package/lib/common/index.js.map +0 -1
- package/lib/environment.json +0 -1
- package/lib/handlers/index.d.ts +0 -2
- package/lib/handlers/index.js +0 -3
- package/lib/handlers/index.js.map +0 -1
- package/lib/lens-core-module/index.d.ts +0 -3
- package/lib/lens-core-module/index.js +0 -4
- package/lib/lens-core-module/index.js.map +0 -1
- package/lib/lens-core-module/loader/index.d.ts +0 -1
- package/lib/lens-core-module/loader/index.js +0 -2
- package/lib/lens-core-module/loader/index.js.map +0 -1
- package/lib/lensCoreWasmVersions.json +0 -5
- package/lib/metrics/metricsHandler.d.ts +0 -10
- package/lib/metrics/metricsHandler.js +0 -13
- package/lib/metrics/metricsHandler.js.map +0 -1
- package/lib/metrics/operational/operationalMetricsReporter.d.ts +0 -64
- package/lib/metrics/operational/operationalMetricsReporter.js +0 -144
- package/lib/metrics/operational/operationalMetricsReporter.js.map +0 -1
- package/lib/session/index.d.ts +0 -1
- package/lib/session/index.js +0 -2
- package/lib/session/index.js.map +0 -1
- package/lib/transforms/index.d.ts +0 -1
- package/lib/transforms/index.js +0 -2
- package/lib/transforms/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CameraKitSession.js","sourceRoot":"","sources":["../../src/session/CameraKitSession.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,EAAc,EAAE,EAAgB,SAAS,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACjG,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC3F,OAAO,EAAQ,MAAM,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MA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AI,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,CAAC,CACrG,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/member-ordering */\nimport { filter, firstValueFrom, map, Observable, of, Subscription, takeUntil, tap } from \"rxjs\";\nimport { dispatch, forActions, inStates, isAction, isState } from \"@snap/state-management\";\nimport { Lens, isLens } from \"../lens/Lens\";\nimport { CanvasType, LensCore } from \"../lens-core-module\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { lensCoreFactory } from \"../lens-core-module/loader/lensCoreFactory\";\nimport { LensLaunchData } from \"../lens/LensLaunchData\";\nimport { getTypeName, guard, validate } from \"../common/validate\";\nimport { TypedEventTarget } from \"../events/TypedEventTarget\";\nimport { TypedCustomEvent } from \"../events/TypedCustomEvent\";\nimport { CameraKitDeviceOptions, CameraKitSource } from \"../media-sources/CameraKitSource\";\nimport { cameraKitSourceError, LensExecutionError } from \"../namedErrors\";\nimport { createMediaStreamSource } from \"../media-sources/MediaStreamSource\";\nimport { createVideoSource } from \"../media-sources/VideoSource\";\nimport { getLogger, LogEntry } from \"../logger/logger\";\nimport { errorLoggingDecorator } from \"../logger/errorLoggingDecorator\";\nimport { logEntriesFactory } from \"../logger/logEntries\";\nimport { PageVisibility, pageVisibilityFactory } from \"../common/pageVisibility\";\nimport { LensPerformanceMetrics } from \"./LensPerformanceMetrics\";\nimport { lensStateFactory, LensState } from \"./lensState\";\nimport { SessionState, sessionStateFactory } from \"./sessionState\";\nimport { Keyboard, lensKeyboardFactory, LensKeyboard } from \"./LensKeyboard\";\nimport { CameraKitSessionEvents, isPublicLensError, isSessionError } from \"./CameraKitSessionEvents\";\n\nconst logger = getLogger(\"CameraKitSession\");\nconst log = errorLoggingDecorator(logger);\n\nfunction isOptionalRenderTarget(value: unknown): value is RenderTarget | undefined {\n return value === \"live\" || value === \"capture\" || value === undefined;\n}\n\n/**\n * Enumerates the supported render targets.\n *\n * Lenses may render to different render targets, as designed by the lens creator. In CameraKit, it's possible to choose\n * which render target to render, and the result for each target is available as a separate `<canvas>` element.\n *\n * @category Rendering\n * @category Lenses\n */\nexport type RenderTarget = \"live\" | \"capture\";\n\n/**\n * A CameraKitSession represents a single rendering pipeline connecting an input media source to output `<canvas>`\n * elements. When a Lens is applied to the session, CameraKit uses the Lens to transform the input media into rendered\n * output.\n *\n * CameraKitSession is the primary object that applications interact with when integrating the CameraKit SDK.\n *\n * A CameraKitSession instance is obtained by calling {@link CameraKit.createSession}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * const session = await cameraKit.createSession()\n * ```\n *\n * @category Rendering\n * @category Lenses\n */\nexport class CameraKitSession {\n /**\n * CameraKitSession renders video output to a `<canvas>` element. In fact, each session contains two canvas outputs\n * corresponding to the RenderTargets used by Lens creators, when using LensStudio to create a Lens.\n *\n * The `live` output renders content suitable for the Lens user (e.g. it may contain additional UI elements\n * applicable only to the person applying the lens). The `capture` output renders content suitable for sharing with\n * other users (e.g. sent to the other members of a video call, or saved to disk for sharing later).\n *\n * For many lenses, these outputs are identical – but each lens is free to render differently, based on its own\n * use-case.\n */\n readonly output: {\n live: HTMLCanvasElement;\n capture: HTMLCanvasElement;\n };\n\n /**\n * Indicates whether or not the session is currently rendering. If `false`, rendering is stopped. Otherwise the\n * value indicates which output is being rendered.\n */\n playing: {\n live: boolean;\n capture: boolean;\n };\n\n /**\n * Add event listeners here to handle events which occur during the CameraKitSession.\n *\n * **Note:** Applications may want to handle the `error` event, and check the contained error type -- if the type\n * is {@link LensExecutionError}, this means the current lens was unable to render and CameraKit will automatically\n * remove the lens.\n *\n * @example\n * ```ts\n * cameraKitSession.events.addEventListener('error', ({ detail }) => {\n * if (detail.error.name === 'LensExecutionError') {\n * console.log(`Lens ${detail.lens.name} encountered an error and was removed. Please pick a different lens.`)\n * }\n * })\n * ```\n */\n readonly events = new TypedEventTarget<CameraKitSessionEvents>();\n\n /**\n * Use this to measure current lens performance.\n */\n readonly metrics: LensPerformanceMetrics;\n\n private readonly removePageVisibilityHandlers: () => void;\n private source?: CameraKitSource;\n private subscriptions: Subscription[];\n\n /**\n * @internal\n */\n constructor(\n /**\n * Use this to interact with lenses which require text input.\n */\n public readonly keyboard: Keyboard,\n\n private readonly lensCore: LensCore,\n private readonly sessionState: SessionState,\n private readonly lensState: LensState,\n logEntries: Observable<LogEntry>,\n pageVisibility: PageVisibility\n ) {\n const outputs = this.lensCore.getOutputCanvases();\n this.output = {\n live: outputs[this.lensCore.CanvasType.Preview.value],\n capture: outputs[this.lensCore.CanvasType.Capture.value],\n };\n this.playing = {\n live: false,\n capture: false,\n };\n\n this.metrics = new LensPerformanceMetrics(this.lensCore);\n\n const removeOnHidden = pageVisibility.onPageHidden(() => this.sessionState.dispatch(\"suspend\", this));\n const removeOnVisible = pageVisibility.onPageVisible(() => this.sessionState.dispatch(\"resume\", this));\n this.removePageVisibilityHandlers = () => {\n removeOnHidden();\n removeOnVisible();\n };\n\n const sessionErrors = logEntries.pipe(\n filter((entry) => entry.level === \"error\"),\n map((entry) => entry.messages.find((e) => e instanceof Error)),\n filter(isSessionError)\n );\n\n this.subscriptions = [\n // In case of an abort error, the only option is to destroy the current session,\n // as it becomes inoperable.\n sessionErrors.pipe(filter((error) => error.name === \"LensAbortError\")).subscribe(() => this.destroy()),\n\n // In case of LensCore lens execution error, we must remove the lens from rendering\n // NOTE: LensCore doesn't differentiate recoverable vs non-recoverable errors and\n // it is recommened to always remove the lens.\n sessionErrors\n .pipe(filter((error) => error.name === \"LensExecutionError\"))\n .subscribe(() => this.removeLens()),\n\n // Report public session errors to apps\n sessionErrors.pipe(filter(isPublicLensError)).subscribe((error) => {\n const state = lensState.getState();\n if (!isState(state, \"noLensApplied\")) {\n this.events.dispatchEvent(new TypedCustomEvent(\"error\", { error, lens: state.data }));\n } else {\n // NOTE: at this point the error is already reported, so we can just log a warning\n logger.warn(\"Lens error occurred even though there is no active lens.\", error);\n }\n }),\n ];\n }\n\n /**\n * Apply a Lens to this session.\n *\n * This method will download (and cache) the Lens executable, and then use that Lens for rendering. If the session\n * is currently playing, this will immediately update the rendered output. Otherwise, the new Lens will be used\n * when session playback in resumed.\n *\n * Calling `applyLens` replaces any prior Lens – only one Lens is allowed at a time (per session).\n *\n * **NOTE**: Errors may occur after the Lens is applied. If the Lens encounters errors while rendering,\n * Camera Kit will automatically remove the Lens from the session and emit a {@link LensExecutionError} event.\n * Applications may want to listen for this error and, for example,\n * prevent the Lens from being selected again by the user.\n *\n * ```ts\n * session.events.addEventListener(\"error\", ({ detail }) => {\n * if (detail.error.name === \"LensExecutionError\") {\n * preventFutureLensSelection(detail.lens);\n * showMessage(\"We're sorry, but the Lens you selected encountered an error. Please choose a different Lens.\");\n * }\n * });\n * ```\n *\n * @param lens The Lens to apply to this session.\n * @param launchParams: This can optionally be provided to pass some initial data to the lens – only certain lenses\n * expect launch data.\n * @returns A promise which can have the following results:\n * 1. Resolved with `true`: the lens has been applied.\n * 2. Resolved with `false`: the lens has not been applied, but no error occurred – this can happen if a\n * subsequent call to `applyLens` interrupted the lens application.\n * 3. Rejected: the lens has not been applied because an error occurred. This can happen if:\n * - The lens ID cannot be found in the LensRepository (use LensRepository to load the lens before calling this\n * method)\n * - Lens content download fails, or the download of any required lens assets fails.\n * - An internal failure occurs in the Lens rendering engine when attempting to apply the lens.\n */\n @validate\n @log\n async applyLens(@guard(isLens) lens: Lens, launchData?: LensLaunchData): Promise<boolean> {\n const action = this.lensState.actions.applyLens({ lens, launchData });\n return firstValueFrom(\n of(action).pipe(\n dispatch(this.lensState),\n\n // If another applyLens occurs while we're waiting, resolve this applyLens promise early – we're no\n // longer waiting for the requested lens to be applied.\n takeUntil(\n this.lensState.events.pipe(\n forActions(\"applyLens\"),\n filter(([a]) => a !== action)\n )\n ),\n\n // If lens application failed, convert this into a rejected promise by throwing the error.\n tap(([a]) => {\n if (isAction(a, \"applyLensFailed\") && a.data.lens.id === lens.id) throw a.data.error;\n }),\n\n inStates(\"lensApplied\"),\n\n map(() => true)\n ),\n // The default value is used if `takeUntil` completes the Observable early – i.e. the lens was not\n // applied (application was interrupted by a new call to `applyLens`), so we'll resolve with `false`.\n { defaultValue: false }\n );\n }\n\n /**\n * Remove a Lens from this session.\n *\n * When a Lens is removed, rendering continues if the session is playing. It will just render the session input\n * directly to the outputs without any image processing.\n *\n * @returns A promise which can have the following results:\n * 1. Resolved with `true`: the session's rendered output has no lens applied.\n * 2. Resolved with `false`: the current lens has been removed, but a subsequent call to `applyLens` means that the\n * session's rendered output will still have a (new) lens applied.\n * 3. Rejected: the lens has failed to be removed. This can happen if an internal failure occurs in the Lens\n * rendering engine when attempting to remove the lens.\n */\n @log\n async removeLens(): Promise<boolean> {\n if (isState(this.lensState.getState(), \"noLensApplied\")) return true;\n return firstValueFrom(\n of(this.lensState.actions.removeLens()).pipe(\n dispatch(this.lensState),\n // If lens removal failed, convert this into a rejected promise by throwing the error.\n tap(([a]) => {\n if (isAction(a, \"removeLensFailed\")) throw a.data;\n }),\n inStates(\"noLensApplied\"),\n\n // If applyLens is called while we're waiting for removal, complete immediately – applying the next lens\n // will replace the current one.\n takeUntil(this.lensState.events.pipe(forActions(\"applyLens\"))),\n map(() => true)\n ),\n // The default value is used if `takeUntil` completes the Observable early (otherwise firstValueFrom will\n // return a rejected Promise).\n { defaultValue: false }\n );\n }\n\n /**\n * Start/resume session playback – LensCore will begin rendering frames to the output.\n *\n * If no source has been set for the session, calling `play()` will update the playing state, but no actual image\n * processing will occur until `setSource()` is called.\n *\n * @example\n * ```ts\n * const cameraKitSession = await cameraKit.createSession()\n * await cameraKitSession.setSource(mySource)\n * await cameraKitSession.play()\n *\n * // If you call `play` before `setSource`, the call to `play` will resolve but playback will only begin once a\n * // media source has been set.\n * ```\n *\n * @param target Specify the {@link RenderTarget} to render. Defaults to the `live` RenderTarget.\n * @returns Promise resolves when playback state has been updated. If no source has been set, this means `play` will\n * resolve before any frames are processed -- but once a source is set, frames will immediately begin processing.\n */\n @validate\n @log\n async play(@guard(isOptionalRenderTarget) target: RenderTarget = \"live\"): Promise<void> {\n if (this.playing[target]) return;\n\n this.playing[target] = true;\n const type = this.renderTargetToCanvasType(target);\n return this.lensCore.playCanvas({ type }).catch((error) => {\n this.playing[target] = false;\n throw error;\n });\n }\n\n /**\n * Pause session playback – LensCore will stop rendering frames to the output.\n *\n * @param target Specify the RenderTarget to pause playback. May be either `'live'` or `'capture'`.\n * Default is `'live'`.\n * @returns Promise resolves when playback has stopped.\n */\n @validate\n @log\n async pause(@guard(isOptionalRenderTarget) target: RenderTarget = \"live\"): Promise<void> {\n if (this.playing[target] === false) return;\n this.playing[target] = false;\n const type = this.renderTargetToCanvasType(target);\n return this.lensCore.pauseCanvas({ type }).catch((error) => {\n this.playing[target] = true;\n throw error;\n });\n }\n\n /**\n * Mute all sounds (default SDK state is unmuted).\n *\n * @param fade Do we want audio to fade out?\n */\n @log\n mute(fade: boolean = false): void {\n this.lensCore.setAllSoundsMuted({\n muted: true,\n fade,\n });\n }\n\n /**\n * Unmute all sounds.\n *\n * @param fade Do we want audio to fade in?\n */\n @log\n unmute(fade: boolean = false): void {\n this.lensCore.setAllSoundsMuted({\n muted: false,\n fade,\n });\n }\n\n /**\n * Set the media source for this session.\n *\n * Sessions may only have one source at a time - if `setSource` is called multiple times, subsequent calls replace\n * the prior source. Setting the source does not trigger rendering (that’s done by `session.play()`). If the session\n * is already playing, setting the source will immediately begin rendering the new source.\n *\n * The CameraKit SDK provides implementations for various common sources, which applications can create using the\n * following functions:\n * - {@link createMediaStreamSource}\n * - {@link createVideoSource}\n * - {@link createImageSource}\n *\n * @param source A CameraKitSource object representing input media (e.g. a webcam stream, video, or some other\n * source of image data), which CameraKit will supply to Lenses in order for them to render effects on top of that\n * source.\n * @returns Promise is resolved when the source has successfully be set. If the session was already in the playing\n * state, the Promise resolves when the first frame from the new source has been rendered. The resolved value is\n * the {@link CameraKitSource} object attached to the session.\n */\n async setSource(source: CameraKitSource): Promise<CameraKitSource>;\n async setSource(\n source: MediaStream | HTMLVideoElement,\n options?: Partial<CameraKitDeviceOptions>\n ): Promise<CameraKitSource>;\n @validate\n @log\n async setSource(\n source: CameraKitSource | MediaStream | HTMLVideoElement,\n options: Partial<CameraKitDeviceOptions> = {}\n ): Promise<CameraKitSource> {\n await this.safelyDetachSource();\n\n // For convenience, we allow callers to pass in native objects (e.g. MediaStream) as well as CameraKitSource.\n // Native objects are wrapped in corresponding CameraKitSource classes with default options.\n const cameraKitSource =\n source instanceof MediaStream\n ? createMediaStreamSource(source, options)\n : source instanceof HTMLVideoElement\n ? createVideoSource(source, options)\n : source;\n\n const priorPlayingState = this.playing;\n this.playing = {\n live: false,\n capture: false,\n };\n\n // The source will provide its data to LensCore, and use other LensCore APIs (e.g. setRenderSize,\n // setInputTransform) to render the source correctly.\n await cameraKitSource.attach(this.lensCore, (error) => {\n logger.error(cameraKitSourceError(\"Error occurred during source attachment.\", error));\n });\n\n // If attachment is successful, we'll update our source so that we can detach it later.\n this.source = cameraKitSource;\n\n // Finally we'll resume playback, if appropriate.\n if (priorPlayingState.live) await this.play(\"live\");\n if (priorPlayingState.capture) await this.play(\"capture\");\n\n return cameraKitSource;\n }\n\n /**\n * Set an FPS limit.\n *\n * This may be useful to reduce CPU/GPU resource usage by CameraKit if, for example, the input\n * media source has a low FPS – CameraKit would then not try to render more frequently than the source produces\n * new frames.\n *\n * This may also be useful to gracefully degrade performance in situations where lowering FPS is preferable over\n * alternatives.\n *\n * @param fpsLimit A maximum FPS, rendering will not exceed this limit\n * @returns Promise is resolved when the limit is successfully set.\n */\n @log\n async setFPSLimit(fpsLimit: number): Promise<void> {\n // LensCore uses 0 to remove the limit.\n const fps = fpsLimit < Number.POSITIVE_INFINITY ? fpsLimit : 0;\n return this.lensCore.setFPSLimit({ fps });\n }\n\n /**\n * Destroy the session.\n *\n * The session will become inoperable. Frame processing stops, and any session-scoped graphical resources are freed.\n */\n @log\n async destroy(): Promise<void> {\n try {\n await this.lensCore.clearAllLenses();\n await this.lensCore.teardown();\n } catch (error) {\n // If a LensCore is in an aborted state, the above lines may throw an error.\n // In such cases, we should continue with the cleanup process.\n // We are also not interested in reporting these errors to our backend.\n logger.warn(\"An error occurred in LensCore during the session termination process.\", error);\n }\n this.subscriptions.forEach((sub) => sub.unsubscribe());\n await this.safelyDetachSource();\n this.removePageVisibilityHandlers();\n this.sessionState.dispatch(\"destroy\", undefined);\n }\n\n private renderTargetToCanvasType(target: RenderTarget): CanvasType {\n return target === \"capture\" ? this.lensCore.CanvasType.Capture : this.lensCore.CanvasType.Preview;\n }\n\n private async safelyDetachSource(): Promise<void> {\n if (this.source) {\n try {\n await this.source.detach((error) => {\n logger.error(cameraKitSourceError(\"Error occurred during source detachment.\", error));\n });\n // If there's a failure to detach, we will report the error and proceed. Failure to detach may lead to a\n // memory leak, but it shouldn't prevent us from switching to the new source.\n } catch (error) {\n logger.error(\n cameraKitSourceError(`Detaching prior source of type ${getTypeName(this.source)} failed.`, error)\n );\n }\n }\n }\n}\n\n/**\n * @internal\n */\nexport const cameraKitSessionFactory = Injectable(\n \"CameraKitSession\",\n [\n lensCoreFactory.token,\n logEntriesFactory.token,\n lensKeyboardFactory.token,\n sessionStateFactory.token,\n lensStateFactory.token,\n pageVisibilityFactory.token,\n ] as const,\n (\n lensCore: LensCore,\n logEntries: Observable<LogEntry>,\n keyboard: LensKeyboard,\n sessionState: SessionState,\n lensState: LensState,\n pageVisibility: PageVisibility\n ) => new CameraKitSession(keyboard, lensCore, sessionState, lensState, logEntries, pageVisibility)\n);\n"]}
|
|
1
|
+
{"version":3,"file":"CameraKitSession.js","sourceRoot":"","sources":["../../src/session/CameraKitSession.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,EAAc,EAAE,EAAgB,SAAS,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACjG,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAA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KH;AAQK;IADL,GAAG;;;;+CAeH;AAuBL;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAC7C,kBAAkB,EAClB;IACI,eAAe,CAAC,KAAK;IACrB,iBAAiB,CAAC,KAAK;IACvB,mBAAmB,CAAC,KAAK;IACzB,mBAAmB,CAAC,KAAK;IACzB,gBAAgB,CAAC,KAAK;IACtB,qBAAqB,CAAC,KAAK;CACrB,EACV,CACI,QAAkB,EAClB,UAAgC,EAChC,QAAsB,EACtB,YAA0B,EAC1B,SAAoB,EACpB,cAA8B,EAChC,EAAE,CAAC,IAAI,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,CAAC,CACrG,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/member-ordering */\nimport { filter, firstValueFrom, map, Observable, of, Subscription, takeUntil, tap } from \"rxjs\";\nimport { dispatch, forActions, inStates, isAction, isState } from \"@snap/state-management\";\nimport { Lens, isLens } from \"../lens/Lens\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { lensCoreFactory } from \"../lens-core-module/loader/lensCoreFactory\";\nimport { LensLaunchData } from \"../lens/LensLaunchData\";\nimport { getTypeName, guard, validate } from \"../common/validate\";\nimport { TypedEventTarget } from \"../events/TypedEventTarget\";\nimport { TypedCustomEvent } from \"../events/TypedCustomEvent\";\nimport { CameraKitDeviceOptions, CameraKitSource } from \"../media-sources/CameraKitSource\";\nimport { cameraKitSourceError, LensExecutionError } from \"../namedErrors\";\nimport { createMediaStreamSource } from \"../media-sources/MediaStreamSource\";\nimport { createVideoSource } from \"../media-sources/VideoSource\";\nimport { getLogger, LogEntry } from \"../logger/logger\";\nimport { errorLoggingDecorator } from \"../logger/errorLoggingDecorator\";\nimport { logEntriesFactory } from \"../logger/logEntries\";\nimport { PageVisibility, pageVisibilityFactory } from \"../common/pageVisibility\";\nimport { LensCore } from \"../lens-core-module/lensCore\";\nimport { CanvasType } from \"../lens-core-module/generated-types\";\nimport { LensPerformanceMetrics } from \"./LensPerformanceMetrics\";\nimport { lensStateFactory, LensState } from \"./lensState\";\nimport { SessionState, sessionStateFactory } from \"./sessionState\";\nimport { Keyboard, lensKeyboardFactory, LensKeyboard } from \"./LensKeyboard\";\nimport { CameraKitSessionEvents, isPublicLensError, isSessionError } from \"./CameraKitSessionEvents\";\n\nconst logger = getLogger(\"CameraKitSession\");\nconst log = errorLoggingDecorator(logger);\n\nfunction isOptionalRenderTarget(value: unknown): value is RenderTarget | undefined {\n return value === \"live\" || value === \"capture\" || value === undefined;\n}\n\n/**\n * Enumerates the supported render targets.\n *\n * Lenses may render to different render targets, as designed by the lens creator. In CameraKit, it's possible to choose\n * which render target to render, and the result for each target is available as a separate `<canvas>` element.\n *\n * @category Rendering\n * @category Lenses\n */\nexport type RenderTarget = \"live\" | \"capture\";\n\n/**\n * A CameraKitSession represents a single rendering pipeline connecting an input media source to output `<canvas>`\n * elements. When a Lens is applied to the session, CameraKit uses the Lens to transform the input media into rendered\n * output.\n *\n * CameraKitSession is the primary object that applications interact with when integrating the CameraKit SDK.\n *\n * A CameraKitSession instance is obtained by calling {@link CameraKit.createSession}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * const session = await cameraKit.createSession()\n * ```\n *\n * @category Rendering\n * @category Lenses\n */\nexport class CameraKitSession {\n /**\n * CameraKitSession renders video output to a `<canvas>` element. In fact, each session contains two canvas outputs\n * corresponding to the RenderTargets used by Lens creators, when using LensStudio to create a Lens.\n *\n * The `live` output renders content suitable for the Lens user (e.g. it may contain additional UI elements\n * applicable only to the person applying the lens). The `capture` output renders content suitable for sharing with\n * other users (e.g. sent to the other members of a video call, or saved to disk for sharing later).\n *\n * For many lenses, these outputs are identical – but each lens is free to render differently, based on its own\n * use-case.\n */\n readonly output: {\n live: HTMLCanvasElement;\n capture: HTMLCanvasElement;\n };\n\n /**\n * Indicates whether or not the session is currently rendering. If `false`, rendering is stopped. Otherwise the\n * value indicates which output is being rendered.\n */\n playing: {\n live: boolean;\n capture: boolean;\n };\n\n /**\n * Add event listeners here to handle events which occur during the CameraKitSession.\n *\n * **Note:** Applications may want to handle the `error` event, and check the contained error type -- if the type\n * is {@link LensExecutionError}, this means the current lens was unable to render and CameraKit will automatically\n * remove the lens.\n *\n * @example\n * ```ts\n * cameraKitSession.events.addEventListener('error', ({ detail }) => {\n * if (detail.error.name === 'LensExecutionError') {\n * console.log(`Lens ${detail.lens.name} encountered an error and was removed. Please pick a different lens.`)\n * }\n * })\n * ```\n */\n readonly events = new TypedEventTarget<CameraKitSessionEvents>();\n\n /**\n * Use this to measure current lens performance.\n */\n readonly metrics: LensPerformanceMetrics;\n\n private readonly removePageVisibilityHandlers: () => void;\n private source?: CameraKitSource;\n private subscriptions: Subscription[];\n\n /**\n * @internal\n */\n constructor(\n /**\n * Use this to interact with lenses which require text input.\n */\n public readonly keyboard: Keyboard,\n\n private readonly lensCore: LensCore,\n private readonly sessionState: SessionState,\n private readonly lensState: LensState,\n logEntries: Observable<LogEntry>,\n pageVisibility: PageVisibility\n ) {\n const outputs = this.lensCore.getOutputCanvases();\n this.output = {\n live: outputs[this.lensCore.CanvasType.Preview.value],\n capture: outputs[this.lensCore.CanvasType.Capture.value],\n };\n this.playing = {\n live: false,\n capture: false,\n };\n\n this.metrics = new LensPerformanceMetrics(this.lensCore);\n\n const removeOnHidden = pageVisibility.onPageHidden(() => this.sessionState.dispatch(\"suspend\", this));\n const removeOnVisible = pageVisibility.onPageVisible(() => this.sessionState.dispatch(\"resume\", this));\n this.removePageVisibilityHandlers = () => {\n removeOnHidden();\n removeOnVisible();\n };\n\n const sessionErrors = logEntries.pipe(\n filter((entry) => entry.level === \"error\"),\n map((entry) => entry.messages.find((e) => e instanceof Error)),\n filter(isSessionError)\n );\n\n this.subscriptions = [\n // In case of an abort error, the only option is to destroy the current session,\n // as it becomes inoperable.\n sessionErrors.pipe(filter((error) => error.name === \"LensAbortError\")).subscribe(() => this.destroy()),\n\n // In case of LensCore lens execution error, we must remove the lens from rendering\n // NOTE: LensCore doesn't differentiate recoverable vs non-recoverable errors and\n // it is recommended to always remove the lens.\n sessionErrors\n .pipe(filter((error) => error.name === \"LensExecutionError\"))\n .subscribe(() => this.removeLens()),\n\n // Report public session errors to apps\n sessionErrors.pipe(filter(isPublicLensError)).subscribe((error) => {\n const state = lensState.getState();\n if (!isState(state, \"noLensApplied\")) {\n this.events.dispatchEvent(new TypedCustomEvent(\"error\", { error, lens: state.data }));\n } else {\n // NOTE: at this point the error is already reported, so we can just log a warning\n logger.warn(\"Lens error occurred even though there is no active lens.\", error);\n }\n }),\n ];\n }\n\n /**\n * Apply a Lens to this session.\n *\n * This method will download (and cache) the Lens executable, and then use that Lens for rendering. If the session\n * is currently playing, this will immediately update the rendered output. Otherwise, the new Lens will be used\n * when session playback in resumed.\n *\n * Calling `applyLens` replaces any prior Lens – only one Lens is allowed at a time (per session).\n *\n * **NOTE**: Errors may occur after the Lens is applied. If the Lens encounters errors while rendering,\n * Camera Kit will automatically remove the Lens from the session and emit a {@link LensExecutionError} event.\n * Applications may want to listen for this error and, for example,\n * prevent the Lens from being selected again by the user.\n *\n * ```ts\n * session.events.addEventListener(\"error\", ({ detail }) => {\n * if (detail.error.name === \"LensExecutionError\") {\n * preventFutureLensSelection(detail.lens);\n * showMessage(\"We're sorry, but the Lens you selected encountered an error. Please choose a different Lens.\");\n * }\n * });\n * ```\n *\n * @param lens The Lens to apply to this session.\n * @param launchData This can optionally be provided to pass some initial data to the Lens – only certain Lenses\n * expect launch data.\n * @returns A promise which can have the following results:\n * 1. Resolved with `true`: the Lens has been applied.\n * 2. Resolved with `false`: the Lens has not been applied, but no error occurred – this can happen if a\n * subsequent call to `applyLens` interrupted the Lens application.\n * 3. Rejected: the Lens has not been applied because an error occurred. This can happen if:\n * - The Lens ID cannot be found in the LensRepository (use LensRepository to load the Lens before calling this\n * method)\n * - Lens content download fails, or the download of any required lens assets fails.\n * - An internal failure occurs in the Lens rendering engine when attempting to apply the Lens.\n */\n @validate\n @log\n async applyLens(\n @guard(isLens) lens: Lens,\n // TODO: Add validation https://jira.sc-corp.net/browse/CAMKIT-6115\n launchData?: LensLaunchData\n ): Promise<boolean> {\n const action = this.lensState.actions.applyLens({ lens, launchData });\n return firstValueFrom(\n of(action).pipe(\n dispatch(this.lensState),\n\n // If another applyLens occurs while we're waiting, resolve this applyLens promise early – we're no\n // longer waiting for the requested lens to be applied.\n takeUntil(\n this.lensState.events.pipe(\n forActions(\"applyLens\"),\n filter(([a]) => a !== action)\n )\n ),\n\n // If lens application failed, convert this into a rejected promise by throwing the error.\n tap(([a]) => {\n if (isAction(a, \"applyLensFailed\") && a.data.lens.id === lens.id) throw a.data.error;\n }),\n\n inStates(\"lensApplied\"),\n\n map(() => true)\n ),\n // The default value is used if `takeUntil` completes the Observable early – i.e. the lens was not\n // applied (application was interrupted by a new call to `applyLens`), so we'll resolve with `false`.\n { defaultValue: false }\n );\n }\n\n /**\n * Remove a Lens from this session.\n *\n * When a Lens is removed, rendering continues if the session is playing. It will just render the session input\n * directly to the outputs without any image processing.\n *\n * @returns A promise which can have the following results:\n * 1. Resolved with `true`: the session's rendered output has no lens applied.\n * 2. Resolved with `false`: the current lens has been removed, but a subsequent call to `applyLens` means that the\n * session's rendered output will still have a (new) lens applied.\n * 3. Rejected: the lens has failed to be removed. This can happen if an internal failure occurs in the Lens\n * rendering engine when attempting to remove the lens.\n */\n @log\n async removeLens(): Promise<boolean> {\n if (isState(this.lensState.getState(), \"noLensApplied\")) return true;\n return firstValueFrom(\n of(this.lensState.actions.removeLens()).pipe(\n dispatch(this.lensState),\n // If lens removal failed, convert this into a rejected promise by throwing the error.\n tap(([a]) => {\n if (isAction(a, \"removeLensFailed\")) throw a.data;\n }),\n inStates(\"noLensApplied\"),\n\n // If applyLens is called while we're waiting for removal, complete immediately – applying the next lens\n // will replace the current one.\n takeUntil(this.lensState.events.pipe(forActions(\"applyLens\"))),\n map(() => true)\n ),\n // The default value is used if `takeUntil` completes the Observable early (otherwise firstValueFrom will\n // return a rejected Promise).\n { defaultValue: false }\n );\n }\n\n /**\n * Start/resume session playback – LensCore will begin rendering frames to the output.\n *\n * If no source has been set for the session, calling `play()` will update the playing state, but no actual image\n * processing will occur until `setSource()` is called.\n *\n * @example\n * ```ts\n * const cameraKitSession = await cameraKit.createSession()\n * await cameraKitSession.setSource(mySource)\n * await cameraKitSession.play()\n *\n * // If you call `play` before `setSource`, the call to `play` will resolve but playback will only begin once a\n * // media source has been set.\n * ```\n *\n * @param target Specify the {@link RenderTarget} to render. Defaults to the `live` RenderTarget.\n * @returns Promise resolves when playback state has been updated. If no source has been set, this means `play` will\n * resolve before any frames are processed -- but once a source is set, frames will immediately begin processing.\n */\n @validate\n @log\n async play(@guard(isOptionalRenderTarget) target: RenderTarget = \"live\"): Promise<void> {\n if (this.playing[target]) return;\n\n this.playing[target] = true;\n const type = this.renderTargetToCanvasType(target);\n return this.lensCore.playCanvas({ type }).catch((error) => {\n this.playing[target] = false;\n throw error;\n });\n }\n\n /**\n * Pause session playback – LensCore will stop rendering frames to the output.\n *\n * @param target Specify the RenderTarget to pause playback. May be either `'live'` or `'capture'`.\n * Default is `'live'`.\n * @returns Promise resolves when playback has stopped.\n */\n @validate\n @log\n async pause(@guard(isOptionalRenderTarget) target: RenderTarget = \"live\"): Promise<void> {\n if (this.playing[target] === false) return;\n this.playing[target] = false;\n const type = this.renderTargetToCanvasType(target);\n return this.lensCore.pauseCanvas({ type }).catch((error) => {\n this.playing[target] = true;\n throw error;\n });\n }\n\n /**\n * Mute all sounds (default SDK state is unmuted).\n *\n * @param fade Do we want audio to fade out?\n */\n @log\n mute(fade: boolean = false): void {\n this.lensCore.setAllSoundsMuted({\n muted: true,\n fade,\n });\n }\n\n /**\n * Unmute all sounds.\n *\n * @param fade Do we want audio to fade in?\n */\n @log\n unmute(fade: boolean = false): void {\n this.lensCore.setAllSoundsMuted({\n muted: false,\n fade,\n });\n }\n\n /**\n * Set the media source for this session.\n *\n * Sessions may only have one source at a time - if `setSource` is called multiple times, subsequent calls replace\n * the prior source. Setting the source does not trigger rendering (that’s done by `session.play()`). If the session\n * is already playing, setting the source will immediately begin rendering the new source.\n *\n * The CameraKit SDK provides implementations for various common sources, which applications can create using the\n * following functions:\n * - {@link createMediaStreamSource}\n * - {@link createVideoSource}\n * - {@link createImageSource}\n *\n * @param source A CameraKitSource object representing input media (e.g. a webcam stream, video, or some other\n * source of image data), which CameraKit will supply to Lenses in order for them to render effects on top of that\n * source.\n * @returns Promise is resolved when the source has successfully be set. If the session was already in the playing\n * state, the Promise resolves when the first frame from the new source has been rendered. The resolved value is\n * the {@link CameraKitSource} object attached to the session.\n */\n async setSource(source: CameraKitSource): Promise<CameraKitSource>;\n async setSource(\n source: MediaStream | HTMLVideoElement,\n options?: Partial<CameraKitDeviceOptions>\n ): Promise<CameraKitSource>;\n @validate\n @log\n async setSource(\n source: CameraKitSource | MediaStream | HTMLVideoElement,\n options: Partial<CameraKitDeviceOptions> = {}\n ): Promise<CameraKitSource> {\n await this.safelyDetachSource();\n\n // For convenience, we allow callers to pass in native objects (e.g. MediaStream) as well as CameraKitSource.\n // Native objects are wrapped in corresponding CameraKitSource classes with default options.\n const cameraKitSource =\n source instanceof MediaStream\n ? createMediaStreamSource(source, options)\n : source instanceof HTMLVideoElement\n ? createVideoSource(source, options)\n : source;\n\n const priorPlayingState = this.playing;\n this.playing = {\n live: false,\n capture: false,\n };\n\n // The source will provide its data to LensCore, and use other LensCore APIs (e.g. setRenderSize,\n // setInputTransform) to render the source correctly.\n await cameraKitSource.attach(this.lensCore, (error) => {\n logger.error(cameraKitSourceError(\"Error occurred during source attachment.\", error));\n });\n\n // If attachment is successful, we'll update our source so that we can detach it later.\n this.source = cameraKitSource;\n\n // Finally we'll resume playback, if appropriate.\n if (priorPlayingState.live) await this.play(\"live\");\n if (priorPlayingState.capture) await this.play(\"capture\");\n\n return cameraKitSource;\n }\n\n /**\n * Set an FPS limit.\n *\n * This may be useful to reduce CPU/GPU resource usage by CameraKit if, for example, the input\n * media source has a low FPS – CameraKit would then not try to render more frequently than the source produces\n * new frames.\n *\n * This may also be useful to gracefully degrade performance in situations where lowering FPS is preferable over\n * alternatives.\n *\n * @param fpsLimit A maximum FPS, rendering will not exceed this limit\n * @returns Promise is resolved when the limit is successfully set.\n */\n @log\n async setFPSLimit(fpsLimit: number): Promise<void> {\n // LensCore uses 0 to remove the limit.\n const fps = fpsLimit < Number.POSITIVE_INFINITY ? fpsLimit : 0;\n return this.lensCore.setFPSLimit({ fps });\n }\n\n /**\n * Destroy the session.\n *\n * The session will become inoperable. Frame processing stops, and any session-scoped graphical resources are freed.\n */\n @log\n async destroy(): Promise<void> {\n try {\n await this.lensCore.clearAllLenses();\n await this.lensCore.teardown();\n } catch (error) {\n // If a LensCore is in an aborted state, the above lines may throw an error.\n // In such cases, we should continue with the cleanup process.\n // We are also not interested in reporting these errors to our backend.\n logger.warn(\"An error occurred in LensCore during the session termination process.\", error);\n }\n this.subscriptions.forEach((sub) => sub.unsubscribe());\n await this.safelyDetachSource();\n this.removePageVisibilityHandlers();\n this.sessionState.dispatch(\"destroy\", undefined);\n }\n\n private renderTargetToCanvasType(target: RenderTarget): CanvasType {\n return target === \"capture\" ? this.lensCore.CanvasType.Capture : this.lensCore.CanvasType.Preview;\n }\n\n private async safelyDetachSource(): Promise<void> {\n if (this.source) {\n try {\n await this.source.detach((error) => {\n logger.error(cameraKitSourceError(\"Error occurred during source detachment.\", error));\n });\n // If there's a failure to detach, we will report the error and proceed. Failure to detach may lead to a\n // memory leak, but it shouldn't prevent us from switching to the new source.\n } catch (error) {\n logger.error(\n cameraKitSourceError(`Detaching prior source of type ${getTypeName(this.source)} failed.`, error)\n );\n }\n }\n }\n}\n\n/**\n * @internal\n */\nexport const cameraKitSessionFactory = Injectable(\n \"CameraKitSession\",\n [\n lensCoreFactory.token,\n logEntriesFactory.token,\n lensKeyboardFactory.token,\n sessionStateFactory.token,\n lensStateFactory.token,\n pageVisibilityFactory.token,\n ] as const,\n (\n lensCore: LensCore,\n logEntries: Observable<LogEntry>,\n keyboard: LensKeyboard,\n sessionState: SessionState,\n lensState: LensState,\n pageVisibility: PageVisibility\n ) => new CameraKitSession(keyboard, lensCore, sessionState, lensState, logEntries, pageVisibility)\n);\n"]}
|
|
@@ -20,7 +20,7 @@ export type KeyboardEvents = TypedCustomEvent<"active", {
|
|
|
20
20
|
* There are two ways to do this:
|
|
21
21
|
* 1. Add the provided DOM element (an HTMLTextAreaElement) to the page. When the user updates this element with text,
|
|
22
22
|
* that text will be sent to the currently active lens.
|
|
23
|
-
* 2. Use the {@link sendInputToLens} method to send text strings to the currently active lens directly.
|
|
23
|
+
* 2. Use the {@link Keyboard.sendInputToLens} method to send text strings to the currently active lens directly.
|
|
24
24
|
*
|
|
25
25
|
* Lenses will also signal to the application when text input is expected -- applications should add an event listener
|
|
26
26
|
* and ensure the user is able to input text when the `active` event is received.
|
|
@@ -81,8 +81,7 @@ export declare const lensKeyboardFactory: {
|
|
|
81
81
|
lens: Lens;
|
|
82
82
|
launchData?: import("..").LensLaunchData | undefined;
|
|
83
83
|
}> | import("@snap/state-management").Action<"downloadComplete", Lens> | import("@snap/state-management").Action<"turnedOn", Lens> | import("@snap/state-management").Action<"resourcesLoaded", Lens> | import("@snap/state-management").Action<"firstFrameProcessed", Lens> | import("@snap/state-management").Action<"applyLensComplete", Lens> | import("@snap/state-management").Action<"applyLensFailed", {
|
|
84
|
-
error: import("./lensState").LensErrors;
|
|
85
|
-
/**
|
|
84
|
+
error: import("./lensState").LensErrors; /**
|
|
86
85
|
* Send text to the active Lens. Also updates the provided HTMLTextAreaElement.
|
|
87
86
|
*
|
|
88
87
|
* @param text String to render. This can include escape sequences, such as the newline character ( \n ) for
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensKeyboard.js","sourceRoot":"","sources":["../../src/session/LensKeyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,E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QAC5E,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED,iBAAiB;QACb,OAAO;YACH,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;YAClD,mBAAmB,EAAE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC;YACxD,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;YACtC,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;YAChD,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;SACnC,CAAC;IACN,CAAC;IAEO,YAAY;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;QACxC,uEAAuE;QACvE,IAAI,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC;YAAE,OAAO;QAC5C,IAAI,CAAC,MAAM,CAAC,aAAa,CACrB,IAAI,gBAAgB,CAAC,QAAQ,EAAE;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,kEAAkE;YAClE,IAAI,EAAE,KAAK,CAAC,IAAI;SACnB,CAAC,CACL,CAAC;IACN,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CACzC,cAAc,EACd,CAAC,gBAAgB,CAAC,KAAK,CAAU,EACjC,CAAC,SAAoB,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,SAAS,CAAC,CACxD,CAAC","sourcesContent":["import { isState, forActions } from \"@snap/state-management\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { TypedCustomEvent } from \"../events/TypedCustomEvent\";\nimport { TypedEventListener, TypedEventListenerOptions, TypedEventTarget } from \"../events/TypedEventTarget\";\nimport { UriHandler } from \"../extensions/UriHandlers\";\nimport { Lens } from \"../lens/Lens\";\nimport { LensState, lensStateFactory } from \"./lensState\";\n\n/**\n * Events emitted by {@link Keyboard}.\n */\nexport type KeyboardEvents = TypedCustomEvent<\n \"active\",\n {\n element: HTMLTextAreaElement;\n active: boolean;\n lens?: Lens;\n }\n>;\n\n/**\n * Keyboard is an API enabling lenses to consume and render user-generated text.\n *\n * Applications that wish to use lenses that expect user-generated text will need to use this API to integrate text\n * input into their user experience.\n *\n * There are two ways to do this:\n * 1. Add the provided DOM element (an HTMLTextAreaElement) to the page. When the user updates this element with text,\n * that text will be sent to the currently active lens.\n * 2. Use the {@link sendInputToLens} method to send text strings to the currently active lens directly.\n *\n * Lenses will also signal to the application when text input is expected -- applications should add an event listener\n * and ensure the user is able to input text when the `active` event is received.\n *\n * @example\n * ```ts\n * cameraKitSession.keyboard.addEventListener('active', ({ detail }) => {\n * const { element, active } = detail\n * if (active) document.body.appendChild(element)\n * else element.remove()\n * })\n * ```\n *\n * @category Lenses\n */\nexport type Keyboard = {\n addEventListener: (\n type: \"active\",\n callback: TypedEventListener<KeyboardEvents>,\n options?: TypedEventListenerOptions\n ) => void;\n removeEventListener: (type: \"active\", callback: TypedEventListener<KeyboardEvents>) => void;\n\n /**\n * Get an HTMLTextAreaElement that communicates text to the active Lens.\n */\n getElement: () => HTMLTextAreaElement;\n\n /**\n * Send text to the active Lens. Also updates the provided HTMLTextAreaElement.\n *\n * @param text String to render. This can include escape sequences, such as the newline character ( \\n ) for\n * multi-line input.\n */\n sendInputToLens: (text: string) => void;\n\n /**\n * Clears the provided HTMLTextAreaElement, and emits the \"active\" event with `active == false`, allowing the\n * application to e.g. remove relevant text input elements from the DOM.\n */\n dismiss: () => void;\n};\n\n/** @internal */\nexport class LensKeyboard {\n public readonly uriHandler: UriHandler;\n private readonly events: TypedEventTarget<KeyboardEvents>;\n private readonly element: HTMLTextAreaElement;\n private active: boolean;\n private handleReply: (text: string) => void;\n\n constructor(private readonly lensState: LensState) {\n this.active = false;\n this.element = document.createElement(\"textarea\");\n this.element.addEventListener(\"keypress\", (event: KeyboardEvent) => {\n if (event.code === \"Enter\" && !event.shiftKey) {\n event.preventDefault();\n this.handleReply(this.element.value);\n }\n });\n this.events = new TypedEventTarget<KeyboardEvents>();\n this.handleReply = () => {};\n this.uriHandler = {\n uri: \"app://textInput/requestKeyboard\",\n handleRequest: (_request, reply) => {\n this.element.autofocus = true;\n this.handleReply = (text: string) => {\n const opt = {\n text: text,\n start: text.length,\n end: text.length,\n done: true,\n shouldNotify: true,\n };\n const output = new TextEncoder().encode(JSON.stringify(opt));\n reply({\n code: 200,\n description: \"\",\n contentType: \"application/json\",\n data: output,\n });\n };\n this.active = true;\n this.updateStatus();\n this.element.focus();\n },\n };\n lensState.events.pipe(forActions(\"turnedOff\")).subscribe(() => {\n this.dismiss();\n });\n }\n\n dismiss(): void {\n if (this.active) {\n this.active = false;\n this.element.value = \"\";\n this.updateStatus();\n }\n }\n\n getElement(): HTMLTextAreaElement {\n return this.element;\n }\n\n sendInputToLens(text: string): void {\n this.element.value = text;\n this.handleReply(text);\n }\n\n addEventListener(\n type: \"active\",\n callback: TypedEventListener<KeyboardEvents>,\n options?: TypedEventListenerOptions\n ): void {\n this.events.addEventListener(type, callback, options);\n }\n\n removeEventListener(type: \"active\", callback: TypedEventListener<KeyboardEvents>): void {\n this.events.removeEventListener(type, callback);\n }\n\n toPublicInterface(): Keyboard {\n return {\n addEventListener: this.addEventListener.bind(this),\n removeEventListener: this.removeEventListener.bind(this),\n getElement: this.getElement.bind(this),\n sendInputToLens: this.sendInputToLens.bind(this),\n dismiss: this.dismiss.bind(this),\n };\n }\n\n private updateStatus(): void {\n const state = this.lensState.getState();\n // If lens keyboard status is changing, we know a lens must be applied.\n if (isState(state, \"noLensApplied\")) return;\n this.events.dispatchEvent(\n new TypedCustomEvent(\"active\", {\n element: this.element,\n active: this.active,\n // If the keyboard is up, it has been triggered by an active lens.\n lens: state.data,\n })\n );\n }\n}\n\n/**\n * @internal\n */\nexport const lensKeyboardFactory = Injectable(\n \"lensKeyboard\",\n [lensStateFactory.token] as const,\n (lensState: LensState) => new LensKeyboard(lensState)\n);\n"]}
|
|
1
|
+
{"version":3,"file":"LensKeyboard.js","sourceRoot":"","sources":["../../src/session/LensKeyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAiD,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG7G,OAAO,EAAa,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAmE1D,gBAAgB;AAChB,MAAM,OAAO,YAAY;IAOrB,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;QAC7C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC,KAAoB,EAAE,EAAE;YAC/D,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;gBAC3C,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;aACxC;QACL,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAgB,EAAkB,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG;YACd,GAAG,EAAE,iCAAiC;YACtC,aAAa,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;gBAC/B,IAAI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E,CAAC,IAAI,YAAY,CAAC,SAAS,CAAC,CACxD,CAAC","sourcesContent":["import { isState, forActions } from \"@snap/state-management\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { TypedCustomEvent } from \"../events/TypedCustomEvent\";\nimport { TypedEventListener, TypedEventListenerOptions, TypedEventTarget } from \"../events/TypedEventTarget\";\nimport { UriHandler } from \"../extensions/UriHandlers\";\nimport { Lens } from \"../lens/Lens\";\nimport { LensState, lensStateFactory } from \"./lensState\";\n\n/**\n * Events emitted by {@link Keyboard}.\n */\nexport type KeyboardEvents = TypedCustomEvent<\n \"active\",\n {\n element: HTMLTextAreaElement;\n active: boolean;\n lens?: Lens;\n }\n>;\n\n/**\n * Keyboard is an API enabling lenses to consume and render user-generated text.\n *\n * Applications that wish to use lenses that expect user-generated text will need to use this API to integrate text\n * input into their user experience.\n *\n * There are two ways to do this:\n * 1. Add the provided DOM element (an HTMLTextAreaElement) to the page. When the user updates this element with text,\n * that text will be sent to the currently active lens.\n * 2. Use the {@link Keyboard.sendInputToLens} method to send text strings to the currently active lens directly.\n *\n * Lenses will also signal to the application when text input is expected -- applications should add an event listener\n * and ensure the user is able to input text when the `active` event is received.\n *\n * @example\n * ```ts\n * cameraKitSession.keyboard.addEventListener('active', ({ detail }) => {\n * const { element, active } = detail\n * if (active) document.body.appendChild(element)\n * else element.remove()\n * })\n * ```\n *\n * @category Lenses\n */\nexport type Keyboard = {\n addEventListener: (\n type: \"active\",\n callback: TypedEventListener<KeyboardEvents>,\n options?: TypedEventListenerOptions\n ) => void;\n removeEventListener: (type: \"active\", callback: TypedEventListener<KeyboardEvents>) => void;\n\n /**\n * Get an HTMLTextAreaElement that communicates text to the active Lens.\n */\n getElement: () => HTMLTextAreaElement;\n\n /**\n * Send text to the active Lens. Also updates the provided HTMLTextAreaElement.\n *\n * @param text String to render. This can include escape sequences, such as the newline character ( \\n ) for\n * multi-line input.\n */\n sendInputToLens: (text: string) => void;\n\n /**\n * Clears the provided HTMLTextAreaElement, and emits the \"active\" event with `active == false`, allowing the\n * application to e.g. remove relevant text input elements from the DOM.\n */\n dismiss: () => void;\n};\n\n/** @internal */\nexport class LensKeyboard {\n public readonly uriHandler: UriHandler;\n private readonly events: TypedEventTarget<KeyboardEvents>;\n private readonly element: HTMLTextAreaElement;\n private active: boolean;\n private handleReply: (text: string) => void;\n\n constructor(private readonly lensState: LensState) {\n this.active = false;\n this.element = document.createElement(\"textarea\");\n this.element.addEventListener(\"keypress\", (event: KeyboardEvent) => {\n if (event.code === \"Enter\" && !event.shiftKey) {\n event.preventDefault();\n this.handleReply(this.element.value);\n }\n });\n this.events = new TypedEventTarget<KeyboardEvents>();\n this.handleReply = () => {};\n this.uriHandler = {\n uri: \"app://textInput/requestKeyboard\",\n handleRequest: (_request, reply) => {\n this.element.autofocus = true;\n this.handleReply = (text: string) => {\n const opt = {\n text: text,\n start: text.length,\n end: text.length,\n done: true,\n shouldNotify: true,\n };\n const output = new TextEncoder().encode(JSON.stringify(opt));\n reply({\n code: 200,\n description: \"\",\n contentType: \"application/json\",\n data: output,\n });\n };\n this.active = true;\n this.updateStatus();\n this.element.focus();\n },\n };\n lensState.events.pipe(forActions(\"turnedOff\")).subscribe(() => {\n this.dismiss();\n });\n }\n\n dismiss(): void {\n if (this.active) {\n this.active = false;\n this.element.value = \"\";\n this.updateStatus();\n }\n }\n\n getElement(): HTMLTextAreaElement {\n return this.element;\n }\n\n sendInputToLens(text: string): void {\n this.element.value = text;\n this.handleReply(text);\n }\n\n addEventListener(\n type: \"active\",\n callback: TypedEventListener<KeyboardEvents>,\n options?: TypedEventListenerOptions\n ): void {\n this.events.addEventListener(type, callback, options);\n }\n\n removeEventListener(type: \"active\", callback: TypedEventListener<KeyboardEvents>): void {\n this.events.removeEventListener(type, callback);\n }\n\n toPublicInterface(): Keyboard {\n return {\n addEventListener: this.addEventListener.bind(this),\n removeEventListener: this.removeEventListener.bind(this),\n getElement: this.getElement.bind(this),\n sendInputToLens: this.sendInputToLens.bind(this),\n dismiss: this.dismiss.bind(this),\n };\n }\n\n private updateStatus(): void {\n const state = this.lensState.getState();\n // If lens keyboard status is changing, we know a lens must be applied.\n if (isState(state, \"noLensApplied\")) return;\n this.events.dispatchEvent(\n new TypedCustomEvent(\"active\", {\n element: this.element,\n active: this.active,\n // If the keyboard is up, it has been triggered by an active lens.\n lens: state.data,\n })\n );\n }\n}\n\n/**\n * @internal\n */\nexport const lensKeyboardFactory = Injectable(\n \"lensKeyboard\",\n [lensStateFactory.token] as const,\n (lensState: LensState) => new LensKeyboard(lensState)\n);\n"]}
|
|
@@ -33,7 +33,7 @@ export declare class LensPerformanceMeasurement {
|
|
|
33
33
|
*/
|
|
34
34
|
measure(): ComputedFrameMetrics;
|
|
35
35
|
/**
|
|
36
|
-
* Reset the measured
|
|
36
|
+
* Reset the measured performance statistics (averages, std deviations). This is equivalent to using
|
|
37
37
|
* {@link LensPerformanceMetrics.beginMeasurement} to create a new LensPerformanceMeasurement instance, but may be
|
|
38
38
|
* more convenient.
|
|
39
39
|
*/
|
|
@@ -14,7 +14,7 @@ const getDefaultFrameMetricsState = () => ({
|
|
|
14
14
|
// consistently, it's safe to assume actual fps is probably even lower.
|
|
15
15
|
const frameDurationThreshold = 1;
|
|
16
16
|
// When computing the median frame processing time, in order to save space, we'll record a maximum frame processing
|
|
17
|
-
// time median of 200ms -- that's already
|
|
17
|
+
// time median of 200ms -- that's already unusably slow, and we don't really care if the true median is greater than
|
|
18
18
|
// 200ms.
|
|
19
19
|
const frameProcessingTimeMedianMax = 200;
|
|
20
20
|
/**
|
|
@@ -61,7 +61,7 @@ export class LensPerformanceMeasurement {
|
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
|
-
* Reset the measured
|
|
64
|
+
* Reset the measured performance statistics (averages, std deviations). This is equivalent to using
|
|
65
65
|
* {@link LensPerformanceMetrics.beginMeasurement} to create a new LensPerformanceMeasurement instance, but may be
|
|
66
66
|
* more convenient.
|
|
67
67
|
*/
|
|
@@ -106,7 +106,7 @@ export class LensPerformanceMeasurement {
|
|
|
106
106
|
// To approximate the median, we put each processing time into a per-millisecond bucket, and then when we
|
|
107
107
|
// compute a measurement, we can count how many frames fell into each bucket. We don't care about latencies
|
|
108
108
|
// above 200ms, since that's already unusably slow (if we regress from 280ms to 320ms, we don't really care
|
|
109
|
-
// since both are
|
|
109
|
+
// since both are unusable).
|
|
110
110
|
this.state.n++;
|
|
111
111
|
this.state.processingTimeBuckets[Math.min(Math.round(processingTimeMs), frameProcessingTimeMedianMax)]++;
|
|
112
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensPerformanceMeasurement.js","sourceRoot":"","sources":["../../src/session/LensPerformanceMeasurement.ts"],"names":[],"mappings":"AAUA,MAAM,2BAA2B,GAAG,GAAsB,EAAE,CAAC,CAAC;IAC1D,MAAM,EAAE,CAAC;IACT,qBAAqB,EAAE,CAAC;IACxB,CAAC,EAAE,CAAC;IACJ,qBAAqB,EAAE,IAAI,WAAW,CAAC,4BAA4B,GAAG,CAAC,CAAC;IACxE,cAAc,EAAE,CAAC;IACjB,aAAa,EAAE,CAAC;IAChB,WAAW,EAAE,CAAC;CACjB,CAAC,CAAC;AAEH,qHAAqH;AACrH,iHAAiH;AACjH,EAAE;AACF,+GAA+G;AAC/G,uEAAuE;AACvE,MAAM,sBAAsB,GAAW,CAAC,CAAC;AAEzC,mHAAmH;AACnH,
|
|
1
|
+
{"version":3,"file":"LensPerformanceMeasurement.js","sourceRoot":"","sources":["../../src/session/LensPerformanceMeasurement.ts"],"names":[],"mappings":"AAUA,MAAM,2BAA2B,GAAG,GAAsB,EAAE,CAAC,CAAC;IAC1D,MAAM,EAAE,CAAC;IACT,qBAAqB,EAAE,CAAC;IACxB,CAAC,EAAE,CAAC;IACJ,qBAAqB,EAAE,IAAI,WAAW,CAAC,4BAA4B,GAAG,CAAC,CAAC;IACxE,cAAc,EAAE,CAAC;IACjB,aAAa,EAAE,CAAC;IAChB,WAAW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pD;QAED,yGAAyG;QACzG,2GAA2G;QAC3G,2GAA2G;QAC3G,4BAA4B;QAC5B,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QACf,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,4BAA4B,CAAC,CAAC,EAAE,CAAC;IAC7G,CAAC;CACJ","sourcesContent":["interface FrameMetricsState {\n avgFps: number;\n averageProcessingTime: number;\n n: number;\n processingTimeBuckets: Uint32Array;\n procFrameCount: number;\n procFrameMean: number;\n procFrameD2: number;\n}\n\nconst getDefaultFrameMetricsState = (): FrameMetricsState => ({\n avgFps: 0,\n averageProcessingTime: 0,\n n: 0,\n processingTimeBuckets: new Uint32Array(frameProcessingTimeMedianMax + 1),\n procFrameCount: 0,\n procFrameMean: 0,\n procFrameD2: 0,\n});\n\n// This duration is chosen to be larger than we expect frame processing to reasonably take on any device, but smaller\n// than the duration of a manual rendering pause (e.g. a user clicking a pause button followed by a play button).\n//\n// This also defines the min avgFps that will be reported – if we see avgFps at `1 / frameDurationThresholdSec`\n// consistently, it's safe to assume actual fps is probably even lower.\nconst frameDurationThreshold: number = 1;\n\n// When computing the median frame processing time, in order to save space, we'll record a maximum frame processing\n// time median of 200ms -- that's already unusably slow, and we don't really care if the true median is greater than\n// 200ms.\nconst frameProcessingTimeMedianMax = 200;\n\n/**\n * @category Rendering\n * @category Metrics\n */\nexport interface ComputedFrameMetrics {\n avgFps: number;\n lensFrameProcessingTimeMsAvg: number;\n lensFrameProcessingTimeMsStd: number;\n lensFrameProcessingTimeMsMedian: number;\n lensFrameProcessingN: number;\n}\n\n/**\n * Represents an ongoing measurement of rendering metrics.\n *\n * An instance of this class is obtained by calling {@link LensPerformanceMetrics.beginMeasurement}. Then it may be\n * used to record rendering performance metrics, reset measurement, or end the measurement.\n *\n * @category Rendering\n * @category Metrics\n */\nexport class LensPerformanceMeasurement {\n private state: FrameMetricsState = { ...getDefaultFrameMetricsState() };\n private priorFrameCompletedTime?: number;\n\n constructor(private instances: Set<LensPerformanceMeasurement>) {\n this.instances.add(this);\n }\n\n /** @internal */\n update(processingTimeMs: number): void {\n this.computeRunningStats(processingTimeMs);\n }\n\n /**\n * Return a {@link ComputedFrameMetrics} object, containing lens performance metrics.\n *\n * This method may be called multiple times, each time reporting values computed since the time when this instance\n * was created.\n */\n measure(): ComputedFrameMetrics {\n // We count the number of frames in each per-millisecond bucket, stopping when we've counted half the frames --\n // that bucket contains the median.\n let median = 0;\n let count = 0;\n for (; median < this.state.processingTimeBuckets.length; median++) {\n count += this.state.processingTimeBuckets[median];\n if (count >= (this.state.n + 1) / 2) break;\n }\n return {\n avgFps: this.state.avgFps,\n lensFrameProcessingTimeMsAvg: this.state.procFrameMean,\n lensFrameProcessingTimeMsStd: Math.sqrt(this.state.procFrameD2 / this.state.procFrameCount),\n lensFrameProcessingTimeMsMedian: this.state.n > 0 ? median : 0,\n lensFrameProcessingN: this.state.n,\n };\n }\n\n /**\n * Reset the measured performance statistics (averages, std deviations). This is equivalent to using\n * {@link LensPerformanceMetrics.beginMeasurement} to create a new LensPerformanceMeasurement instance, but may be\n * more convenient.\n */\n reset(): void {\n this.state = { ...getDefaultFrameMetricsState() };\n }\n\n /**\n * Stop measuring performance statistics.\n *\n * This instance will not be garbage collected until this method is called. Therefore it is important to call this\n * method at the appropriate time to avoid leaking memory -- particularly if your application creates many\n * LensPerformanceMeasurement instances.\n */\n end(): void {\n this.instances.delete(this);\n }\n /**\n * In order to calculate the mean, variance, and standard deviation for the processing times\n * we are using Welford's online algorithm.\n * https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm\n *\n * @param processingTimeMs Processing time that is returned from registered callback\n */\n private computeRunningStats(processingTimeMs: number) {\n // calculate mean and delta squared for variance and standard deviation\n const delta = processingTimeMs - this.state.procFrameMean;\n this.state.procFrameCount += 1;\n this.state.procFrameMean += delta / this.state.procFrameCount;\n\n const delta2 = processingTimeMs - this.state.procFrameMean;\n this.state.procFrameD2 += delta * delta2;\n\n // Determine average fps\n if (this.priorFrameCompletedTime === undefined) {\n this.priorFrameCompletedTime = performance.now();\n } else {\n const frameDurationSec = (performance.now() - this.priorFrameCompletedTime) / 1000;\n if (frameDurationSec < frameDurationThreshold) {\n this.state.avgFps = (this.state.avgFps + 1 / frameDurationSec) / 2;\n }\n this.priorFrameCompletedTime = performance.now();\n }\n\n // To approximate the median, we put each processing time into a per-millisecond bucket, and then when we\n // compute a measurement, we can count how many frames fell into each bucket. We don't care about latencies\n // above 200ms, since that's already unusably slow (if we regress from 280ms to 320ms, we don't really care\n // since both are unusable).\n this.state.n++;\n this.state.processingTimeBuckets[Math.min(Math.round(processingTimeMs), frameProcessingTimeMedianMax)]++;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensPerformanceMetrics.js","sourceRoot":"","sources":["../../src/session/LensPerformanceMetrics.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE1E,MAAM,MAAM,GAAG,SAAS,CAAC,kBAAkB,CAAC,CAAC;AAC7C,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,sBAAsB;IAG/B,gBAAgB;IAChB,YAAoB,QAAkB;QAAlB,aAAQ,GAAR,QAAQ,CAAU;QAClC,IAAI,CAAC,oBAAoB,GAAG,IAAI,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,QAAQ;aACR,2BAA2B,CAAC;YACzB,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,EAAE,EAAE,EAAE;gBACvC,IAAI;oBACA,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,EAAE;wBAC1D,WAAW,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;qBACxC;iBACJ;gBAAC,OAAO,KAAK,EAAE;oBACZ,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;iBACvB;YACL,CAAC;SACJ,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CACb,MAAM,CAAC,KAAK,CAAC,8DAA8D,KAAK,CAAC,OAAO,EAAE,CAAC,CAC9F,CAAC;IACV,CAAC;IAED;;;;;OAKG;IAEH,gBAAgB;QACZ,OAAO,IAAI,0BAA0B,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACrE,CAAC;CACJ;AAHG;IADC,GAAG;;;oCACgB,0BAA0B;8DAE7C","sourcesContent":["import { errorLoggingDecorator } from \"../logger/errorLoggingDecorator\";\nimport { LensCore } from \"../lens-core-module\";\nimport { getLogger } from \"../logger/logger\";\nimport { LensPerformanceMeasurement } from \"./LensPerformanceMeasurement\";\n\nconst logger = getLogger(\"RenderingMetrics\");\nconst log = errorLoggingDecorator(logger);\n\n/**\n * Use to measure lens rendering performance.\n *\n * The {@link LensPerformanceMetrics.beginMeasurement} method is used to start measuring rendering performance. After\n * a measurement has begun, performance metrics can be read using {@link LensPerformanceMeasurement}.\n *\n * @example\n * ```ts\n * const measurement = cameraKitSession.metrics.beginMeasurement()\n * // some time later\n * console.log(measurement.measure())\n * ```\n *\n * @category Rendering\n * @category Metrics\n */\nexport class LensPerformanceMetrics {\n private readonly measurementInstances: Set<LensPerformanceMeasurement>;\n\n /** @internal */\n constructor(private lensCore: LensCore) {\n this.measurementInstances = new Set();\n this.lensCore\n .setOnFrameProcessedCallback({\n onFrameProcessed: ({ processingTimeMs }) => {\n try {\n for (const measurement of this.measurementInstances.values()) {\n measurement.update(processingTimeMs);\n }\n } catch (error) {\n logger.error(error);\n }\n },\n })\n .catch((error) =>\n logger.error(`Failed registering setOnFrameProcessedCallback with error: ${error.message}`)\n );\n }\n\n /**\n * Begin a measurement window, during which time rendering metrics will be gathered.\n *\n * @returns A {@link LensPerformanceMeasurement} representing an ongoing measurement of aggregated rendering\n * metrics, from which specific metrics can be obtained.\n */\n @log\n beginMeasurement(): LensPerformanceMeasurement {\n return new LensPerformanceMeasurement(this.measurementInstances);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"LensPerformanceMetrics.js","sourceRoot":"","sources":["../../src/session/LensPerformanceMetrics.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE1E,MAAM,MAAM,GAAG,SAAS,CAAC,kBAAkB,CAAC,CAAC;AAC7C,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,sBAAsB;IAG/B,gBAAgB;IAChB,YAAoB,QAAkB;QAAlB,aAAQ,GAAR,QAAQ,CAAU;QAClC,IAAI,CAAC,oBAAoB,GAAG,IAAI,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,QAAQ;aACR,2BAA2B,CAAC;YACzB,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,EAAE,EAAE,EAAE;gBACvC,IAAI;oBACA,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,EAAE;wBAC1D,WAAW,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;qBACxC;iBACJ;gBAAC,OAAO,KAAK,EAAE;oBACZ,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;iBACvB;YACL,CAAC;SACJ,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CACb,MAAM,CAAC,KAAK,CAAC,8DAA8D,KAAK,CAAC,OAAO,EAAE,CAAC,CAC9F,CAAC;IACV,CAAC;IAED;;;;;OAKG;IAEH,gBAAgB;QACZ,OAAO,IAAI,0BAA0B,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACrE,CAAC;CACJ;AAHG;IADC,GAAG;;;oCACgB,0BAA0B;8DAE7C","sourcesContent":["import { errorLoggingDecorator } from \"../logger/errorLoggingDecorator\";\nimport { LensCore } from \"../lens-core-module/lensCore\";\nimport { getLogger } from \"../logger/logger\";\nimport { LensPerformanceMeasurement } from \"./LensPerformanceMeasurement\";\n\nconst logger = getLogger(\"RenderingMetrics\");\nconst log = errorLoggingDecorator(logger);\n\n/**\n * Use to measure lens rendering performance.\n *\n * The {@link LensPerformanceMetrics.beginMeasurement} method is used to start measuring rendering performance. After\n * a measurement has begun, performance metrics can be read using {@link LensPerformanceMeasurement}.\n *\n * @example\n * ```ts\n * const measurement = cameraKitSession.metrics.beginMeasurement()\n * // some time later\n * console.log(measurement.measure())\n * ```\n *\n * @category Rendering\n * @category Metrics\n */\nexport class LensPerformanceMetrics {\n private readonly measurementInstances: Set<LensPerformanceMeasurement>;\n\n /** @internal */\n constructor(private lensCore: LensCore) {\n this.measurementInstances = new Set();\n this.lensCore\n .setOnFrameProcessedCallback({\n onFrameProcessed: ({ processingTimeMs }) => {\n try {\n for (const measurement of this.measurementInstances.values()) {\n measurement.update(processingTimeMs);\n }\n } catch (error) {\n logger.error(error);\n }\n },\n })\n .catch((error) =>\n logger.error(`Failed registering setOnFrameProcessedCallback with error: ${error.message}`)\n );\n }\n\n /**\n * Begin a measurement window, during which time rendering metrics will be gathered.\n *\n * @returns A {@link LensPerformanceMeasurement} representing an ongoing measurement of aggregated rendering\n * metrics, from which specific metrics can be obtained.\n */\n @log\n beginMeasurement(): LensPerformanceMeasurement {\n return new LensPerformanceMeasurement(this.measurementInstances);\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { StateMachine } from "@snap/state-management";
|
|
2
2
|
import { Lens } from "../lens/Lens";
|
|
3
3
|
import { LensRepository } from "../lens/LensRepository";
|
|
4
|
-
import { LensCore } from "../lens-core-module";
|
|
5
4
|
import { IndexedDBPersistence } from "../persistence/IndexedDBPersistence";
|
|
6
5
|
import { LensLaunchData } from "../lens/LensLaunchData";
|
|
7
6
|
import { LensAssetRepository } from "../lens/assets/LensAssetRepository";
|
|
8
7
|
import { LegalError, LensContentValidationError, LensError } from "../namedErrors";
|
|
9
|
-
import {
|
|
8
|
+
import { MetricsClient } from "../clients/metricsClient";
|
|
9
|
+
import { LensCore } from "../lens-core-module/lensCore";
|
|
10
10
|
declare const createLensState: () => StateMachine<import("@snap/state-management").Action<"applyLens", {
|
|
11
11
|
lens: Lens;
|
|
12
12
|
launchData?: LensLaunchData | undefined;
|
|
@@ -17,7 +17,7 @@ declare const createLensState: () => StateMachine<import("@snap/state-management
|
|
|
17
17
|
export type LensErrors = LegalError | LensContentValidationError | LensError;
|
|
18
18
|
export type LensState = ReturnType<typeof createLensState>;
|
|
19
19
|
export declare const lensStateFactory: {
|
|
20
|
-
(args_0: LensCore, args_1: LensRepository, args_2: LensAssetRepository, args_3: IndexedDBPersistence<ArrayBuffer>, args_4: StateMachine<import("@snap/state-management").Action<"requestLegalPrompt", undefined> | import("@snap/state-management").Action<"accept", string> | import("@snap/state-management").Action<"reject", string>, import("@snap/state-management").State<"unknown", undefined> | import("@snap/state-management").State<"accepted", undefined> | import("@snap/state-management").State<"rejected", undefined>>, args_5:
|
|
20
|
+
(args_0: LensCore, args_1: LensRepository, args_2: LensAssetRepository, args_3: IndexedDBPersistence<ArrayBuffer>, args_4: StateMachine<import("@snap/state-management").Action<"requestLegalPrompt", undefined> | import("@snap/state-management").Action<"accept", string> | import("@snap/state-management").Action<"reject", string>, import("@snap/state-management").State<"unknown", undefined> | import("@snap/state-management").State<"accepted", undefined> | import("@snap/state-management").State<"rejected", undefined>>, args_5: MetricsClient): StateMachine<import("@snap/state-management").Action<"applyLens", {
|
|
21
21
|
lens: Lens;
|
|
22
22
|
launchData?: LensLaunchData | undefined;
|
|
23
23
|
}> | import("@snap/state-management").Action<"downloadComplete", Lens> | import("@snap/state-management").Action<"turnedOn", Lens> | import("@snap/state-management").Action<"resourcesLoaded", Lens> | import("@snap/state-management").Action<"firstFrameProcessed", Lens> | import("@snap/state-management").Action<"applyLensComplete", Lens> | import("@snap/state-management").Action<"applyLensFailed", {
|
|
@@ -25,6 +25,6 @@ export declare const lensStateFactory: {
|
|
|
25
25
|
lens: Lens;
|
|
26
26
|
}> | import("@snap/state-management").Action<"applyLensAborted", Lens> | import("@snap/state-management").Action<"removeLens", undefined> | import("@snap/state-management").Action<"turnedOff", Lens> | import("@snap/state-management").Action<"removeLensComplete", undefined> | import("@snap/state-management").Action<"removeLensFailed", Error>, import("@snap/state-management").State<"noLensApplied", undefined> | import("@snap/state-management").State<"applyingLens", Lens> | import("@snap/state-management").State<"lensApplied", Lens>>;
|
|
27
27
|
token: "lensState";
|
|
28
|
-
dependencies: readonly ["lensCore", "LensRepository", "lensAssetRepository", "lensPersistenceStore", "legalState", "
|
|
28
|
+
dependencies: readonly ["lensCore", "LensRepository", "lensAssetRepository", "lensPersistenceStore", "legalState", "metricsClient"];
|
|
29
29
|
};
|
|
30
30
|
export {};
|
package/lib/session/lensState.js
CHANGED
|
@@ -2,7 +2,6 @@ import { defineAction, defineActions, defineState, defineStates, dispatch, forAc
|
|
|
2
2
|
import { catchError, exhaustMap, from, map, merge, mergeMap, Observable, of, switchMap, take, takeUntil, tap, } from "rxjs";
|
|
3
3
|
import { Injectable } from "../dependency-injection/Injectable";
|
|
4
4
|
import { lensRepositoryFactory } from "../lens/LensRepository";
|
|
5
|
-
import { lensCoreFactory } from "../lens-core-module";
|
|
6
5
|
import { lensPersistenceStoreFactory } from "../lens/LensPersistenceStore";
|
|
7
6
|
import { encodeLensLaunchData } from "../lens/LensLaunchData";
|
|
8
7
|
import { legalStateFactory } from "../legal/legalState";
|
|
@@ -10,9 +9,10 @@ import { lensAssetRepositoryFactory } from "../lens/assets/LensAssetRepository";
|
|
|
10
9
|
import { legalError, lensContentValidationError, lensError, } from "../namedErrors";
|
|
11
10
|
import { getLogger } from "../logger/logger";
|
|
12
11
|
import { Timer } from "../metrics/operational/Timer";
|
|
13
|
-
import { operationalMetricReporterFactory, } from "../metrics/operational/operationalMetricsReporter";
|
|
14
12
|
import { unsubscribed } from "../observable-operators/unsubscribed";
|
|
15
13
|
import { assertUnreachable } from "../common/assertions";
|
|
14
|
+
import { metricsClientFactory } from "../clients/metricsClient";
|
|
15
|
+
import { lensCoreFactory } from "../lens-core-module/loader/lensCoreFactory";
|
|
16
16
|
const logger = getLogger("LensState");
|
|
17
17
|
const createLensState = () => {
|
|
18
18
|
const actions = defineActions(defineAction("applyLens")(), defineAction("downloadComplete")(), defineAction("turnedOn")(), defineAction("resourcesLoaded")(), defineAction("firstFrameProcessed")(), defineAction("applyLensComplete")(), defineAction("applyLensFailed")(), defineAction("applyLensAborted")(), defineAction("removeLens")(), defineAction("turnedOff")(), defineAction("removeLensComplete")(), defineAction("removeLensFailed")());
|
|
@@ -27,8 +27,8 @@ export const lensStateFactory = Injectable("lensState", [
|
|
|
27
27
|
lensAssetRepositoryFactory.token,
|
|
28
28
|
lensPersistenceStoreFactory.token,
|
|
29
29
|
legalStateFactory.token,
|
|
30
|
-
|
|
31
|
-
], (lensCore, lensRepository, lensAssetRepository, lensPersistence, legalState,
|
|
30
|
+
metricsClientFactory.token,
|
|
31
|
+
], (lensCore, lensRepository, lensAssetRepository, lensPersistence, legalState, metrics) => {
|
|
32
32
|
const lensState = createLensState();
|
|
33
33
|
let firstLensApply = true;
|
|
34
34
|
/**
|
|
@@ -130,7 +130,7 @@ export const lensStateFactory = Injectable("lensState", [
|
|
|
130
130
|
onFirstFrameProcessed: () => {
|
|
131
131
|
coreTimer.measure("first-frame");
|
|
132
132
|
applyTimer.measure("success");
|
|
133
|
-
applyTimer.stopAndReport(
|
|
133
|
+
applyTimer.stopAndReport(metrics);
|
|
134
134
|
dispatch("firstFrameProcessed");
|
|
135
135
|
}, onTurnOff: () => dispatch("turnedOff") }),
|
|
136
136
|
],
|
|
@@ -151,7 +151,7 @@ export const lensStateFactory = Injectable("lensState", [
|
|
|
151
151
|
.catch((lensCoreError) => {
|
|
152
152
|
coreTimer.measure("failure");
|
|
153
153
|
applyTimer.measure("failure");
|
|
154
|
-
applyTimer.stopAndReport(
|
|
154
|
+
applyTimer.stopAndReport(metrics);
|
|
155
155
|
const message = `Failed to apply lens ${lensInput.lensId}.`;
|
|
156
156
|
const error = /validation failed/.test(lensCoreError.message)
|
|
157
157
|
? lensContentValidationError(message, lensCoreError)
|
|
@@ -161,7 +161,7 @@ export const lensStateFactory = Injectable("lensState", [
|
|
|
161
161
|
});
|
|
162
162
|
})), catchError((error) => {
|
|
163
163
|
applyTimer.measure("failure");
|
|
164
|
-
applyTimer.stopAndReport(
|
|
164
|
+
applyTimer.stopAndReport(metrics);
|
|
165
165
|
return of(lensState.actions.applyLensFailed({ error, lens }));
|
|
166
166
|
}),
|
|
167
167
|
// If a new applyLens is received, `switchMap` will unsubscribe from this inner observable,
|
|
@@ -169,7 +169,7 @@ export const lensStateFactory = Injectable("lensState", [
|
|
|
169
169
|
// to measure aborted lens applications.
|
|
170
170
|
unsubscribed(() => {
|
|
171
171
|
applyTimer.measure("abort");
|
|
172
|
-
applyTimer.stopAndReport(
|
|
172
|
+
applyTimer.stopAndReport(metrics);
|
|
173
173
|
}));
|
|
174
174
|
}), dispatch(lensState))
|
|
175
175
|
.subscribe({
|
|
@@ -199,8 +199,8 @@ export const lensStateFactory = Injectable("lensState", [
|
|
|
199
199
|
.pipe(inStates("applyingLens"), forActions("removeLens"), switchMap(([a]) => lensState.events.pipe(
|
|
200
200
|
// Wait to remove the lens until it has been applied.
|
|
201
201
|
inStates("lensApplied"),
|
|
202
|
-
// But cancel the removal if a new applyLens
|
|
203
|
-
// make sure the latest apply/remove
|
|
202
|
+
// But cancel the removal if a new applyLens supersedes the current lens. The goal here is to
|
|
203
|
+
// make sure the latest apply/remove preempts any previous request to apply/remove.
|
|
204
204
|
takeUntil(lensState.events.pipe(forActions("applyLens"))), map(() => a))), dispatch(lensState))
|
|
205
205
|
.subscribe({
|
|
206
206
|
error: logger.error,
|