@snap/camera-kit 0.9.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -15
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/CameraKit.html +116 -98
- package/docs/html/classes/CameraKitSession.html +175 -152
- package/docs/html/classes/CameraKitSource.html +109 -99
- package/docs/html/classes/LensPerformanceMeasurement.html +98 -92
- package/docs/html/classes/LensPerformanceMetrics.html +83 -79
- package/docs/html/classes/LensRepository.html +120 -107
- package/docs/html/classes/LensSources.html +86 -80
- package/docs/html/classes/Transform2D.html +98 -92
- package/docs/html/classes/TypedCustomEvent.html +83 -80
- package/docs/html/classes/TypedEventTarget.html +92 -89
- package/docs/html/functions/Injectable.html +87 -78
- package/docs/html/functions/bootstrapCameraKit.html +89 -84
- package/docs/html/functions/createExtension.html +76 -73
- package/docs/html/functions/createImageSource.html +80 -75
- package/docs/html/functions/createMediaStreamSource.html +81 -76
- package/docs/html/functions/createUserMediaSource.html +84 -75
- package/docs/html/functions/createVideoSource.html +80 -75
- package/docs/html/functions/estimateLensPerformance.html +76 -73
- package/docs/html/functions/getRequiredBootstrapURLs.html +78 -74
- package/docs/html/functions/lensSourcesFactory.html +74 -72
- package/docs/html/functions/uriHandlersFactory.html +76 -73
- package/docs/html/index.html +80 -78
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +107 -98
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +82 -79
- package/docs/html/interfaces/ComputedFrameMetrics.html +94 -82
- package/docs/html/interfaces/CreateSessionOptions.html +86 -81
- package/docs/html/interfaces/EstimatedLensPerformance.html +85 -82
- package/docs/html/interfaces/Lens.html +120 -102
- package/docs/html/interfaces/LensSource.html +102 -92
- package/docs/html/interfaces/MediaStreamSourceOptions.html +80 -78
- package/docs/html/interfaces/Preview.html +135 -0
- package/docs/html/interfaces/Snapcode.html +143 -0
- package/docs/html/interfaces/UriCancelRequest.html +80 -78
- package/docs/html/interfaces/UriHandler.html +102 -91
- package/docs/html/interfaces/UriRequest.html +89 -87
- package/docs/html/interfaces/UriResponse.html +89 -87
- package/docs/html/interfaces/VideoSourceOptions.html +77 -75
- package/docs/html/modules.html +153 -149
- package/docs/html/types/AssetLoader.html +75 -72
- package/docs/html/types/AssetTiming.html +75 -72
- package/docs/html/types/BenchmarkError.html +73 -71
- package/docs/html/types/BootstrapError.html +75 -72
- package/docs/html/types/CacheKeyNotFoundError.html +73 -71
- package/docs/html/types/CameraKitDeviceInfo.html +75 -72
- package/docs/html/types/CameraKitSessionEventListener.html +75 -72
- package/docs/html/types/CameraKitSessionEvents.html +82 -72
- package/docs/html/types/CameraKitSourceError.html +73 -71
- package/docs/html/types/CameraKitSourceInfo.html +73 -71
- package/docs/html/types/CameraKitSourceOptions.html +75 -72
- package/docs/html/types/ConfigurationError.html +75 -72
- package/docs/html/types/Keyboard.html +85 -78
- package/docs/html/types/KeyboardEvents.html +84 -72
- package/docs/html/types/LegalError.html +73 -71
- package/docs/html/types/LensAssetError.html +75 -72
- package/docs/html/types/LensContentValidationError.html +73 -71
- package/docs/html/types/LensError.html +73 -71
- package/docs/html/types/LensExecutionError.html +75 -72
- package/docs/html/types/LensImagePickerError.html +75 -72
- package/docs/html/types/LensLaunchParams.html +75 -72
- package/docs/html/types/LensMetricsEvents.html +75 -72
- package/docs/html/types/LensPerformanceCluster.html +75 -72
- package/docs/html/types/LensView.html +75 -72
- package/docs/html/types/LensWait.html +75 -72
- package/docs/html/types/PersistentStoreError.html +75 -72
- package/docs/html/types/PlatformNotSupportedError.html +75 -72
- package/docs/html/types/PublicContainer.html +75 -72
- package/docs/html/types/RenderTarget.html +75 -72
- package/docs/html/types/Uri.html +73 -71
- package/docs/html/types/UriHandlers.html +75 -72
- package/docs/html/types/WebGLError.html +73 -71
- package/docs/html/variables/extensionRequestContext.html +75 -72
- package/docs/md/README.md +18 -15
- package/docs/md/classes/CameraKit.md +14 -1
- package/docs/md/classes/CameraKitSession.md +1 -2
- package/docs/md/classes/CameraKitSource.md +1 -1
- package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
- package/docs/md/classes/LensPerformanceMetrics.md +1 -1
- package/docs/md/classes/LensRepository.md +1 -1
- package/docs/md/classes/LensSources.md +1 -1
- package/docs/md/classes/Transform2D.md +1 -1
- package/docs/md/classes/TypedCustomEvent.md +1 -1
- package/docs/md/classes/TypedEventTarget.md +1 -1
- package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +1 -1
- package/docs/md/interfaces/CameraKitSourceSubscriber.md +1 -1
- package/docs/md/interfaces/ComputedFrameMetrics.md +15 -1
- package/docs/md/interfaces/CreateSessionOptions.md +1 -1
- package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
- package/docs/md/interfaces/Lens.md +14 -3
- package/docs/md/interfaces/LensSource.md +1 -1
- package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
- package/docs/md/interfaces/Preview.md +19 -0
- package/docs/md/interfaces/Snapcode.md +28 -0
- package/docs/md/interfaces/UriCancelRequest.md +1 -1
- package/docs/md/interfaces/UriHandler.md +1 -1
- package/docs/md/interfaces/UriRequest.md +1 -1
- package/docs/md/interfaces/UriResponse.md +1 -1
- package/docs/md/interfaces/VideoSourceOptions.md +1 -1
- package/docs/md/modules.md +11 -3
- package/lib/CameraKit.d.ts +29 -16
- package/lib/CameraKit.js +34 -5
- package/lib/CameraKit.js.map +1 -1
- package/lib/__tests__/data.js +9 -1
- package/lib/__tests__/data.js.map +1 -1
- package/lib/assertPlatformSupported.js +1 -1
- package/lib/assertPlatformSupported.js.map +1 -1
- package/lib/benchmark/webglUtils.js +2 -2
- package/lib/benchmark/webglUtils.js.map +1 -1
- package/lib/bootstrapCameraKit.js +9 -5
- package/lib/bootstrapCameraKit.js.map +1 -1
- package/lib/common/__mocks__/loadScript.d.ts +1 -1
- package/lib/common/__mocks__/loadScript.js +1 -1
- package/lib/common/__mocks__/loadScript.js.map +1 -1
- package/lib/common/dialog.d.ts +16 -0
- package/lib/common/dialog.js +146 -0
- package/lib/common/dialog.js.map +1 -0
- package/lib/common/hash.d.ts +5 -0
- package/lib/common/hash.js +17 -0
- package/lib/common/hash.js.map +1 -0
- package/lib/common/loadScript.d.ts +6 -1
- package/lib/common/loadScript.js +9 -2
- package/lib/common/loadScript.js.map +1 -1
- package/lib/common/localization.d.ts +17 -10
- package/lib/common/localization.js +653 -18
- package/lib/common/localization.js.map +1 -1
- package/lib/common/pageVisibility.d.ts +34 -20
- package/lib/common/pageVisibility.js +57 -48
- package/lib/common/pageVisibility.js.map +1 -1
- package/lib/common/validate.js +2 -2
- package/lib/common/validate.js.map +1 -1
- package/lib/dependency-injection/Container.d.ts +2 -2
- package/lib/dependency-injection/Container.js +10 -10
- package/lib/dependency-injection/Container.js.map +1 -1
- package/lib/dependency-injection/RootServices.d.ts +5 -1
- package/lib/dependency-injection/RootServices.js.map +1 -1
- package/lib/environment.json +1 -1
- package/lib/events/scan.js +1 -1
- package/lib/events/scan.js.map +1 -1
- package/lib/extensions/LensSources.d.ts +5 -5
- package/lib/extensions/LensSources.js +9 -9
- package/lib/extensions/LensSources.js.map +1 -1
- package/lib/extensions/UriHandlers.d.ts +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +17 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +63 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +38 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +5 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +61 -0
- 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 +64 -3
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +70 -2
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +506 -3
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +125 -3
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +1917 -1852
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +55 -132
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +8 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +265 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +628 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +140 -2
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
- package/lib/generated-proto/pb_schema/common/ruid.d.ts +2 -0
- package/lib/generated-proto/pb_schema/common/ruid.js +2 -0
- package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -1
- package/lib/generated-proto/pb_schema/common/value.d.ts +22 -0
- package/lib/generated-proto/pb_schema/common/value.js +45 -0
- package/lib/generated-proto/pb_schema/common/value.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +2 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.js +12 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -1
- package/lib/handlers/HandlerChainBuilder.js +7 -2
- package/lib/handlers/HandlerChainBuilder.js.map +1 -1
- package/lib/handlers/batchingHandler.d.ts +8 -2
- package/lib/handlers/batchingHandler.js +5 -8
- package/lib/handlers/batchingHandler.js.map +1 -1
- package/lib/handlers/mappingHandler.d.ts +5 -1
- package/lib/handlers/mappingHandler.js +6 -4
- package/lib/handlers/mappingHandler.js.map +1 -1
- package/lib/handlers/rateLimitingHandler.d.ts +5 -1
- package/lib/handlers/rateLimitingHandler.js +6 -4
- package/lib/handlers/rateLimitingHandler.js.map +1 -1
- package/lib/handlers/requestStateEmittingHandler.d.ts +18 -5
- package/lib/handlers/requestStateEmittingHandler.js +12 -8
- package/lib/handlers/requestStateEmittingHandler.js.map +1 -1
- package/lib/handlers/responseCachingHandler.d.ts +1 -1
- package/lib/handlers/responseCachingHandler.js +1 -1
- package/lib/handlers/responseCachingHandler.js.map +1 -1
- package/lib/handlers/retryingHandler.d.ts +5 -1
- package/lib/handlers/retryingHandler.js +13 -9
- package/lib/handlers/retryingHandler.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js.map +1 -1
- package/lib/legal/legalPrompt.d.ts +7 -4
- package/lib/legal/legalPrompt.js +122 -133
- package/lib/legal/legalPrompt.js.map +1 -1
- package/lib/legal/legalState.d.ts +2 -2
- package/lib/legal/legalState.js +52 -38
- package/lib/legal/legalState.js.map +1 -1
- package/lib/lens/Lens.d.ts +32 -3
- package/lib/lens/Lens.js +10 -3
- package/lib/lens/Lens.js.map +1 -1
- package/lib/lens/LensLaunchParams.js +6 -4
- package/lib/lens/LensLaunchParams.js.map +1 -1
- package/lib/lens/LensPersistenceStore.js +1 -1
- package/lib/lens/LensPersistenceStore.js.map +1 -1
- package/lib/lens/LensRepository.d.ts +3 -2
- package/lib/lens/LensRepository.js +6 -5
- package/lib/lens/LensRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetRepository.d.ts +5 -3
- package/lib/lens/assets/LensAssetRepository.js +21 -12
- package/lib/lens/assets/LensAssetRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetsProvider.js +1 -1
- package/lib/lens/assets/LensAssetsProvider.js.map +1 -1
- package/lib/lens/lensEnvelopeUtil.js +1 -1
- package/lib/lens/lensEnvelopeUtil.js.map +1 -1
- package/lib/lens-client-interface/imagePicker.js +2 -2
- package/lib/lens-client-interface/imagePicker.js.map +1 -1
- package/lib/lens-client-interface/lensClientInterface.js +1 -1
- package/lib/lens-client-interface/lensClientInterface.js.map +1 -1
- package/lib/lens-core-module/loader/lensCoreFactory.js +4 -2
- package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -1
- package/lib/lensCoreWasmVersions.json +3 -3
- package/lib/logger/logEntries.d.ts +1 -1
- package/lib/logger/logEntries.js +3 -3
- package/lib/logger/logEntries.js.map +1 -1
- package/lib/logger/logger.d.ts +7 -2
- package/lib/logger/logger.js +9 -4
- package/lib/logger/logger.js.map +1 -1
- package/lib/media-sources/FunctionSource.js +1 -1
- package/lib/media-sources/FunctionSource.js.map +1 -1
- package/lib/media-sources/MediaStreamSource.d.ts +5 -1
- package/lib/media-sources/MediaStreamSource.js +14 -5
- package/lib/media-sources/MediaStreamSource.js.map +1 -1
- package/lib/metrics/businessEventsReporter.d.ts +3 -2
- package/lib/metrics/businessEventsReporter.js +16 -9
- package/lib/metrics/businessEventsReporter.js.map +1 -1
- package/lib/metrics/metricsHandler.d.ts +3 -2
- package/lib/metrics/metricsHandler.js +3 -3
- package/lib/metrics/metricsHandler.js.map +1 -1
- package/lib/metrics/operational/Count.d.ts +17 -0
- package/lib/metrics/operational/Count.js +28 -0
- package/lib/metrics/operational/Count.js.map +1 -0
- package/lib/metrics/operational/Histogram.d.ts +17 -0
- package/lib/metrics/operational/Histogram.js +23 -0
- package/lib/metrics/operational/Histogram.js.map +1 -0
- package/lib/metrics/operational/Metric.d.ts +20 -0
- package/lib/metrics/operational/Metric.js +26 -0
- package/lib/metrics/operational/Metric.js.map +1 -0
- package/lib/metrics/operational/Timer.d.ts +91 -0
- package/lib/metrics/operational/Timer.js +122 -0
- package/lib/metrics/operational/Timer.js.map +1 -0
- package/lib/metrics/{operationalMetricsReporter.d.ts → operational/operationalMetricsReporter.d.ts} +15 -4
- package/lib/metrics/{operationalMetricsReporter.js → operational/operationalMetricsReporter.js} +24 -8
- package/lib/metrics/operational/operationalMetricsReporter.js.map +1 -0
- package/lib/metrics/reporters/reportBenchmarks.d.ts +1 -1
- package/lib/metrics/reporters/reportBenchmarks.js +1 -1
- package/lib/metrics/reporters/reportBenchmarks.js.map +1 -1
- package/lib/metrics/reporters/reportGlobalException.d.ts +1 -1
- package/lib/metrics/reporters/reportGlobalException.js +1 -1
- package/lib/metrics/reporters/reportGlobalException.js.map +1 -1
- package/lib/metrics/reporters/reportHttpMetrics.d.ts +4 -4
- package/lib/metrics/reporters/reportHttpMetrics.js +3 -3
- package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
- package/lib/metrics/reporters/reportLegalState.d.ts +1 -1
- package/lib/metrics/reporters/reportLegalState.js +1 -1
- package/lib/metrics/reporters/reportLegalState.js.map +1 -1
- package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +4 -4
- package/lib/metrics/reporters/reportLensAndAssetDownload.js +7 -3
- package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -1
- package/lib/metrics/reporters/reportLensValidationFailed.d.ts +1 -1
- package/lib/metrics/reporters/reportLensView.d.ts +2 -2
- package/lib/metrics/reporters/reportLensView.js +23 -17
- package/lib/metrics/reporters/reportLensView.js.map +1 -1
- package/lib/metrics/reporters/reportLensWait.d.ts +2 -2
- package/lib/metrics/reporters/reportLensWait.js +1 -1
- package/lib/metrics/reporters/reportLensWait.js.map +1 -1
- package/lib/metrics/reporters/reportSessionException.d.ts +1 -1
- package/lib/metrics/reporters/reporters.d.ts +7 -6
- package/lib/metrics/reporters/reporters.js +3 -3
- package/lib/metrics/reporters/reporters.js.map +1 -1
- package/lib/observable-operators/unsubscribed.d.ts +12 -0
- package/lib/observable-operators/unsubscribed.js +27 -0
- package/lib/observable-operators/unsubscribed.js.map +1 -0
- package/lib/remote-configuration/cofHandler.d.ts +3 -2
- package/lib/remote-configuration/cofHandler.js +8 -4
- package/lib/remote-configuration/cofHandler.js.map +1 -1
- package/lib/remote-configuration/remoteConfiguration.d.ts +16 -4
- package/lib/remote-configuration/remoteConfiguration.js +32 -6
- package/lib/remote-configuration/remoteConfiguration.js.map +1 -1
- package/lib/session/CameraKitSession.d.ts +4 -4
- package/lib/session/CameraKitSession.js +10 -9
- package/lib/session/CameraKitSession.js.map +1 -1
- package/lib/session/LensKeyboard.d.ts +1 -1
- package/lib/session/LensPerformanceMeasurement.d.ts +2 -0
- package/lib/session/LensPerformanceMeasurement.js +27 -4
- package/lib/session/LensPerformanceMeasurement.js.map +1 -1
- package/lib/session/lensState.d.ts +5 -4
- package/lib/session/lensState.js +95 -41
- package/lib/session/lensState.js.map +1 -1
- package/package.json +12 -12
- package/lib/metrics/operationalMetricsReporter.js.map +0 -1
|
@@ -5,8 +5,7 @@ import { dispatch, forActions, inStates, isAction, isState } from "@snap/state-m
|
|
|
5
5
|
import { isLens } from "../lens";
|
|
6
6
|
import { Injectable } from "../dependency-injection/Injectable";
|
|
7
7
|
import { lensCoreFactory } from "../lens-core-module/loader/lensCoreFactory";
|
|
8
|
-
import {
|
|
9
|
-
import { guard, validate } from "../common/validate";
|
|
8
|
+
import { getTypeName, guard, validate } from "../common/validate";
|
|
10
9
|
import { TypedEventTarget } from "../events/TypedEventTarget";
|
|
11
10
|
import { TypedCustomEvent } from "../events/TypedCustomEvent";
|
|
12
11
|
import { cameraKitSourceError } from "../namedErrors";
|
|
@@ -15,6 +14,7 @@ import { createVideoSource } from "../media-sources/VideoSource";
|
|
|
15
14
|
import { getLogger } from "../logger/logger";
|
|
16
15
|
import { errorLoggingDecorator } from "../logger/errorLoggingDecorator";
|
|
17
16
|
import { logEntriesFactory } from "../logger/logEntries";
|
|
17
|
+
import { pageVisibilityFactory } from "../common/pageVisibility";
|
|
18
18
|
import { LensPerformanceMetrics } from "./LensPerformanceMetrics";
|
|
19
19
|
import { lensStateFactory } from "./lensState";
|
|
20
20
|
import { sessionStateFactory } from "./sessionState";
|
|
@@ -51,7 +51,7 @@ export class CameraKitSession {
|
|
|
51
51
|
/**
|
|
52
52
|
* Use this to interact with lenses which require text input.
|
|
53
53
|
*/
|
|
54
|
-
keyboard, lensCore, sessionState, lensState, logEntries) {
|
|
54
|
+
keyboard, lensCore, sessionState, lensState, logEntries, pageVisibility) {
|
|
55
55
|
this.keyboard = keyboard;
|
|
56
56
|
this.lensCore = lensCore;
|
|
57
57
|
this.sessionState = sessionState;
|
|
@@ -80,8 +80,8 @@ export class CameraKitSession {
|
|
|
80
80
|
};
|
|
81
81
|
this.playing = false;
|
|
82
82
|
this.metrics = new LensPerformanceMetrics(this.lensCore);
|
|
83
|
-
const removeOnHidden = onPageHidden(() => this.sessionState.dispatch("suspend", this));
|
|
84
|
-
const removeOnVisible = onPageVisible(() => this.sessionState.dispatch("resume", this));
|
|
83
|
+
const removeOnHidden = pageVisibility.onPageHidden(() => this.sessionState.dispatch("suspend", this));
|
|
84
|
+
const removeOnVisible = pageVisibility.onPageVisible(() => this.sessionState.dispatch("resume", this));
|
|
85
85
|
this.removePageVisibilityHandlers = () => {
|
|
86
86
|
removeOnHidden();
|
|
87
87
|
removeOnVisible();
|
|
@@ -296,7 +296,7 @@ export class CameraKitSession {
|
|
|
296
296
|
// The source will provide its data to LensCore, and use other LensCore APIs (e.g. setRenderSize,
|
|
297
297
|
// setInputTransform) to render the source correctly.
|
|
298
298
|
yield cameraKitSource.attach(this.lensCore, (error) => {
|
|
299
|
-
logger.error(cameraKitSourceError("Error
|
|
299
|
+
logger.error(cameraKitSourceError("Error occurred during source attachment.", error));
|
|
300
300
|
});
|
|
301
301
|
// If attachment is successful, we'll update our source so that we can detach it later.
|
|
302
302
|
this.source = cameraKitSource;
|
|
@@ -353,13 +353,13 @@ export class CameraKitSession {
|
|
|
353
353
|
if (this.source) {
|
|
354
354
|
try {
|
|
355
355
|
yield this.source.detach((error) => {
|
|
356
|
-
logger.error(cameraKitSourceError("Error
|
|
356
|
+
logger.error(cameraKitSourceError("Error occurred during source detachment.", error));
|
|
357
357
|
});
|
|
358
358
|
// If there's a failure to detach, we will report the error and proceed. Failure to detach may lead to a
|
|
359
359
|
// memory leak, but it shouldn't prevent us from switching to the new source.
|
|
360
360
|
}
|
|
361
361
|
catch (error) {
|
|
362
|
-
logger.error(cameraKitSourceError(`Detaching prior source of type ${
|
|
362
|
+
logger.error(cameraKitSourceError(`Detaching prior source of type ${getTypeName(this.source)} failed.`, error));
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
});
|
|
@@ -435,5 +435,6 @@ export const cameraKitSessionFactory = Injectable("CameraKitSession", [
|
|
|
435
435
|
lensKeyboardFactory.token,
|
|
436
436
|
sessionStateFactory.token,
|
|
437
437
|
lensStateFactory.token,
|
|
438
|
-
|
|
438
|
+
pageVisibilityFactory.token,
|
|
439
|
+
], (lensCore, logEntries, keyboard, sessionState, lensState, pageVisibility) => new CameraKitSession(keyboard, lensCore, sessionState, lensState, logEntries, pageVisibility));
|
|
439
440
|
//# sourceMappingURL=CameraKitSession.js.map
|
|
@@ -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,SAAS,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBA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MAAM,CAAC,KAAK,CACR,oBAAoB,CAAC,kCAAkC,OAAO,IAAI,CAAC,MAAM,UAAU,EAAE,KAAK,CAAC,CAC9F,CAAC;iBACL;aACJ;QACL,CAAC;KAAA;CACJ;AAtRS;IAFL,QAAQ;IACR,GAAG;IACa,WAAA,KAAK,CAAC,MAAM,CAAC,CAAA;;;;iDA4B7B;AAgBK;IADL,GAAG;;;;kDAqBH;AAwBK;IAFL,QAAQ;IACR,GAAG;IACQ,WAAA,KAAK,CAAC,sBAAsB,CAAC,CAAA;;;;4CAexC;AAWK;IAFL,QAAQ;IACR,GAAG;IACS,WAAA,KAAK,CAAC,sBAAsB,CAAC,CAAA;;;;6CAgBzC;AAQD;IADC,GAAG;;;;4CAMH;AAQD;IADC,GAAG;;;;8CAMH;AA8BK;IAFL,QAAQ;IACR,GAAG;;;;iDAkCH;AAgBK;IADL,GAAG;;;;mDAOH;AAQK;IADL,GAAG;;;;+CASH;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;CAChB,EACV,CACI,QAAwB,EACxB,UAAgC,EAChC,QAAsB,EACtB,YAA0B,EAC1B,SAAoB,EACtB,EAAE,CAAC,IAAI,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,CAAC,CACrF,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\";\nimport { CanvasType, LensCoreModule } from \"../lens-core-module\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { lensCoreFactory } from \"../lens-core-module/loader/lensCoreFactory\";\nimport { LensLaunchParams } from \"../lens/LensLaunchParams\";\nimport { onPageHidden, onPageVisible } from \"../common/pageVisibility\";\nimport { guard, validate } from \"../common/validate\";\nimport { TypedEventTarget } from \"../events/TypedEventTarget\";\nimport { TypedCustomEvent } from \"../events/TypedCustomEvent\";\nimport { CameraKitDeviceInfo, CameraKitSource } from \"../media-sources/CameraKitSource\";\nimport { cameraKitSourceError } 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 { LensPerformanceMetrics } from \"./LensPerformanceMetrics\";\nimport { lensStateFactory, LensState } from \"./lensState\";\nimport { SessionState, sessionStateFactory } from \"./sessionState\";\nimport { Keyboard, lensKeyboardFactory, LensKeyboard } from \"./LensKeyboard\";\nimport { CameraKitSessionEvents, 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: false | RenderTarget;\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: LensCoreModule,\n private readonly sessionState: SessionState,\n private readonly lensState: LensState,\n logEntries: Observable<LogEntry>\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 = false;\n\n this.metrics = new LensPerformanceMetrics(this.lensCore);\n\n const removeOnHidden = onPageHidden(() => this.sessionState.dispatch(\"suspend\", this));\n const removeOnVisible = 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 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 LensExecutionError and LensImagePickerError errors to apps\n sessionErrors.subscribe((error) => {\n if (error.name !== \"LensExecutionError\" && error.name !== \"LensImagePickerError\") return;\n\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(\n new Error(\"Lens error occurred even though there is no active lens.\", {\n cause: error,\n })\n );\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, launchParams?: LensLaunchParams): Promise<boolean> {\n const action = this.lensState.actions.applyLens({ lens, launchParams });\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) return;\n this.playing = target;\n\n const type = this.renderTargetToCanvasType(target);\n return new Promise((resolve, reject) => {\n this.lensCore.playCanvas({\n type,\n onSuccess: resolve,\n onFailure: (error: Error) => {\n this.playing = false;\n reject(error);\n },\n });\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) return;\n const priorPlayingState = this.playing;\n this.playing = false;\n\n const type = this.renderTargetToCanvasType(target);\n return new Promise((resolve, reject) => {\n this.lensCore.pauseCanvas({\n type,\n onSuccess: resolve,\n onFailure: (error: Error) => {\n this.playing = priorPlayingState;\n reject(error);\n },\n });\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 createUserMediaSource}\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<CameraKitDeviceInfo>\n ): Promise<CameraKitSource>;\n @validate\n @log\n async setSource(\n source: CameraKitSource | MediaStream | HTMLVideoElement,\n options: Partial<CameraKitDeviceInfo> = {}\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 = false;\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 happened 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) {\n await this.play(priorPlayingState);\n }\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 new Promise((onSuccess, onFailure) => {\n this.lensCore.setFPSLimit({ fps, onSuccess, onFailure });\n });\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 this.subscriptions.forEach((sub) => sub.unsubscribe());\n await this.removeLens();\n await this.safelyDetachSource();\n await new Promise<void>((resolve, reject) => {\n this.lensCore.teardown({ onSuccess: resolve, onFailure: reject });\n });\n this.removePageVisibilityHandlers();\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 happened 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 ${typeof 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 ] as const,\n (\n lensCore: LensCoreModule,\n logEntries: Observable<LogEntry>,\n keyboard: LensKeyboard,\n sessionState: SessionState,\n lensState: LensState\n ) => new CameraKitSession(keyboard, lensCore, sessionState, lensState, logEntries)\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,QAAQ,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC3F,OAAO,EAAQ,MAAM,EAAE,MAAM,SAAS,CAAC;AAEvC,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,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8B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K,CACR,oBAAoB,CAAC,kCAAkC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CACpG,CAAC;iBACL;aACJ;QACL,CAAC;KAAA;CACJ;AArRS;IAFL,QAAQ;IACR,GAAG;IACa,WAAA,KAAK,CAAC,MAAM,CAAC,CAAA;;;;iDA4B7B;AAgBK;IADL,GAAG;;;;kDAqBH;AAwBK;IAFL,QAAQ;IACR,GAAG;IACQ,WAAA,KAAK,CAAC,sBAAsB,CAAC,CAAA;;;;4CAexC;AAWK;IAFL,QAAQ;IACR,GAAG;IACS,WAAA,KAAK,CAAC,sBAAsB,CAAC,CAAA;;;;6CAgBzC;AAQD;IADC,GAAG;;;;4CAMH;AAQD;IADC,GAAG;;;;8CAMH;AA6BK;IAFL,QAAQ;IACR,GAAG;;;;iDAkCH;AAgBK;IADL,GAAG;;;;mDAOH;AAQK;IADL,GAAG;;;;+CASH;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,QAAwB,EACxB,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\";\nimport { CanvasType, LensCoreModule } from \"../lens-core-module\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { lensCoreFactory } from \"../lens-core-module/loader/lensCoreFactory\";\nimport { LensLaunchParams } from \"../lens/LensLaunchParams\";\nimport { getTypeName, guard, validate } from \"../common/validate\";\nimport { TypedEventTarget } from \"../events/TypedEventTarget\";\nimport { TypedCustomEvent } from \"../events/TypedCustomEvent\";\nimport { CameraKitDeviceInfo, CameraKitSource } from \"../media-sources/CameraKitSource\";\nimport { cameraKitSourceError } 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, 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: false | RenderTarget;\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: LensCoreModule,\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 = false;\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 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 LensExecutionError and LensImagePickerError errors to apps\n sessionErrors.subscribe((error) => {\n if (error.name !== \"LensExecutionError\" && error.name !== \"LensImagePickerError\") return;\n\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(\n new Error(\"Lens error occurred even though there is no active lens.\", {\n cause: error,\n })\n );\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, launchParams?: LensLaunchParams): Promise<boolean> {\n const action = this.lensState.actions.applyLens({ lens, launchParams });\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) return;\n this.playing = target;\n\n const type = this.renderTargetToCanvasType(target);\n return new Promise((resolve, reject) => {\n this.lensCore.playCanvas({\n type,\n onSuccess: resolve,\n onFailure: (error: Error) => {\n this.playing = false;\n reject(error);\n },\n });\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) return;\n const priorPlayingState = this.playing;\n this.playing = false;\n\n const type = this.renderTargetToCanvasType(target);\n return new Promise((resolve, reject) => {\n this.lensCore.pauseCanvas({\n type,\n onSuccess: resolve,\n onFailure: (error: Error) => {\n this.playing = priorPlayingState;\n reject(error);\n },\n });\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<CameraKitDeviceInfo>\n ): Promise<CameraKitSource>;\n @validate\n @log\n async setSource(\n source: CameraKitSource | MediaStream | HTMLVideoElement,\n options: Partial<CameraKitDeviceInfo> = {}\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 = false;\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) {\n await this.play(priorPlayingState);\n }\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 new Promise((onSuccess, onFailure) => {\n this.lensCore.setFPSLimit({ fps, onSuccess, onFailure });\n });\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 this.subscriptions.forEach((sub) => sub.unsubscribe());\n await this.removeLens();\n await this.safelyDetachSource();\n await new Promise<void>((resolve, reject) => {\n this.lensCore.teardown({ onSuccess: resolve, onFailure: reject });\n });\n this.removePageVisibilityHandlers();\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: LensCoreModule,\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"]}
|
|
@@ -83,7 +83,7 @@ export declare const lensKeyboardFactory: {
|
|
|
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
84
|
error: import("./lensState").LensErrors;
|
|
85
85
|
lens: Lens;
|
|
86
|
-
}> | 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>>): LensKeyboard;
|
|
86
|
+
}> | 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>>): LensKeyboard;
|
|
87
87
|
token: "lensKeyboard";
|
|
88
88
|
dependencies: readonly ["lensState"];
|
|
89
89
|
};
|
|
@@ -6,6 +6,8 @@ export interface ComputedFrameMetrics {
|
|
|
6
6
|
avgFps: number;
|
|
7
7
|
lensFrameProcessingTimeMsAvg: number;
|
|
8
8
|
lensFrameProcessingTimeMsStd: number;
|
|
9
|
+
lensFrameProcessingTimeMsMedian: number;
|
|
10
|
+
lensFrameProcessingN: number;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Represents an ongoing measurement of rendering metrics.
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
const
|
|
1
|
+
const getDefaultFrameMetricsState = () => ({
|
|
2
2
|
avgFps: 0,
|
|
3
3
|
averageProcessingTime: 0,
|
|
4
|
+
n: 0,
|
|
5
|
+
processingTimeBuckets: new Uint32Array(frameProcessingTimeMedianMax + 1),
|
|
4
6
|
procFrameCount: 0,
|
|
5
7
|
procFrameMean: 0,
|
|
6
8
|
procFrameD2: 0,
|
|
7
|
-
};
|
|
9
|
+
});
|
|
8
10
|
// This duration is chosen to be larger than we expect frame processing to reasonably take on any device, but smaller
|
|
9
11
|
// than the duration of a manual rendering pause (e.g. a user clicking a pause button followed by a play button).
|
|
10
12
|
//
|
|
11
13
|
// This also defines the min avgFps that will be reported – if we see avgFps at `1 / frameDurationThresholdSec`
|
|
12
14
|
// consistently, it's safe to assume actual fps is probably even lower.
|
|
13
15
|
const frameDurationThreshold = 1;
|
|
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 unnusably slow, and we don't really care if the true median is greater than
|
|
18
|
+
// 200ms.
|
|
19
|
+
const frameProcessingTimeMedianMax = 200;
|
|
14
20
|
/**
|
|
15
21
|
* Represents an ongoing measurement of rendering metrics.
|
|
16
22
|
*
|
|
@@ -23,7 +29,7 @@ const frameDurationThreshold = 1;
|
|
|
23
29
|
export class LensPerformanceMeasurement {
|
|
24
30
|
constructor(instances) {
|
|
25
31
|
this.instances = instances;
|
|
26
|
-
this.state = Object.assign({},
|
|
32
|
+
this.state = Object.assign({}, getDefaultFrameMetricsState());
|
|
27
33
|
this.instances.add(this);
|
|
28
34
|
}
|
|
29
35
|
/** @internal */
|
|
@@ -37,10 +43,21 @@ export class LensPerformanceMeasurement {
|
|
|
37
43
|
* was created.
|
|
38
44
|
*/
|
|
39
45
|
measure() {
|
|
46
|
+
// We count the number of frames in each per-millisecond bucket, stopping when we've counted half the frames --
|
|
47
|
+
// that bucket contains the median.
|
|
48
|
+
let median = 0;
|
|
49
|
+
let count = 0;
|
|
50
|
+
for (; median < this.state.processingTimeBuckets.length; median++) {
|
|
51
|
+
count += this.state.processingTimeBuckets[median];
|
|
52
|
+
if (count >= (this.state.n + 1) / 2)
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
40
55
|
return {
|
|
41
56
|
avgFps: this.state.avgFps,
|
|
42
57
|
lensFrameProcessingTimeMsAvg: this.state.procFrameMean,
|
|
43
58
|
lensFrameProcessingTimeMsStd: Math.sqrt(this.state.procFrameD2 / this.state.procFrameCount),
|
|
59
|
+
lensFrameProcessingTimeMsMedian: this.state.n > 0 ? median : 0,
|
|
60
|
+
lensFrameProcessingN: this.state.n,
|
|
44
61
|
};
|
|
45
62
|
}
|
|
46
63
|
/**
|
|
@@ -49,7 +66,7 @@ export class LensPerformanceMeasurement {
|
|
|
49
66
|
* more convenient.
|
|
50
67
|
*/
|
|
51
68
|
reset() {
|
|
52
|
-
this.state = Object.assign({},
|
|
69
|
+
this.state = Object.assign({}, getDefaultFrameMetricsState());
|
|
53
70
|
}
|
|
54
71
|
/**
|
|
55
72
|
* Stop measuring performance statistics.
|
|
@@ -86,6 +103,12 @@ export class LensPerformanceMeasurement {
|
|
|
86
103
|
}
|
|
87
104
|
this.priorFrameCompletedTime = performance.now();
|
|
88
105
|
}
|
|
106
|
+
// To approximate the median, we put each processing time into a per-millisecond bucket, and then when we
|
|
107
|
+
// compute a measurement, we can count how many frames fell into each bucket. We don't care about latencies
|
|
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 unnusable).
|
|
110
|
+
this.state.n++;
|
|
111
|
+
this.state.processingTimeBuckets[Math.min(Math.round(processingTimeMs), frameProcessingTimeMedianMax)]++;
|
|
89
112
|
}
|
|
90
113
|
}
|
|
91
114
|
//# sourceMappingURL=LensPerformanceMeasurement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensPerformanceMeasurement.js","sourceRoot":"","sources":["../../src/session/LensPerformanceMeasurement.ts"],"names":[],"mappings":"
|
|
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,qHAAqH;AACrH,SAAS;AACT,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAczC;;;;;;;;GAQG;AACH,MAAM,OAAO,0BAA0B;IAInC,YAAoB,SAA0C;QAA1C,cAAS,GAAT,SAAS,CAAiC;QAHtD,UAAK,qBAA2B,2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Buckets: 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 unnusably 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 perforamance 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 unnusable).\n this.state.n++;\n this.state.processingTimeBuckets[Math.min(Math.round(processingTimeMs), frameProcessingTimeMedianMax)]++;\n }\n}\n"]}
|
|
@@ -6,24 +6,25 @@ import { IndexedDBPersistence } from "../persistence/IndexedDBPersistence";
|
|
|
6
6
|
import { LensLaunchParams } from "../lens/LensLaunchParams";
|
|
7
7
|
import { LensAssetRepository } from "../lens/assets/LensAssetRepository";
|
|
8
8
|
import { LegalError, LensContentValidationError, LensError } from "../namedErrors";
|
|
9
|
+
import { OperationalMetricsReporter } from "../metrics/operational/operationalMetricsReporter";
|
|
9
10
|
declare const createLensState: () => StateMachine<import("@snap/state-management").Action<"applyLens", {
|
|
10
11
|
lens: Lens;
|
|
11
12
|
launchParams?: LensLaunchParams | undefined;
|
|
12
13
|
}> | 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", {
|
|
13
14
|
error: LensErrors;
|
|
14
15
|
lens: Lens;
|
|
15
|
-
}> | 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>>;
|
|
16
|
+
}> | 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>>;
|
|
16
17
|
export type LensErrors = LegalError | LensContentValidationError | LensError;
|
|
17
18
|
export type LensState = ReturnType<typeof createLensState>;
|
|
18
19
|
export declare const lensStateFactory: {
|
|
19
|
-
(args_0: LensCoreModule, 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
|
|
20
|
+
(args_0: LensCoreModule, 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: OperationalMetricsReporter): StateMachine<import("@snap/state-management").Action<"applyLens", {
|
|
20
21
|
lens: Lens;
|
|
21
22
|
launchParams?: LensLaunchParams | undefined;
|
|
22
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", {
|
|
23
24
|
error: LensErrors;
|
|
24
25
|
lens: Lens;
|
|
25
|
-
}> | 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>>;
|
|
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>>;
|
|
26
27
|
token: "lensState";
|
|
27
|
-
dependencies: readonly ["lensCore", "LensRepository", "lensAssetRepository", "lensPersistenceStore", "legalState"];
|
|
28
|
+
dependencies: readonly ["lensCore", "LensRepository", "lensAssetRepository", "lensPersistenceStore", "legalState", "operationalMetricsReporter"];
|
|
28
29
|
};
|
|
29
30
|
export {};
|