@snap/camera-kit 0.13.2 → 0.14.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/docs/html/assets/search.js +1 -1
- package/docs/html/classes/CameraKit.html +4 -3
- package/docs/html/classes/CameraKitSession.html +4 -3
- package/docs/html/classes/CameraKitSource.html +4 -3
- package/docs/html/classes/LensPerformanceMeasurement.html +4 -3
- package/docs/html/classes/LensPerformanceMetrics.html +4 -3
- package/docs/html/classes/LensRepository.html +6 -5
- package/docs/html/classes/LensSources.html +4 -3
- package/docs/html/classes/Transform2D.html +4 -3
- package/docs/html/classes/TypedCustomEvent.html +4 -3
- package/docs/html/classes/TypedEventTarget.html +4 -3
- package/docs/html/functions/Injectable.html +4 -3
- package/docs/html/functions/bootstrapCameraKit.html +4 -3
- package/docs/html/functions/createExtension.html +4 -3
- package/docs/html/functions/createImageSource.html +4 -3
- package/docs/html/functions/createMediaStreamSource.html +4 -3
- package/docs/html/functions/createUserMediaSource.html +4 -3
- package/docs/html/functions/createVideoSource.html +4 -3
- package/docs/html/functions/estimateLensPerformance.html +4 -3
- package/docs/html/functions/getRequiredBootstrapURLs.html +4 -3
- package/docs/html/functions/lensSourcesFactory.html +4 -3
- package/docs/html/functions/remoteApiServicesFactory.html +4 -3
- package/docs/html/index.html +5 -4
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +16 -5
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +5 -4
- package/docs/html/interfaces/ComputedFrameMetrics.html +4 -3
- package/docs/html/interfaces/CreateSessionOptions.html +4 -3
- package/docs/html/interfaces/EstimatedLensPerformance.html +4 -3
- package/docs/html/interfaces/Lens.html +13 -3
- package/docs/html/interfaces/LensSource.html +4 -3
- package/docs/html/interfaces/MediaStreamSourceOptions.html +4 -3
- package/docs/html/interfaces/Preview.html +4 -3
- package/docs/html/interfaces/RemoteApiRequest.html +4 -3
- package/docs/html/interfaces/RemoteApiResponse.html +4 -3
- package/docs/html/interfaces/RemoteApiService.html +4 -3
- package/docs/html/interfaces/Snapcode.html +4 -3
- package/docs/html/interfaces/UriCancelRequest.html +4 -3
- package/docs/html/interfaces/UriRequest.html +4 -3
- package/docs/html/interfaces/UriResponse.html +4 -3
- package/docs/html/interfaces/VideoSourceOptions.html +4 -3
- package/docs/html/modules.html +6 -4
- package/docs/html/types/AssetLoader.html +4 -3
- package/docs/html/types/AssetTiming.html +4 -3
- package/docs/html/types/BenchmarkError.html +4 -3
- package/docs/html/types/BootstrapError.html +4 -3
- package/docs/html/types/CacheKeyNotFoundError.html +4 -3
- package/docs/html/types/CameraKitDeviceInfo.html +4 -3
- package/docs/html/types/CameraKitDeviceOptions.html +4 -3
- package/docs/html/types/CameraKitSessionEventListener.html +4 -3
- package/docs/html/types/CameraKitSessionEvents.html +6 -5
- package/docs/html/types/CameraKitSourceError.html +4 -3
- package/docs/html/types/CameraKitSourceInfo.html +4 -3
- package/docs/html/types/CameraKitSourceOptions.html +4 -3
- package/docs/html/types/ConfigurationError.html +4 -3
- package/docs/html/types/Keyboard.html +4 -3
- package/docs/html/types/KeyboardEvents.html +4 -3
- package/docs/html/types/LegalError.html +4 -3
- package/docs/html/types/LensAbortError.html +119 -0
- package/docs/html/types/LensAssetError.html +4 -3
- package/docs/html/types/LensContentValidationError.html +4 -3
- package/docs/html/types/LensError.html +4 -3
- package/docs/html/types/LensExecutionError.html +4 -3
- package/docs/html/types/LensImagePickerError.html +4 -3
- package/docs/html/types/LensLaunchParams.html +4 -3
- package/docs/html/types/LensMetricsEvents.html +4 -3
- package/docs/html/types/LensPerformanceCluster.html +4 -3
- package/docs/html/types/LensView.html +4 -3
- package/docs/html/types/LensWait.html +4 -3
- package/docs/html/types/PersistentStoreError.html +4 -3
- package/docs/html/types/PlatformNotSupportedError.html +4 -3
- package/docs/html/types/PublicContainer.html +4 -3
- package/docs/html/types/RemoteApiRequestHandler.html +4 -3
- package/docs/html/types/RemoteApiServices.html +4 -3
- package/docs/html/types/RemoteApiStatus.html +4 -3
- package/docs/html/types/RenderTarget.html +4 -3
- package/docs/html/types/Uri.html +4 -3
- package/docs/html/types/WebGLError.html +4 -3
- package/docs/html/variables/extensionRequestContext.html +4 -3
- package/docs/md/classes/CameraKit.md +1 -1
- package/docs/md/classes/CameraKitSession.md +1 -1
- package/docs/md/classes/CameraKitSource.md +1 -1
- package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
- package/docs/md/classes/LensPerformanceMetrics.md +1 -1
- package/docs/md/classes/LensRepository.md +3 -3
- package/docs/md/classes/LensSources.md +1 -1
- package/docs/md/classes/Transform2D.md +1 -1
- package/docs/md/classes/TypedCustomEvent.md +1 -1
- package/docs/md/classes/TypedEventTarget.md +1 -1
- package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +13 -2
- package/docs/md/interfaces/CameraKitSourceSubscriber.md +3 -3
- package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
- package/docs/md/interfaces/CreateSessionOptions.md +1 -1
- package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
- package/docs/md/interfaces/Lens.md +11 -1
- package/docs/md/interfaces/LensSource.md +1 -1
- package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
- package/docs/md/interfaces/Preview.md +1 -1
- package/docs/md/interfaces/RemoteApiRequest.md +1 -1
- package/docs/md/interfaces/RemoteApiResponse.md +1 -1
- package/docs/md/interfaces/RemoteApiService.md +1 -1
- package/docs/md/interfaces/Snapcode.md +1 -1
- package/docs/md/interfaces/UriCancelRequest.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 +24 -4
- package/lib/CameraKit.d.ts +139 -7
- package/lib/CameraKit.js +19 -19
- package/lib/CameraKit.js.map +1 -1
- package/lib/__tests__/data.d.ts +9 -4
- package/lib/__tests__/data.js +19 -9
- package/lib/__tests__/data.js.map +1 -1
- package/lib/bootstrapCameraKit.js +2 -2
- package/lib/bootstrapCameraKit.js.map +1 -1
- package/lib/common/localization.js +7 -31
- package/lib/common/localization.js.map +1 -1
- package/lib/configuration.d.ts +7 -0
- package/lib/configuration.js +1 -0
- package/lib/configuration.js.map +1 -1
- package/lib/configurationOverrides.d.ts +2 -2
- package/lib/configurationOverrides.js +11 -6
- package/lib/configurationOverrides.js.map +1 -1
- package/lib/dependency-injection/RootServices.d.ts +2 -2
- package/lib/dependency-injection/RootServices.js.map +1 -1
- package/lib/environment.json +1 -1
- package/lib/extensions/extensionRequestContext.js +4 -4
- package/lib/extensions/extensionRequestContext.js.map +1 -1
- package/lib/extensions/uriHandlersRegister.d.ts +2 -2
- package/lib/extensions/uriHandlersRegister.js.map +1 -1
- package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +272 -0
- package/lib/generated-proto/blizzard/cameraKitEvents.js +38 -24
- package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -1
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.js +2 -2
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/lens/Lens.d.ts +9 -1
- package/lib/lens/Lens.js +2 -1
- package/lib/lens/Lens.js.map +1 -1
- package/lib/lens/LensPersistenceStore.d.ts +2 -2
- package/lib/lens/LensPersistenceStore.js.map +1 -1
- package/lib/lens/LensRepository.d.ts +2 -2
- package/lib/lens/LensRepository.js +5 -4
- package/lib/lens/LensRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetRepository.d.ts +4 -4
- package/lib/lens/assets/LensAssetRepository.js +1 -3
- package/lib/lens/assets/LensAssetRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetsProvider.d.ts +9 -3
- package/lib/lens/assets/LensAssetsProvider.js +12 -5
- package/lib/lens/assets/LensAssetsProvider.js.map +1 -1
- package/lib/lens-client-interface/imagePicker.d.ts +2 -2
- package/lib/lens-client-interface/imagePicker.js.map +1 -1
- package/lib/lens-client-interface/lensClientInterface.d.ts +2 -2
- package/lib/lens-client-interface/lensClientInterface.js.map +1 -1
- package/lib/lens-core-module/generated-types.d.ts +4 -2
- package/lib/lens-core-module/generated-types.js.map +1 -1
- package/lib/lens-core-module/index.d.ts +1 -0
- package/lib/lens-core-module/index.js +1 -0
- package/lib/lens-core-module/index.js.map +1 -1
- package/lib/lens-core-module/lensCore.d.ts +41 -0
- package/lib/lens-core-module/lensCore.js +54 -0
- package/lib/lens-core-module/lensCore.js.map +1 -0
- package/lib/lens-core-module/lensCoreError.d.ts +15 -0
- package/lib/lens-core-module/lensCoreError.js +43 -0
- package/lib/lens-core-module/lensCoreError.js.map +1 -0
- package/lib/lens-core-module/loader/lensCoreFactory.d.ts +1 -2
- package/lib/lens-core-module/loader/lensCoreFactory.js +24 -26
- package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -1
- package/lib/lensCoreWasmVersions.json +3 -3
- package/lib/logger/registerLogEntriesSubscriber.js +2 -2
- package/lib/logger/registerLogEntriesSubscriber.js.map +1 -1
- package/lib/media-sources/CameraKitSource.d.ts +3 -3
- package/lib/media-sources/CameraKitSource.js +22 -31
- package/lib/media-sources/CameraKitSource.js.map +1 -1
- package/lib/media-sources/FunctionSource.js +33 -36
- package/lib/media-sources/FunctionSource.js.map +1 -1
- package/lib/media-sources/MediaStreamSource.js +11 -15
- package/lib/media-sources/MediaStreamSource.js.map +1 -1
- package/lib/metrics/businessEventsReporter.js +114 -108
- package/lib/metrics/businessEventsReporter.js.map +1 -1
- package/lib/metrics/reporters/reportGlobalException.js +25 -7
- package/lib/metrics/reporters/reportGlobalException.js.map +1 -1
- package/lib/metrics/reporters/reportHttpMetrics.js +2 -2
- package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
- package/lib/metrics/reporters/reportLensView.js +5 -3
- package/lib/metrics/reporters/reportLensView.js.map +1 -1
- package/lib/metrics/reporters/reportLensWait.js +8 -2
- package/lib/metrics/reporters/reportLensWait.js.map +1 -1
- package/lib/metrics/reporters/reportPlatformCapabilities.d.ts +12 -0
- package/lib/metrics/reporters/reportPlatformCapabilities.js +18 -0
- package/lib/metrics/reporters/reportPlatformCapabilities.js.map +1 -0
- package/lib/metrics/reporters/reporters.d.ts +2 -1
- package/lib/metrics/reporters/reporters.js +3 -1
- package/lib/metrics/reporters/reporters.js.map +1 -1
- package/lib/namedErrors.d.ts +17 -0
- package/lib/namedErrors.js +2 -0
- package/lib/namedErrors.js.map +1 -1
- package/lib/platform/assertPlatformSupported.d.ts +4 -0
- package/lib/platform/assertPlatformSupported.js +15 -0
- package/lib/platform/assertPlatformSupported.js.map +1 -0
- package/lib/platform/cameraKitUserAgent.d.ts +2 -0
- package/lib/platform/cameraKitUserAgent.js +20 -0
- package/lib/platform/cameraKitUserAgent.js.map +1 -0
- package/lib/platform/platformCapabilities.d.ts +50 -0
- package/lib/platform/platformCapabilities.js +121 -0
- package/lib/platform/platformCapabilities.js.map +1 -0
- package/lib/{common/cameraKitUserAgent.d.ts → platform/platformInfo.d.ts} +13 -10
- package/lib/{common/cameraKitUserAgent.js → platform/platformInfo.js} +94 -100
- package/lib/platform/platformInfo.js.map +1 -0
- package/lib/remote-configuration/cofHandler.js +2 -2
- package/lib/remote-configuration/cofHandler.js.map +1 -1
- package/lib/remote-configuration/preloadConfiguration.d.ts +2 -2
- package/lib/remote-configuration/preloadConfiguration.js.map +1 -1
- package/lib/session/CameraKitSession.d.ts +3 -3
- package/lib/session/CameraKitSession.js +23 -30
- package/lib/session/CameraKitSession.js.map +1 -1
- package/lib/session/CameraKitSessionEvents.d.ts +7 -3
- package/lib/session/CameraKitSessionEvents.js +17 -0
- package/lib/session/CameraKitSessionEvents.js.map +1 -1
- package/lib/session/LensPerformanceMetrics.d.ts +2 -2
- package/lib/session/LensPerformanceMetrics.js +4 -3
- package/lib/session/LensPerformanceMetrics.js.map +1 -1
- package/lib/session/lensState.d.ts +2 -2
- package/lib/session/lensState.js +36 -37
- package/lib/session/lensState.js.map +1 -1
- package/package.json +2 -2
- package/lib/assertPlatformSupported.d.ts +0 -6
- package/lib/assertPlatformSupported.js +0 -21
- package/lib/assertPlatformSupported.js.map +0 -1
- package/lib/common/cameraKitUserAgent.js.map +0 -1
- package/lib/common/locale.d.ts +0 -2
- package/lib/common/locale.js +0 -11
- package/lib/common/locale.js.map +0 -1
package/lib/CameraKit.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LensRepository } from "./lens/LensRepository";
|
|
2
2
|
import { Container } from "./dependency-injection/Container";
|
|
3
|
-
import {
|
|
3
|
+
import { LensCoreError } from "./lens-core-module/lensCoreError";
|
|
4
|
+
import { LensCore } from "./lens-core-module/lensCore";
|
|
4
5
|
import { CameraKitSession } from "./session/CameraKitSession";
|
|
5
6
|
import { RootServices } from "./dependency-injection/RootServices";
|
|
6
7
|
import { MetricsEventTarget } from "./metrics/metricsEventTarget";
|
|
@@ -81,7 +82,7 @@ export declare class CameraKit {
|
|
|
81
82
|
/**
|
|
82
83
|
* Used to query for lenses and lens groups.
|
|
83
84
|
*/
|
|
84
|
-
lensRepository: LensRepository, lensCore:
|
|
85
|
+
lensRepository: LensRepository, lensCore: LensCore, pageVisibility: PageVisibility, container: Container<RootServices>, allMetrics: MetricsEventTarget);
|
|
85
86
|
/**
|
|
86
87
|
* Create a CameraKitSession.
|
|
87
88
|
*
|
|
@@ -107,16 +108,147 @@ export declare class CameraKit {
|
|
|
107
108
|
}
|
|
108
109
|
/** @internal */
|
|
109
110
|
export declare const cameraKitFactory: {
|
|
110
|
-
(args_0: LensRepository, args_1: MetricsEventTarget, args_2:
|
|
111
|
+
(args_0: LensRepository, args_1: MetricsEventTarget, args_2: {
|
|
112
|
+
ErrorType: {
|
|
113
|
+
LensDeserialization: import("./lens-core-module").LensCoreEnumValue;
|
|
114
|
+
Validation: import("./lens-core-module").LensCoreEnumValue;
|
|
115
|
+
Uncategorized: import("./lens-core-module").LensCoreEnumValue;
|
|
116
|
+
LensExecution: import("./lens-core-module").LensCoreEnumValue;
|
|
117
|
+
Abort: import("./lens-core-module").LensCoreEnumValue;
|
|
118
|
+
Uninitialized: import("./lens-core-module").LensCoreEnumValue;
|
|
119
|
+
};
|
|
120
|
+
AssetType: {
|
|
121
|
+
RemoteMediaByUrl: import("./lens-core-module").LensCoreEnumValue;
|
|
122
|
+
DeviceDependent: import("./lens-core-module").LensCoreEnumValue;
|
|
123
|
+
Static: import("./lens-core-module").LensCoreEnumValue;
|
|
124
|
+
URL: import("./lens-core-module").LensCoreEnumValue;
|
|
125
|
+
BitmojiDynamicAsset: import("./lens-core-module").LensCoreEnumValue;
|
|
126
|
+
};
|
|
127
|
+
CanvasType: {
|
|
128
|
+
None: import("./lens-core-module").LensCoreEnumValue;
|
|
129
|
+
Preview: import("./lens-core-module").LensCoreEnumValue;
|
|
130
|
+
Capture: import("./lens-core-module").LensCoreEnumValue;
|
|
131
|
+
All: import("./lens-core-module").LensCoreEnumValue;
|
|
132
|
+
};
|
|
133
|
+
LensApiVisibility: {
|
|
134
|
+
Dev: import("./lens-core-module").LensCoreEnumValue;
|
|
135
|
+
Private: import("./lens-core-module").LensCoreEnumValue;
|
|
136
|
+
Public: import("./lens-core-module").LensCoreEnumValue;
|
|
137
|
+
};
|
|
138
|
+
DeviceClass: {
|
|
139
|
+
Undefined: import("./lens-core-module").LensCoreEnumValue;
|
|
140
|
+
BarelyWorking: import("./lens-core-module").LensCoreEnumValue;
|
|
141
|
+
LowEnd: import("./lens-core-module").LensCoreEnumValue;
|
|
142
|
+
MidEnd: import("./lens-core-module").LensCoreEnumValue;
|
|
143
|
+
HighEnd: import("./lens-core-module").LensCoreEnumValue;
|
|
144
|
+
};
|
|
145
|
+
RenderLoopMode: {
|
|
146
|
+
SetTimeout: import("./lens-core-module").LensCoreEnumValue;
|
|
147
|
+
RequestAnimationFrame: import("./lens-core-module").LensCoreEnumValue;
|
|
148
|
+
};
|
|
149
|
+
UserDataAccess: {
|
|
150
|
+
Restricted: import("./lens-core-module").LensCoreEnumValue;
|
|
151
|
+
Unrestricted: import("./lens-core-module").LensCoreEnumValue;
|
|
152
|
+
};
|
|
153
|
+
InterfaceControl: {
|
|
154
|
+
ToggleCameraButton: import("./lens-core-module").LensCoreEnumValue;
|
|
155
|
+
ImagePicker: import("./lens-core-module").LensCoreEnumValue;
|
|
156
|
+
Hint: import("./lens-core-module").LensCoreEnumValue;
|
|
157
|
+
Modal: import("./lens-core-module").LensCoreEnumValue;
|
|
158
|
+
LinkBitmojiCallToAction: import("./lens-core-module").LensCoreEnumValue;
|
|
159
|
+
SnapButton: import("./lens-core-module").LensCoreEnumValue;
|
|
160
|
+
PlayButton: import("./lens-core-module").LensCoreEnumValue;
|
|
161
|
+
All: import("./lens-core-module").LensCoreEnumValue;
|
|
162
|
+
ExitFullScreenButton: import("./lens-core-module").LensCoreEnumValue;
|
|
163
|
+
MemoriesButton: import("./lens-core-module").LensCoreEnumValue;
|
|
164
|
+
LensAttachmentButton: import("./lens-core-module").LensCoreEnumValue;
|
|
165
|
+
ReverseCamera: import("./lens-core-module").LensCoreEnumValue;
|
|
166
|
+
};
|
|
167
|
+
InterfaceAction: {
|
|
168
|
+
EnableHighlight: import("./lens-core-module").LensCoreEnumValue;
|
|
169
|
+
DisableHighlight: import("./lens-core-module").LensCoreEnumValue;
|
|
170
|
+
Trigger: import("./lens-core-module").LensCoreEnumValue;
|
|
171
|
+
Show: import("./lens-core-module").LensCoreEnumValue;
|
|
172
|
+
Hide: import("./lens-core-module").LensCoreEnumValue;
|
|
173
|
+
};
|
|
174
|
+
ExternalMediaOrientation: {
|
|
175
|
+
CW0: import("./lens-core-module").LensCoreEnumValue;
|
|
176
|
+
CW90: import("./lens-core-module").LensCoreEnumValue;
|
|
177
|
+
CW180: import("./lens-core-module").LensCoreEnumValue;
|
|
178
|
+
CW270: import("./lens-core-module").LensCoreEnumValue;
|
|
179
|
+
};
|
|
180
|
+
mainScriptUrlOrBlob: string;
|
|
181
|
+
} & {
|
|
182
|
+
getCoreVersion: () => number;
|
|
183
|
+
getOutputCanvases: () => import("./lens-core-module").GetOutputCanvasesOutput;
|
|
184
|
+
startProfiling: () => void;
|
|
185
|
+
endProfiling: () => void;
|
|
186
|
+
registerUriListener: (scheme: string, route: string, listener: import("./lens-core-module").UriListener) => void;
|
|
187
|
+
provideUriResponse: (requestId: string, response: import("./lens-core-module").UriResponse) => void;
|
|
188
|
+
setRemoteAssetsProvider: (provider: import("./lens-core-module").SetRemoteAssetsProviderInput) => void;
|
|
189
|
+
setRemoteAssetsUploadHandler: (provider: import("./lens-core-module").SetRemoteAssetsUploadHandlerInput) => void;
|
|
190
|
+
provideRemoteAssetsUploadResponse: (assetResponse: import("./lens-core-module").ProvideRemoteAssetsUploadResponseInput) => void;
|
|
191
|
+
registerShowHintCallback: (callback: import("./lens-core-module").ShowHintCallback) => void;
|
|
192
|
+
registerHideHintCallback: (callback: import("./lens-core-module").HideHintCallback) => void;
|
|
193
|
+
registerSavePersistentStoreCallback: (callback: import("./lens-core-module").SavePersistentStoreCallback) => void;
|
|
194
|
+
setInterfaceControlVisibility: (config: import("./lens-core-module").SetInterfaceControlVisibilityInput) => void;
|
|
195
|
+
handleClientInterfaceAction: (config: import("./lens-core-module").HandleClientInterfaceActionInput) => void;
|
|
196
|
+
provideExternalImage: (config: import("./lens-core-module").ProvideExternalImageInput) => void;
|
|
197
|
+
provideExternalVideo: (config: import("./lens-core-module").ProvideExternalVideoInput) => void;
|
|
198
|
+
setScreenDimmingRequestHandler: (callback: import("./lens-core-module").ScreenDimmingRequestHandler) => void;
|
|
199
|
+
setClientInterfaceRequestHandler: (callback: import("./lens-core-module").ClientInterfaceRequestHandler) => void;
|
|
200
|
+
setPreloadedConfiguration: (config: import("./lens-core-module").SetPreloadedConfigurationInput) => void;
|
|
201
|
+
setAllSoundsMuted: (config: import("./lens-core-module").SetAllSoundsMutedInput) => void;
|
|
202
|
+
setSystemFonts: (config: import("./lens-core-module").SetSystemFontsInput) => void;
|
|
203
|
+
registerBeginWebXrHandler: (handler: ((config: import("./lens-core-module").BeginWebXrInput) => void) | null) => void;
|
|
204
|
+
registerEndWebXrHandler: (handler: (() => void) | null) => void;
|
|
205
|
+
} & {
|
|
206
|
+
processFrame: (input: Omit<import("./lens-core-module").ProcessFrameInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
207
|
+
addLens: (input: Omit<import("./lens-core-module").AddLensInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
208
|
+
replaceLenses: (input: Omit<import("./lens-core-module").ReplaceLensesInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
209
|
+
removeLens: (input: Omit<import("./lens-core-module").RemoveLensInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
210
|
+
clearAllLenses: () => Promise<any>;
|
|
211
|
+
teardown: () => Promise<any>;
|
|
212
|
+
useMediaElement: (input: Omit<import("./lens-core-module").UseMediaElementInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
213
|
+
setFPSLimit: (input: Omit<import("./lens-core-module").SetFpsLimitInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
214
|
+
setRenderLoopMode: (input: Omit<import("./lens-core-module").SetRenderLoopInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
215
|
+
playCanvas: (input: Omit<import("./lens-core-module").PlayCanvasInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
216
|
+
pauseCanvas: (input: Omit<import("./lens-core-module").PauseCanvasInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
217
|
+
setRenderSize: (input: Omit<import("./lens-core-module").SetRenderSizeMatchInputResolutionInput, "onFailure" | "onSuccess"> | Omit<import("./lens-core-module").SetRenderSizeExplicitInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
218
|
+
setInputTransform: (input: Omit<import("./lens-core-module").SetInputTransformInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
219
|
+
imageToYuvBuffer: (input: Omit<import("./lens-core-module").ImageToYuvBufferInput, "onFailure" | "onSuccess">) => Promise<ArrayBuffer>;
|
|
220
|
+
yuvBufferToBitmap: (input: Omit<import("./lens-core-module").YuvBufferToBitmapInput, "onFailure" | "onSuccess">) => Promise<ImageBitmap>;
|
|
221
|
+
setOnFrameProcessedCallback: (input: Omit<import("./lens-core-module").SetOnFrameProcessedInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
222
|
+
setDeviceClass: (input: Omit<import("./lens-core-module").SetDeviceClassInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
223
|
+
setAudioParameters: (input: Omit<import("./lens-core-module").SetAudioParametersInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
224
|
+
processAudioSampleBuffer: (input: Omit<import("./lens-core-module").ProcessAudioSampleBufferInput, "onFailure" | "onSuccess">) => Promise<any>;
|
|
225
|
+
} & {
|
|
226
|
+
initialize(input: {
|
|
227
|
+
canvas?: string | HTMLCanvasElement | undefined;
|
|
228
|
+
outputResolution?: import("./lens-core-module").Dimensions | undefined;
|
|
229
|
+
showFpsPanel?: boolean | undefined;
|
|
230
|
+
shouldUseWorker?: boolean | undefined;
|
|
231
|
+
onFrameProcessed?: ((arg: import("./lens-core-module").OnFrameProcessedParam) => void) | undefined;
|
|
232
|
+
xrCapabilities?: import("./lens-core-module").XrCapabilities | undefined;
|
|
233
|
+
exceptionHandler?: ((err: LensCoreError) => void) | undefined;
|
|
234
|
+
}): Promise<void>;
|
|
235
|
+
provideRemoteAssetsResponse(input: {
|
|
236
|
+
assetId: string;
|
|
237
|
+
assetType: import("./lens-core-module").LensCoreEnumValue;
|
|
238
|
+
assetBuffer?: ArrayBuffer | undefined;
|
|
239
|
+
assetChecksum?: string | undefined;
|
|
240
|
+
onFailure?: ((err: LensCoreError) => void) | undefined;
|
|
241
|
+
}): void;
|
|
242
|
+
}, args_3: PageVisibility, args_4: Container<{
|
|
111
243
|
LensRepository: LensRepository;
|
|
112
244
|
} & {
|
|
113
245
|
metricsEventTarget: MetricsEventTarget;
|
|
114
246
|
} & {
|
|
115
|
-
lensCore:
|
|
247
|
+
lensCore: LensCore;
|
|
116
248
|
} & {
|
|
117
249
|
pageVisibility: PageVisibility;
|
|
118
250
|
} & {
|
|
119
|
-
lensCore:
|
|
251
|
+
lensCore: LensCore;
|
|
120
252
|
} & import("./dependency-injection/RootServices").PublicServices & import("./dependency-injection/types").ServicesFromInjectables<[{
|
|
121
253
|
(): MetricsEventTarget;
|
|
122
254
|
token: "metricsEventTarget";
|
|
@@ -148,7 +280,7 @@ export declare const cameraKitFactory: {
|
|
|
148
280
|
token: "LensRepository";
|
|
149
281
|
dependencies: readonly ["requestStateEventTarget", "cameraKitServiceFetchHandler", "defaultFetchHandler", "lensSources", "lensAssetRepository", "configuration"];
|
|
150
282
|
}, {
|
|
151
|
-
(args_0:
|
|
283
|
+
(args_0: LensCore): import("./persistence/IndexedDBPersistence").IndexedDBPersistence<ArrayBuffer>;
|
|
152
284
|
token: "lensPersistenceStore";
|
|
153
285
|
dependencies: readonly ["lensCore"];
|
|
154
286
|
}, {
|
|
@@ -160,7 +292,7 @@ export declare const cameraKitFactory: {
|
|
|
160
292
|
token: "operationalMetricsReporter";
|
|
161
293
|
dependencies: readonly ["metricsHandler", "pageVisibility", "configuration"];
|
|
162
294
|
}, {
|
|
163
|
-
(args_0:
|
|
295
|
+
(args_0: LensCore, args_1: import("./lens").AssetLoader, args_2: import("./lens").AssetLoader, args_3: import("./lens").AssetLoader, args_4: MetricsEventTarget, args_5: import("./handlers/requestStateEmittingHandler").RequestStateEventTarget): import("./lens").LensAssetRepository;
|
|
164
296
|
token: "lensAssetRepository";
|
|
165
297
|
dependencies: readonly ["lensCore", "deviceDependentAssetLoader", "remoteMediaAssetLoader", "staticAssetLoader", "metricsEventTarget", "requestStateEventTarget"];
|
|
166
298
|
}, {
|
package/lib/CameraKit.js
CHANGED
|
@@ -13,7 +13,7 @@ import { lensStateFactory } from "./session/lensState";
|
|
|
13
13
|
import { lensKeyboardFactory } from "./session/LensKeyboard";
|
|
14
14
|
import { registerLensClientInterfaceHandler } from "./lens-client-interface/lensClientInterface";
|
|
15
15
|
import { sessionStateFactory } from "./session/sessionState";
|
|
16
|
-
import { lensExecutionError } from "./namedErrors";
|
|
16
|
+
import { lensExecutionError, lensAbortError } from "./namedErrors";
|
|
17
17
|
import { getLogger, resetLogger } from "./logger/logger";
|
|
18
18
|
import { errorLoggingDecorator } from "./logger/errorLoggingDecorator";
|
|
19
19
|
import { TypedEventTarget } from "./events/TypedEventTarget";
|
|
@@ -87,8 +87,16 @@ export class CameraKit {
|
|
|
87
87
|
createSession({ liveRenderTarget, renderWhileTabHidden, } = {}) {
|
|
88
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
89
|
// Any error happened during lens rendering can be processed by subscribing to sessionErrors
|
|
90
|
-
const exceptionHandler = (error) =>
|
|
91
|
-
|
|
90
|
+
const exceptionHandler = (error) => {
|
|
91
|
+
if (error.name === "LensCoreAbortError") {
|
|
92
|
+
logger.error(lensAbortError("Unrecoverable error occurred during lens execution. " +
|
|
93
|
+
"The CameraKitSession will be destroyed.", error));
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
logger.error(lensExecutionError("Error occurred during lens execution. " +
|
|
97
|
+
"The lens cannot be rendered and will be removed from the CameraKitSession.", error));
|
|
98
|
+
}
|
|
99
|
+
};
|
|
92
100
|
/**
|
|
93
101
|
* If/when we add support for multiple concurrent sessions, we'll need to create a copy of the LensCore WASM
|
|
94
102
|
* module. If we move managing web workers into JS, spawing a new worker thread with its own copy of LensCore
|
|
@@ -98,23 +106,15 @@ export class CameraKit {
|
|
|
98
106
|
* In order to process tab while it is hidden, the current stopgap is to pass in renderWhileTabHidden as true,
|
|
99
107
|
* which will initiate session in non worker mode, and set the RenderLoopMode to `SetTimeout`.
|
|
100
108
|
*/
|
|
101
|
-
yield
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
exceptionHandler,
|
|
106
|
-
onSuccess,
|
|
107
|
-
onFailure,
|
|
108
|
-
});
|
|
109
|
+
yield this.lensCore.initialize({
|
|
110
|
+
canvas: liveRenderTarget,
|
|
111
|
+
shouldUseWorker: !renderWhileTabHidden && this.container.get(configurationToken).shouldUseWorker,
|
|
112
|
+
exceptionHandler,
|
|
109
113
|
});
|
|
110
|
-
yield
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
: this.lensCore.RenderLoopMode.RequestAnimationFrame,
|
|
115
|
-
onSuccess,
|
|
116
|
-
onFailure,
|
|
117
|
-
});
|
|
114
|
+
yield this.lensCore.setRenderLoopMode({
|
|
115
|
+
mode: renderWhileTabHidden
|
|
116
|
+
? this.lensCore.RenderLoopMode.SetTimeout
|
|
117
|
+
: this.lensCore.RenderLoopMode.RequestAnimationFrame,
|
|
118
118
|
});
|
|
119
119
|
// Each session gets its own DI Container – some Services provided by this Container may be shared with the
|
|
120
120
|
// root CameraKit Container, but others may be scoped to the session by passing their token to `copy()`.
|
package/lib/CameraKit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CameraKit.js","sourceRoot":"","sources":["../src/CameraKit.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAkB,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAa,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAE/D,OAAO,EAAoB,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAsB,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAC7F,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BA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EAC9B,OAA2B,EAC3B,QAAwB,EACxB,cAA8B,EAC9B,SAAkC,EACpC,EAAE,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,OAAO,CAAC,CACnF,CAAC","sourcesContent":["import { lensRepositoryFactory, LensRepository } from \"./lens/LensRepository\";\nimport { CONTAINER, Container } from \"./dependency-injection/Container\";\nimport { Injectable } from \"./dependency-injection/Injectable\";\nimport { LensCoreError, LensCoreModule } from \"./lens-core-module/generated-types\";\nimport { CameraKitSession, cameraKitSessionFactory } from \"./session/CameraKitSession\";\nimport { registerLensAssetsProvider } from \"./lens/assets/LensAssetsProvider\";\nimport { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport { configurationToken } from \"./configuration\";\nimport { RootServices } from \"./dependency-injection/RootServices\";\nimport { registerUriHandlers } from \"./extensions/uriHandlersRegister\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport { reportSessionScopedMetrics } from \"./metrics/reporters/reporters\";\nimport { lensStateFactory } from \"./session/lensState\";\nimport { lensKeyboardFactory } from \"./session/LensKeyboard\";\nimport { registerLensClientInterfaceHandler } from \"./lens-client-interface/lensClientInterface\";\nimport { sessionStateFactory } from \"./session/sessionState\";\nimport { lensExecutionError } from \"./namedErrors\";\nimport { getLogger, resetLogger } from \"./logger/logger\";\nimport { errorLoggingDecorator } from \"./logger/errorLoggingDecorator\";\nimport { TypedEventTarget } from \"./events/TypedEventTarget\";\nimport { TypedCustomEvent } from \"./events/TypedCustomEvent\";\nimport { LensView } from \"./metrics/reporters/reportLensView\";\nimport { LensWait } from \"./metrics/reporters/reportLensWait\";\nimport { PageVisibility, pageVisibilityFactory } from \"./common/pageVisibility\";\nimport { setPreloadedConfiguration } from \"./remote-configuration/preloadConfiguration\";\n\nconst logger = getLogger(\"CameraKit\");\nconst log = errorLoggingDecorator(logger);\n\n/**\n * Metrics event names that are exposed to apps.\n */\nconst publicMetricsEventNames: Array<LensMetricsEvents[\"detail\"][\"name\"]> = [\"lensView\", \"lensWait\"];\n\n/**\n * Lens metrics events.\n *\n * These events are emitted by {@link CameraKit} to report lens usage, performance, apply latency, etc.\n *\n * @category Lenses\n * @category Metrics\n */\nexport type LensMetricsEvents =\n | TypedCustomEvent<LensView[\"name\"], LensView>\n | TypedCustomEvent<LensWait[\"name\"], LensWait>;\n\n/**\n * Options available when creating a {@link CameraKitSession}.\n *\n * @category Rendering\n */\nexport interface CreateSessionOptions {\n /**\n * Optionally provide an existing canvas element, on which the Live RenderTarget will be rendered.\n *\n * If this is not provided, CameraKit will create a new canvas element which can be added to the DOM.\n */\n liveRenderTarget?: HTMLCanvasElement;\n\n /**\n * Browsers optimize tabs when they are hidden - for example, by pausing the execution of requestAnimationFrame\n * callbacks.\n *\n * If you need the CameraKitSession to continue rendering even when the tab is in the background, set this to true.\n * There is a small performance penalty, and it's a good practice to only render in the background if absolutely\n * necessary.\n */\n renderWhileTabHidden?: boolean;\n}\n\n/**\n * The entry point to the CameraKit SDK's API. Most of CameraKit's features are accessed via this class.\n *\n * Applications obtain an instance of CameraKit by calling {@link bootstrapCameraKit}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * ```\n *\n * Then this class can be used to:\n * - Create a {@link CameraKitSession} instance, which provides the API for setting up media inputs, applying Lenses,\n * and obtaining rendered `<canvas>` outputs.\n * - Query for lenses using {@link LensRepository}.\n * - Listen for lens usage metrics events using {@link MetricsEventTarget}.\n *\n * @category Rendering\n * @category Lenses\n */\nexport class CameraKit {\n /** @deprecated Use {@link lensRepository} */\n readonly lenses: { repository: LensRepository };\n\n /**\n * Business metrics (e.g. each time a lens is viewed) are emitted here.\n */\n readonly metrics: TypedEventTarget<LensMetricsEvents> = new TypedEventTarget();\n\n private sessions: CameraKitSession[] = [];\n\n /** @internal */\n constructor(\n /**\n * Used to query for lenses and lens groups.\n */\n readonly lensRepository: LensRepository,\n\n private readonly lensCore: LensCoreModule,\n private readonly pageVisibility: PageVisibility,\n private readonly container: Container<RootServices>,\n allMetrics: MetricsEventTarget\n ) {\n this.lenses = { repository: this.lensRepository };\n // Proxy only a subset of all metrics events to the public-facing emitter -- applications don't need to\n // know about most events.\n publicMetricsEventNames.forEach((eventName) => {\n allMetrics.addEventListener(eventName, (e) => this.metrics.dispatchEvent(e));\n });\n }\n\n /**\n * Create a CameraKitSession.\n *\n * This initializes the rendering engine and returns a {@link CameraKitSession} instance, which provides access\n * to Lens rendering.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * const session = await cameraKit.createSession()\n *\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * session.applyLens(lens)\n * ```\n *\n * @param options\n */\n @log\n async createSession({\n liveRenderTarget,\n renderWhileTabHidden,\n }: CreateSessionOptions = {}): Promise<CameraKitSession> {\n // Any error happened during lens rendering can be processed by subscribing to sessionErrors\n const exceptionHandler = (error: LensCoreError) =>\n logger.error(\n lensExecutionError(\n \"Error occurred during lens execution. \" +\n \"The lens cannot be rendered and will be removed from the CameraKitSession.\",\n error\n )\n );\n\n /**\n * If/when we add support for multiple concurrent sessions, we'll need to create a copy of the LensCore WASM\n * module. If we move managing web workers into JS, spawing a new worker thread with its own copy of LensCore\n * probably becomes a lot more straightforward.\n *\n * Currently chromium has a bug preventing rendering while tab is hidden when LensCore is in worker mode.\n * In order to process tab while it is hidden, the current stopgap is to pass in renderWhileTabHidden as true,\n * which will initiate session in non worker mode, and set the RenderLoopMode to `SetTimeout`.\n */\n await new Promise<void>((onSuccess, onFailure) => {\n this.lensCore.initialize({\n canvas: liveRenderTarget,\n shouldUseWorker: !renderWhileTabHidden && this.container.get(configurationToken).shouldUseWorker,\n exceptionHandler,\n onSuccess,\n onFailure,\n });\n });\n\n await new Promise<void>((onSuccess, onFailure) => {\n this.lensCore.setRenderLoopMode({\n mode: renderWhileTabHidden\n ? this.lensCore.RenderLoopMode.SetTimeout\n : this.lensCore.RenderLoopMode.RequestAnimationFrame,\n onSuccess,\n onFailure,\n });\n });\n\n // Each session gets its own DI Container – some Services provided by this Container may be shared with the\n // root CameraKit Container, but others may be scoped to the session by passing their token to `copy()`.\n const sessionContainer = this.container\n // Right now this is a no-op. If/when we add support for multiple concurrent sessions, we may end up\n // scoping LensCore to the session.\n .copy()\n\n .provides(sessionStateFactory)\n .provides(lensStateFactory)\n .provides(lensKeyboardFactory)\n .provides(cameraKitSessionFactory)\n\n .run(registerLensAssetsProvider)\n .run(registerLensClientInterfaceHandler)\n .run(setPreloadedConfiguration)\n\n // We'll run a PartialContainer containing reporters for session-scoped metrics. Running this container\n // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain\n // actions occur).\n .run(reportSessionScopedMetrics)\n\n // UriHandlers may have dependencies on session-scoped services (e.g. LensState, LensKeyboard), so they'll\n // be registered with LensCore here.\n .run(registerUriHandlers);\n\n const session = sessionContainer.get(cameraKitSessionFactory.token);\n this.sessions.push(session);\n return session;\n }\n\n /**\n * Destroys all sessions and frees all resources.\n */\n @log\n async destroy() {\n resetLogger();\n this.pageVisibility.destroy();\n await Promise.all(this.sessions.map((session) => session.destroy()));\n this.sessions = [];\n }\n}\n\n/** @internal */\nexport const cameraKitFactory = Injectable(\n \"CameraKit\",\n [\n lensRepositoryFactory.token,\n metricsEventTargetFactory.token,\n lensCoreFactory.token,\n pageVisibilityFactory.token,\n CONTAINER,\n ] as const,\n (\n lensRepository: LensRepository,\n metrics: MetricsEventTarget,\n lensCore: LensCoreModule,\n pageVisibility: PageVisibility,\n container: Container<RootServices>\n ) => new CameraKit(lensRepository, lensCore, pageVisibility, container, metrics)\n);\n"]}
|
|
1
|
+
{"version":3,"file":"CameraKit.js","sourceRoot":"","sources":["../src/CameraKit.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAkB,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAa,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAA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OAAO,EAAE,CAAC,CAAC,CAAC;YACrE,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACvB,CAAC;KAAA;CACJ;AAtFS;IADL,GAAG;;;;8CA2EH;AAMK;IADL,GAAG;;;;wCAMH;AAGL,gBAAgB;AAChB,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CACtC,WAAW,EACX;IACI,qBAAqB,CAAC,KAAK;IAC3B,yBAAyB,CAAC,KAAK;IAC/B,eAAe,CAAC,KAAK;IACrB,qBAAqB,CAAC,KAAK;IAC3B,SAAS;CACH,EACV,CACI,cAA8B,EAC9B,OAA2B,EAC3B,QAAkB,EAClB,cAA8B,EAC9B,SAAkC,EACpC,EAAE,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,OAAO,CAAC,CACnF,CAAC","sourcesContent":["import { lensRepositoryFactory, LensRepository } from \"./lens/LensRepository\";\nimport { CONTAINER, Container } from \"./dependency-injection/Container\";\nimport { Injectable } from \"./dependency-injection/Injectable\";\nimport { LensCoreError } from \"./lens-core-module/lensCoreError\";\nimport { LensCore } from \"./lens-core-module/lensCore\";\nimport { CameraKitSession, cameraKitSessionFactory } from \"./session/CameraKitSession\";\nimport { registerLensAssetsProvider } from \"./lens/assets/LensAssetsProvider\";\nimport { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport { configurationToken } from \"./configuration\";\nimport { RootServices } from \"./dependency-injection/RootServices\";\nimport { registerUriHandlers } from \"./extensions/uriHandlersRegister\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport { reportSessionScopedMetrics } from \"./metrics/reporters/reporters\";\nimport { lensStateFactory } from \"./session/lensState\";\nimport { lensKeyboardFactory } from \"./session/LensKeyboard\";\nimport { registerLensClientInterfaceHandler } from \"./lens-client-interface/lensClientInterface\";\nimport { sessionStateFactory } from \"./session/sessionState\";\nimport { lensExecutionError, lensAbortError } from \"./namedErrors\";\nimport { getLogger, resetLogger } from \"./logger/logger\";\nimport { errorLoggingDecorator } from \"./logger/errorLoggingDecorator\";\nimport { TypedEventTarget } from \"./events/TypedEventTarget\";\nimport { TypedCustomEvent } from \"./events/TypedCustomEvent\";\nimport { LensView } from \"./metrics/reporters/reportLensView\";\nimport { LensWait } from \"./metrics/reporters/reportLensWait\";\nimport { PageVisibility, pageVisibilityFactory } from \"./common/pageVisibility\";\nimport { setPreloadedConfiguration } from \"./remote-configuration/preloadConfiguration\";\n\nconst logger = getLogger(\"CameraKit\");\nconst log = errorLoggingDecorator(logger);\n\n/**\n * Metrics event names that are exposed to apps.\n */\nconst publicMetricsEventNames: Array<LensMetricsEvents[\"detail\"][\"name\"]> = [\"lensView\", \"lensWait\"];\n\n/**\n * Lens metrics events.\n *\n * These events are emitted by {@link CameraKit} to report lens usage, performance, apply latency, etc.\n *\n * @category Lenses\n * @category Metrics\n */\nexport type LensMetricsEvents =\n | TypedCustomEvent<LensView[\"name\"], LensView>\n | TypedCustomEvent<LensWait[\"name\"], LensWait>;\n\n/**\n * Options available when creating a {@link CameraKitSession}.\n *\n * @category Rendering\n */\nexport interface CreateSessionOptions {\n /**\n * Optionally provide an existing canvas element, on which the Live RenderTarget will be rendered.\n *\n * If this is not provided, CameraKit will create a new canvas element which can be added to the DOM.\n */\n liveRenderTarget?: HTMLCanvasElement;\n\n /**\n * Browsers optimize tabs when they are hidden - for example, by pausing the execution of requestAnimationFrame\n * callbacks.\n *\n * If you need the CameraKitSession to continue rendering even when the tab is in the background, set this to true.\n * There is a small performance penalty, and it's a good practice to only render in the background if absolutely\n * necessary.\n */\n renderWhileTabHidden?: boolean;\n}\n\n/**\n * The entry point to the CameraKit SDK's API. Most of CameraKit's features are accessed via this class.\n *\n * Applications obtain an instance of CameraKit by calling {@link bootstrapCameraKit}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * ```\n *\n * Then this class can be used to:\n * - Create a {@link CameraKitSession} instance, which provides the API for setting up media inputs, applying Lenses,\n * and obtaining rendered `<canvas>` outputs.\n * - Query for lenses using {@link LensRepository}.\n * - Listen for lens usage metrics events using {@link MetricsEventTarget}.\n *\n * @category Rendering\n * @category Lenses\n */\nexport class CameraKit {\n /** @deprecated Use {@link lensRepository} */\n readonly lenses: { repository: LensRepository };\n\n /**\n * Business metrics (e.g. each time a lens is viewed) are emitted here.\n */\n readonly metrics: TypedEventTarget<LensMetricsEvents> = new TypedEventTarget();\n\n private sessions: CameraKitSession[] = [];\n\n /** @internal */\n constructor(\n /**\n * Used to query for lenses and lens groups.\n */\n readonly lensRepository: LensRepository,\n\n private readonly lensCore: LensCore,\n private readonly pageVisibility: PageVisibility,\n private readonly container: Container<RootServices>,\n allMetrics: MetricsEventTarget\n ) {\n this.lenses = { repository: this.lensRepository };\n // Proxy only a subset of all metrics events to the public-facing emitter -- applications don't need to\n // know about most events.\n publicMetricsEventNames.forEach((eventName) => {\n allMetrics.addEventListener(eventName, (e) => this.metrics.dispatchEvent(e));\n });\n }\n\n /**\n * Create a CameraKitSession.\n *\n * This initializes the rendering engine and returns a {@link CameraKitSession} instance, which provides access\n * to Lens rendering.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * const session = await cameraKit.createSession()\n *\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * session.applyLens(lens)\n * ```\n *\n * @param options\n */\n @log\n async createSession({\n liveRenderTarget,\n renderWhileTabHidden,\n }: CreateSessionOptions = {}): Promise<CameraKitSession> {\n // Any error happened during lens rendering can be processed by subscribing to sessionErrors\n const exceptionHandler = (error: LensCoreError) => {\n if (error.name === \"LensCoreAbortError\") {\n logger.error(\n lensAbortError(\n \"Unrecoverable error occurred during lens execution. \" +\n \"The CameraKitSession will be destroyed.\",\n error\n )\n );\n } else {\n logger.error(\n lensExecutionError(\n \"Error occurred during lens execution. \" +\n \"The lens cannot be rendered and will be removed from the CameraKitSession.\",\n error\n )\n );\n }\n };\n\n /**\n * If/when we add support for multiple concurrent sessions, we'll need to create a copy of the LensCore WASM\n * module. If we move managing web workers into JS, spawing a new worker thread with its own copy of LensCore\n * probably becomes a lot more straightforward.\n *\n * Currently chromium has a bug preventing rendering while tab is hidden when LensCore is in worker mode.\n * In order to process tab while it is hidden, the current stopgap is to pass in renderWhileTabHidden as true,\n * which will initiate session in non worker mode, and set the RenderLoopMode to `SetTimeout`.\n */\n await this.lensCore.initialize({\n canvas: liveRenderTarget,\n shouldUseWorker: !renderWhileTabHidden && this.container.get(configurationToken).shouldUseWorker,\n exceptionHandler,\n });\n\n await this.lensCore.setRenderLoopMode({\n mode: renderWhileTabHidden\n ? this.lensCore.RenderLoopMode.SetTimeout\n : this.lensCore.RenderLoopMode.RequestAnimationFrame,\n });\n\n // Each session gets its own DI Container – some Services provided by this Container may be shared with the\n // root CameraKit Container, but others may be scoped to the session by passing their token to `copy()`.\n const sessionContainer = this.container\n // Right now this is a no-op. If/when we add support for multiple concurrent sessions, we may end up\n // scoping LensCore to the session.\n .copy()\n\n .provides(sessionStateFactory)\n .provides(lensStateFactory)\n .provides(lensKeyboardFactory)\n .provides(cameraKitSessionFactory)\n\n .run(registerLensAssetsProvider)\n .run(registerLensClientInterfaceHandler)\n .run(setPreloadedConfiguration)\n\n // We'll run a PartialContainer containing reporters for session-scoped metrics. Running this container\n // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain\n // actions occur).\n .run(reportSessionScopedMetrics)\n\n // UriHandlers may have dependencies on session-scoped services (e.g. LensState, LensKeyboard), so they'll\n // be registered with LensCore here.\n .run(registerUriHandlers);\n\n const session = sessionContainer.get(cameraKitSessionFactory.token);\n this.sessions.push(session);\n return session;\n }\n\n /**\n * Destroys all sessions and frees all resources.\n */\n @log\n async destroy() {\n resetLogger();\n this.pageVisibility.destroy();\n await Promise.all(this.sessions.map((session) => session.destroy()));\n this.sessions = [];\n }\n}\n\n/** @internal */\nexport const cameraKitFactory = Injectable(\n \"CameraKit\",\n [\n lensRepositoryFactory.token,\n metricsEventTargetFactory.token,\n lensCoreFactory.token,\n pageVisibilityFactory.token,\n CONTAINER,\n ] as const,\n (\n lensRepository: LensRepository,\n metrics: MetricsEventTarget,\n lensCore: LensCore,\n pageVisibility: PageVisibility,\n container: Container<RootServices>\n ) => new CameraKit(lensRepository, lensCore, pageVisibility, container, metrics)\n);\n"]}
|
package/lib/__tests__/data.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
|
-
import { ContentProto
|
|
2
|
+
import { ContentProto } from "../lens";
|
|
3
3
|
import { LensCoreModule, AssetType as LensCoreAssetType } from "../lens-core-module/generated-types";
|
|
4
|
+
import { LensProtoWithGroupId } from "../lens/Lens";
|
|
4
5
|
export declare const falsyValues: readonly [false, null, undefined, 0, ""];
|
|
5
6
|
export declare const truthyValues: readonly [true, 1, {}, Date, readonly []];
|
|
6
|
-
export declare function createLensFixture(name
|
|
7
|
-
|
|
7
|
+
export declare function createLensFixture({ name, groupId, content, }: {
|
|
8
|
+
name: string;
|
|
9
|
+
groupId?: string;
|
|
10
|
+
content?: Partial<ContentProto>;
|
|
11
|
+
}): LensProtoWithGroupId;
|
|
12
|
+
export type LensCoreMock = Pick<jest.Mocked<LensCoreModule>, "AssetType" | "CanvasType" | "ExternalMediaOrientation" | "InterfaceAction" | "InterfaceControl" | "RenderLoopMode" | "getOutputCanvases" | "initialize" | "provideExternalImage" | "provideExternalVideo" | "provideRemoteAssetsResponse" | "provideRemoteAssetsUploadResponse" | "provideUriResponse" | "registerSavePersistentStoreCallback" | "registerUriListener" | "setAllSoundsMuted" | "setClientInterfaceRequestHandler" | "setFPSLimit" | "setInputTransform" | "setOnFrameProcessedCallback" | "setPreloadedConfiguration" | "setRemoteAssetsProvider" | "setRemoteAssetsUploadHandler" | "setRenderLoopMode" | "setRenderSize" | "useMediaElement">;
|
|
8
13
|
export declare const AssetType: Record<keyof LensCoreModule["AssetType"], LensCoreAssetType>;
|
|
9
|
-
export declare function
|
|
14
|
+
export declare function createLensCoreModule(): LensCoreMock;
|
package/lib/__tests__/data.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import { Lens_CameraFacing } from "../lens";
|
|
3
3
|
export const falsyValues = [false, null, undefined, 0, ""];
|
|
4
4
|
export const truthyValues = [true, 1, {}, new Date(), []];
|
|
5
|
-
export function createLensFixture(name, content) {
|
|
5
|
+
export function createLensFixture({ name, groupId = "test-group-id", content = {}, }) {
|
|
6
6
|
return {
|
|
7
7
|
id: name,
|
|
8
|
+
groupId,
|
|
8
9
|
name,
|
|
9
10
|
vendorData: {},
|
|
10
11
|
content: Object.assign({ iconUrlBolt: "https://bolt.com/iconUrl1", lnsSha256: "", lnsUrlBolt: "", preview: {
|
|
@@ -32,7 +33,7 @@ export const AssetType = {
|
|
|
32
33
|
URL: { value: 2 },
|
|
33
34
|
BitmojiDynamicAsset: { value: 4 },
|
|
34
35
|
};
|
|
35
|
-
export function
|
|
36
|
+
export function createLensCoreModule() {
|
|
36
37
|
return {
|
|
37
38
|
AssetType,
|
|
38
39
|
CanvasType: { Preview: { value: 1 }, Capture: { value: 2 }, None: { value: 0 }, All: { value: 3 } },
|
|
@@ -43,17 +44,26 @@ export function createLensCore() {
|
|
|
43
44
|
InterfaceControl: { ImagePicker: { value: 1 } },
|
|
44
45
|
// https://github.sc-corp.net/Snapchat/LensCore/blob/2d538ecc41f67dd2c199e0ff0eefd96aac6f22dc/Src/Common/IExternalMediaFilePickedObserver.h#L21
|
|
45
46
|
ExternalMediaOrientation: { CW0: { value: 0 }, CW90: { value: 1 }, CW180: { value: 2 }, CW270: { value: 3 } },
|
|
46
|
-
initialize: jest.fn(),
|
|
47
|
-
setRemoteAssetsProvider: jest.fn(),
|
|
48
|
-
provideRemoteAssetsResponse: jest.fn(),
|
|
49
47
|
getOutputCanvases: jest.fn(),
|
|
50
|
-
|
|
51
|
-
setRenderLoopMode: jest.fn(),
|
|
52
|
-
setOnFrameProcessedCallback: jest.fn(),
|
|
53
|
-
setClientInterfaceRequestHandler: jest.fn(),
|
|
48
|
+
initialize: jest.fn(),
|
|
54
49
|
provideExternalImage: jest.fn(),
|
|
55
50
|
provideExternalVideo: jest.fn(),
|
|
51
|
+
provideRemoteAssetsResponse: jest.fn(),
|
|
52
|
+
provideRemoteAssetsUploadResponse: jest.fn(),
|
|
53
|
+
provideUriResponse: jest.fn(),
|
|
56
54
|
registerSavePersistentStoreCallback: jest.fn(),
|
|
55
|
+
registerUriListener: jest.fn(),
|
|
56
|
+
setAllSoundsMuted: jest.fn(),
|
|
57
|
+
setClientInterfaceRequestHandler: jest.fn(),
|
|
58
|
+
setFPSLimit: jest.fn(),
|
|
59
|
+
setOnFrameProcessedCallback: jest.fn(),
|
|
60
|
+
setPreloadedConfiguration: jest.fn(),
|
|
61
|
+
setRemoteAssetsProvider: jest.fn(),
|
|
62
|
+
setRemoteAssetsUploadHandler: jest.fn(),
|
|
63
|
+
setRenderLoopMode: jest.fn(),
|
|
64
|
+
setRenderSize: jest.fn(),
|
|
65
|
+
useMediaElement: jest.fn(),
|
|
66
|
+
setInputTransform: jest.fn(),
|
|
57
67
|
};
|
|
58
68
|
}
|
|
59
69
|
//# sourceMappingURL=data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/__tests__/data.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/__tests__/data.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EAAgB,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAI1D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,CAAU,CAAC;AACpE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,IAAI,E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EAAE,EAAE;QACpC,uBAAuB,EAAE,IAAI,CAAC,EAAE,EAAE;QAClC,4BAA4B,EAAE,IAAI,CAAC,EAAE,EAAE;QACvC,iBAAiB,EAAE,IAAI,CAAC,EAAE,EAAE;QAC5B,aAAa,EAAE,IAAI,CAAC,EAAE,EAAE;QACxB,eAAe,EAAE,IAAI,CAAC,EAAE,EAAE;QAC1B,iBAAiB,EAAE,IAAI,CAAC,EAAE,EAAE;KAC/B,CAAC;AACN,CAAC","sourcesContent":["/* eslint-disable max-len */\nimport { ContentProto, Lens_CameraFacing } from \"../lens\";\nimport { LensCoreModule, AssetType as LensCoreAssetType } from \"../lens-core-module/generated-types\";\nimport { LensProtoWithGroupId } from \"../lens/Lens\";\n\nexport const falsyValues = [false, null, undefined, 0, \"\"] as const;\nexport const truthyValues = [true, 1, {}, new Date(), []] as const;\n\nexport function createLensFixture({\n name,\n groupId = \"test-group-id\",\n content = {},\n}: {\n name: string;\n groupId?: string;\n content?: Partial<ContentProto>;\n}): LensProtoWithGroupId {\n return {\n id: name,\n groupId,\n name,\n vendorData: {},\n content: {\n iconUrlBolt: \"https://bolt.com/iconUrl1\",\n lnsSha256: \"\",\n lnsUrlBolt: \"\",\n preview: {\n imageUrl: \"https://bolt.com/previewUrl1\",\n imageSequenceSize: 100,\n imageSequenceWebpUrlPattern: \"http://images.com/face-%d.com\",\n },\n assetManifest: [],\n defaultHintId: \"\",\n hintTranslations: {},\n ...content,\n },\n scannable: {\n snapcodeImageUrl: \"https://snapcodeImageUrl.com\",\n snapcodeDeeplink: \"https://snapcodeDeeplink.com\",\n },\n isThirdParty: false,\n cameraFacingPreference: Lens_CameraFacing.UNRECOGNIZED,\n featureMetadata: [],\n lensCreator: {\n displayName: \"\",\n },\n };\n}\n\nexport type LensCoreMock = Pick<\n jest.Mocked<LensCoreModule>,\n | \"AssetType\"\n | \"CanvasType\"\n | \"ExternalMediaOrientation\"\n | \"InterfaceAction\"\n | \"InterfaceControl\"\n | \"RenderLoopMode\"\n | \"getOutputCanvases\"\n | \"initialize\"\n | \"provideExternalImage\"\n | \"provideExternalVideo\"\n | \"provideRemoteAssetsResponse\"\n | \"provideRemoteAssetsUploadResponse\"\n | \"provideUriResponse\"\n | \"registerSavePersistentStoreCallback\"\n | \"registerUriListener\"\n | \"setAllSoundsMuted\"\n | \"setClientInterfaceRequestHandler\"\n | \"setFPSLimit\"\n | \"setInputTransform\"\n | \"setOnFrameProcessedCallback\"\n | \"setPreloadedConfiguration\"\n | \"setRemoteAssetsProvider\"\n | \"setRemoteAssetsUploadHandler\"\n | \"setRenderLoopMode\"\n | \"setRenderSize\"\n | \"useMediaElement\"\n>;\n\n// NOTE: type of the record ensures newly added asset types break compilation\nexport const AssetType: Record<keyof LensCoreModule[\"AssetType\"], LensCoreAssetType> = {\n DeviceDependent: { value: 3 },\n RemoteMediaByUrl: { value: 6 },\n Static: { value: 1 },\n URL: { value: 2 },\n BitmojiDynamicAsset: { value: 4 },\n};\n\nexport function createLensCoreModule(): LensCoreMock {\n return {\n AssetType,\n CanvasType: { Preview: { value: 1 }, Capture: { value: 2 }, None: { value: 0 }, All: { value: 3 } },\n RenderLoopMode: { SetTimeout: { value: 1 }, RequestAnimationFrame: { value: 0 } },\n // https://github.sc-corp.net/Snapchat/LensCore/blob/502b54b9a663203bcdf3b90c63214cdf8cc1e713/Src/CoreManager/ClientInterfaceDelegate.hpp#L39\n InterfaceAction: { Show: { value: 3 } } as any,\n // https://github.sc-corp.net/Snapchat/LensCore/blob/502b54b9a663203bcdf3b90c63214cdf8cc1e713/Src/CoreManager/ClientInterfaceDelegate.hpp#L21\n InterfaceControl: { ImagePicker: { value: 1 } } as any,\n // https://github.sc-corp.net/Snapchat/LensCore/blob/2d538ecc41f67dd2c199e0ff0eefd96aac6f22dc/Src/Common/IExternalMediaFilePickedObserver.h#L21\n ExternalMediaOrientation: { CW0: { value: 0 }, CW90: { value: 1 }, CW180: { value: 2 }, CW270: { value: 3 } },\n getOutputCanvases: jest.fn(),\n initialize: jest.fn(),\n provideExternalImage: jest.fn(),\n provideExternalVideo: jest.fn(),\n provideRemoteAssetsResponse: jest.fn(),\n provideRemoteAssetsUploadResponse: jest.fn(),\n provideUriResponse: jest.fn(),\n registerSavePersistentStoreCallback: jest.fn(),\n registerUriListener: jest.fn(),\n setAllSoundsMuted: jest.fn(),\n setClientInterfaceRequestHandler: jest.fn(),\n setFPSLimit: jest.fn(),\n setOnFrameProcessedCallback: jest.fn(),\n setPreloadedConfiguration: jest.fn(),\n setRemoteAssetsProvider: jest.fn(),\n setRemoteAssetsUploadHandler: jest.fn(),\n setRenderLoopMode: jest.fn(),\n setRenderSize: jest.fn(),\n useMediaElement: jest.fn(),\n setInputTransform: jest.fn(),\n };\n}\n"]}
|
|
@@ -21,7 +21,7 @@ import { metricsEventTargetFactory } from "./metrics/metricsEventTarget";
|
|
|
21
21
|
import { reportGloballyScopedMetrics } from "./metrics/reporters/reporters";
|
|
22
22
|
import { getLogger } from "./logger/logger";
|
|
23
23
|
import { logEntriesFactory } from "./logger/logEntries";
|
|
24
|
-
import { assertPlatformSupported } from "./assertPlatformSupported";
|
|
24
|
+
import { assertPlatformSupported } from "./platform/assertPlatformSupported";
|
|
25
25
|
import { lensPersistenceStoreFactory } from "./lens/LensPersistenceStore";
|
|
26
26
|
import { remoteConfigurationFactory } from "./remote-configuration/remoteConfiguration";
|
|
27
27
|
import { lensAssetRepositoryFactory } from "./lens/assets/LensAssetRepository";
|
|
@@ -137,7 +137,7 @@ export function bootstrapCameraKit(configuration, provide) {
|
|
|
137
137
|
// it just runs them once).
|
|
138
138
|
telemetryContainer.get(reportGlobalException.token);
|
|
139
139
|
// At this point, logger is configured to report to console and Blizzard.
|
|
140
|
-
assertPlatformSupported();
|
|
140
|
+
yield assertPlatformSupported();
|
|
141
141
|
// LensCore is a foundational component which must be created asynchronously.
|
|
142
142
|
// But it's annoying for every consumer of LensCore to have to wait on Promise<LensCore>
|
|
143
143
|
// (which means they become async themselves). So we'll create a DI container which provides Promise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YACZ,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE;gBACxB,KAAK,GAAG,cAAc,CAAC,iDAAiD,EAAE,KAAK,CAAC,CAAC;aACpF;YACD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,KAAK,CAAC;SACf;IACL,CAAC;CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,eAAe;IAC3B,OAAO,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { lensRepositoryFactory } from \"./lens/LensRepository\";\nimport { Container } from \"./dependency-injection/Container\";\nimport { CameraKit, cameraKitFactory } from \"./CameraKit\";\nimport { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport { Injectable } from \"./dependency-injection/Injectable\";\nimport { remoteMediaAssetLoaderFactory } from \"./lens/assets/remoteMediaAssetLoaderFactory\";\nimport { deviceDependentAssetLoaderFactory } from \"./lens/assets/deviceDependentAssetLoader\";\nimport { staticAssetLoaderFactory } from \"./lens/assets/staticAssetLoader\";\nimport { defaultFetchHandlerFactory } from \"./handlers/defaultFetchHandler\";\nimport { cameraKitServiceFetchHandlerFactory } from \"./handlers/cameraKitServiceFetchHandlerFactory\";\nimport { CameraKitBootstrapConfiguration, createCameraKitConfigurationFactory } from \"./configuration\";\nimport { PublicServices } from \"./dependency-injection/RootServices\";\nimport { PartialContainer } from \"./dependency-injection/PartialContainer\";\nimport { metricsHandlerFactory } from \"./metrics/metricsHandler\";\nimport { operationalMetricReporterFactory } from \"./metrics/operational/operationalMetricsReporter\";\nimport { lensSourcesFactory } from \"./extensions/LensSources\";\nimport { uriHandlersFactory } from \"./extensions/UriHandlers\";\nimport { assert } from \"./common/assertions\";\nimport { isSafeString } from \"./common/typeguards\";\nimport { metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport { reportGloballyScopedMetrics } from \"./metrics/reporters/reporters\";\nimport { getLogger } from \"./logger/logger\";\nimport { logEntriesFactory } from \"./logger/logEntries\";\nimport { assertPlatformSupported } from \"./assertPlatformSupported\";\nimport { lensPersistenceStoreFactory } from \"./lens/LensPersistenceStore\";\nimport { remoteConfigurationFactory } from \"./remote-configuration/remoteConfiguration\";\nimport { lensAssetRepositoryFactory } from \"./lens/assets/LensAssetRepository\";\nimport { legalStateFactory } from \"./legal/legalState\";\nimport { legalPromptFactory } from \"./legal/legalPrompt\";\nimport { bootstrapError, ConfigurationError, configurationError, PlatformNotSupportedError } from \"./namedErrors\";\nimport { businessEventsReporterFactory } from \"./metrics/businessEventsReporter\";\nimport { reportGlobalException } from \"./metrics/reporters/reportGlobalException\";\nimport { registerLogEntriesSubscriber } from \"./logger/registerLogEntriesSubscriber\";\nimport { requestStateEventTargetFactory } from \"./handlers/requestStateEmittingHandler\";\nimport { pageVisibilityFactory } from \"./common/pageVisibility\";\nimport { cofHandlerFactory } from \"./remote-configuration/cofHandler\";\nimport { remoteApiServicesFactory } from \"./extensions/RemoteApiServices\";\n\nconst logger = getLogger(\"bootstrapCameraKit\");\n\n// The following errors are not wrapped with BootstrapError and bubble up as is.\nconst nonWrappableErrors: [ConfigurationError[\"name\"], PlatformNotSupportedError[\"name\"]] = [\n \"ConfigurationError\",\n \"PlatformNotSupportedError\",\n];\n\n/**\n * Returns true if given error has to be wrapped with BoostrapError.\n */\nfunction shouldWrapError(error: unknown): boolean {\n if (error instanceof Error) {\n return !nonWrappableErrors.some((name) => error.name === name);\n }\n return true;\n}\n\n/**\n * For more advanced use-cases, this DI Container holds services for which a custom implementation may be provided by\n * the application.\n *\n * @category Bootstrapping and Configuration\n */\nexport type PublicContainer = Container<PublicServices>;\n\n/**\n * Bootstrap CameraKit. This will download the WebAssembly code which powers CameraKit's rendering engine, and return\n * an instance of {@link CameraKit}.\n *\n * CameraKit must be provided with some configuration (the application's API token), and there are some additional\n * configurations which are optional.\n *\n * Descriptions of the available configurations can be found in the documentation for\n * {@link CameraKitBootstrapConfiguration}\n *\n * ---\n *\n * There is also a second, more advanced way to modify CameraKit to provide greater flexibility to support less common\n * use cases.\n *\n * This requires some knowledge of CameraKit's dependency injection system, and allows applications to provide their\n * own custom implementations of certain CameraKit components. This functionality will only be needed by applications\n * with very specific, more advanced requirements.\n *\n * @example\n * ```ts\n * // The most common way to bootstrap:\n * const cameraKit = await bootstrapCameraKit({ apiToken: myApiToken })\n *\n * // For special advanced use-cases, it is possible to provide custom implementations for certain CameraKit components.\n * const cameraKit = await bootstrapCameraKit(config, (container) => {\n * return container.provides(myCustomRemoteMediaAssetLoaderFactory)\n * })\n * ```\n *\n * @param configuration Configure CameraKit with e.g. credentials, global resource endpoints, etc.\n * @param provide Optional function that can make modifications to CameraKit's root DI container.\n * @returns A {@link CameraKit} instance, which is the entry point to CameraKit's API.\n *\n * @throws\n * - {@link ConfigurationError} when provided configuration object is invalid\n * - {@link PlatformNotSupportedError} when current platform is not supported by CameraKit\n * - {@link BootstrapError} when a failure occurs while initializing CameraKit and downloading the render engine\n * WebAssembly binary.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function bootstrapCameraKit(\n configuration: CameraKitBootstrapConfiguration,\n provide?: (c: PublicContainer) => PublicContainer\n): Promise<CameraKit> {\n try {\n const startTimeMs = performance.now();\n\n assert(isSafeString(configuration.apiToken), configurationError(\"Invalid or unsafe apiToken provided.\"));\n\n const configurationFactory = createCameraKitConfigurationFactory(configuration);\n\n // Public container holds services which applications can overwrite with their own implementations.\n const defaultPublicContainer = Container.provides(configurationFactory)\n .provides(pageVisibilityFactory)\n .provides(defaultFetchHandlerFactory)\n .provides(remoteMediaAssetLoaderFactory)\n .provides(lensSourcesFactory)\n .provides(remoteApiServicesFactory)\n .provides(uriHandlersFactory);\n\n const publicContainer = provide ? provide(defaultPublicContainer) : defaultPublicContainer;\n\n // Now that the client's provide() function has completed and the configuration override is ready,\n // we create another container to initialize the logger. This ensures that logging is available\n // as we continue bootstrapping. We don't initialize the logger as part of the defaultPublicContainer\n // because we don't want applications to provide their own logger implementations,\n // and we're not interested in errors thrown by their provide() function.\n // Below is the minimum required container to report errors to Blizzard.\n const telemetryContainer = Container.provides(publicContainer)\n .provides(logEntriesFactory)\n .run(registerLogEntriesSubscriber)\n .provides(cameraKitServiceFetchHandlerFactory)\n .provides(requestStateEventTargetFactory)\n .provides(metricsEventTargetFactory)\n .provides(metricsHandlerFactory)\n .provides(operationalMetricReporterFactory)\n .provides(reportGlobalException)\n .provides(cofHandlerFactory)\n .provides(remoteConfigurationFactory)\n .provides(legalPromptFactory)\n .provides(legalStateFactory)\n // We'll run a PartialContainer containing reporters for globally-scoped metrics. Running this container\n // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain\n // actions occur). This PartialContainer also includes the service which listens to locally-reported metrics\n // and sends them to our backend.\n .run(reportGloballyScopedMetrics)\n .run(businessEventsReporterFactory);\n\n // Run the exception logger so that it can subscribe to log events -- we can't use `Container.run()` because\n // reportGlobalException is also used as a dependency by other Services (and run does not provide Services,\n // it just runs them once).\n telemetryContainer.get(reportGlobalException.token);\n\n // At this point, logger is configured to report to console and Blizzard.\n\n assertPlatformSupported();\n\n // LensCore is a foundational component which must be created asynchronously.\n // But it's annoying for every consumer of LensCore to have to wait on Promise<LensCore>\n // (which means they become async themselves). So we'll create a DI container which provides Promise<LensCore>,\n // wait for that promise once here, then create a new DI container that just contains LensCore.\n const lensCore = await telemetryContainer.provides(lensCoreFactory).get(lensCoreFactory.token);\n\n const container = telemetryContainer\n .provides(Injectable(lensCoreFactory.token, () => lensCore))\n .provides(lensPersistenceStoreFactory)\n .provides(deviceDependentAssetLoaderFactory)\n .provides(staticAssetLoaderFactory)\n .provides(lensAssetRepositoryFactory)\n .provides(lensRepositoryFactory)\n\n .provides(cameraKitFactory);\n\n const cameraKit = container.get(cameraKitFactory.token);\n\n const bootstrapTimeMs = performance.now() - startTimeMs;\n const reporter = container.get(operationalMetricReporterFactory.token);\n reporter.timer(\"bootstrap_time\", bootstrapTimeMs);\n\n return cameraKit;\n } catch (error) {\n if (shouldWrapError(error)) {\n error = bootstrapError(\"Error occurred during Camera Kit bootstrapping.\", error);\n }\n logger.error(error);\n throw error;\n }\n}\n\n/**\n * Extensions offer a way to provide custom implementations of certain parts of the CameraKit SDK.\n *\n * This enables more advanced use-cases, in which the default behavior of the SDK is substantially altered. For example,\n * replacing the default implementation that loads remote lens assets with a custom implementation that returns\n * different assets based on some business logic within the application.\n *\n * An extension is implemented as a [PartialContainer] – a collection of factory functions, each with its own\n * dependencies, which each provide some \"Service.\" A Service can be of any type, and the CameraKit SDK defines its\n * own Services, some of which can be overridden by providing a custom implementation of the type via an extension.\n *\n * Here's an example of how extensions might be used:\n * ```ts\n * import { bootstrapCameraKit, createExtension, remoteMediaAssetLoaderFactory } from '@snap/camera-kit'\n *\n * const myCustomRemoteAssetLoader = Injectable(\n * remoteMediaAssetLoaderFactory.token,\n * [remoteMediaAssetLoaderFactory.token] as const,\n * (defaultLoader: AssetLoader): AssetLoader => {\n * return async (asset, lens) => {\n * if (lens?.id === MY_SPECIAL_LENS) {\n * return (await fetch('my/asset.glb')).arrayBuffer()\n * }\n * return defaultLoader(asset, lens)\n * }\n * },\n * )\n *\n * const myExtension = createExtension().provides(myCustomeRemoteAssetLoader)\n * const cameraKit = bootstrapCameraKit(config, container => container.provides(myExtension))\n * ```\n *\n * This also enables greater modularity – the person/team creating the extension can do so in their own package, which\n * could be shared by many applications that all require the same functionality.\n *\n * @returns A {@link PartialContainer} which can be used to create a collection of Services, and can later be provided\n * to CameraKit's DI container during {@link bootstrapCameraKit}.\n *\n * @category Bootstrapping and Configuration\n */\nexport function createExtension(): PartialContainer {\n return new PartialContainer({});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bootstrapCameraKit.js","sourceRoot":"","sources":["../src/bootstrapCameraKit.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,eAAe;IAC3B,OAAO,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { lensRepositoryFactory } from \"./lens/LensRepository\";\nimport { Container } from \"./dependency-injection/Container\";\nimport { CameraKit, cameraKitFactory } from \"./CameraKit\";\nimport { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport { Injectable } from \"./dependency-injection/Injectable\";\nimport { remoteMediaAssetLoaderFactory } from \"./lens/assets/remoteMediaAssetLoaderFactory\";\nimport { deviceDependentAssetLoaderFactory } from \"./lens/assets/deviceDependentAssetLoader\";\nimport { staticAssetLoaderFactory } from \"./lens/assets/staticAssetLoader\";\nimport { defaultFetchHandlerFactory } from \"./handlers/defaultFetchHandler\";\nimport { cameraKitServiceFetchHandlerFactory } from \"./handlers/cameraKitServiceFetchHandlerFactory\";\nimport { CameraKitBootstrapConfiguration, createCameraKitConfigurationFactory } from \"./configuration\";\nimport { PublicServices } from \"./dependency-injection/RootServices\";\nimport { PartialContainer } from \"./dependency-injection/PartialContainer\";\nimport { metricsHandlerFactory } from \"./metrics/metricsHandler\";\nimport { operationalMetricReporterFactory } from \"./metrics/operational/operationalMetricsReporter\";\nimport { lensSourcesFactory } from \"./extensions/LensSources\";\nimport { uriHandlersFactory } from \"./extensions/UriHandlers\";\nimport { assert } from \"./common/assertions\";\nimport { isSafeString } from \"./common/typeguards\";\nimport { metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport { reportGloballyScopedMetrics } from \"./metrics/reporters/reporters\";\nimport { getLogger } from \"./logger/logger\";\nimport { logEntriesFactory } from \"./logger/logEntries\";\nimport { assertPlatformSupported } from \"./platform/assertPlatformSupported\";\nimport { lensPersistenceStoreFactory } from \"./lens/LensPersistenceStore\";\nimport { remoteConfigurationFactory } from \"./remote-configuration/remoteConfiguration\";\nimport { lensAssetRepositoryFactory } from \"./lens/assets/LensAssetRepository\";\nimport { legalStateFactory } from \"./legal/legalState\";\nimport { legalPromptFactory } from \"./legal/legalPrompt\";\nimport { bootstrapError, ConfigurationError, configurationError, PlatformNotSupportedError } from \"./namedErrors\";\nimport { businessEventsReporterFactory } from \"./metrics/businessEventsReporter\";\nimport { reportGlobalException } from \"./metrics/reporters/reportGlobalException\";\nimport { registerLogEntriesSubscriber } from \"./logger/registerLogEntriesSubscriber\";\nimport { requestStateEventTargetFactory } from \"./handlers/requestStateEmittingHandler\";\nimport { pageVisibilityFactory } from \"./common/pageVisibility\";\nimport { cofHandlerFactory } from \"./remote-configuration/cofHandler\";\nimport { remoteApiServicesFactory } from \"./extensions/RemoteApiServices\";\n\nconst logger = getLogger(\"bootstrapCameraKit\");\n\n// The following errors are not wrapped with BootstrapError and bubble up as is.\nconst nonWrappableErrors: [ConfigurationError[\"name\"], PlatformNotSupportedError[\"name\"]] = [\n \"ConfigurationError\",\n \"PlatformNotSupportedError\",\n];\n\n/**\n * Returns true if given error has to be wrapped with BoostrapError.\n */\nfunction shouldWrapError(error: unknown): boolean {\n if (error instanceof Error) {\n return !nonWrappableErrors.some((name) => error.name === name);\n }\n return true;\n}\n\n/**\n * For more advanced use-cases, this DI Container holds services for which a custom implementation may be provided by\n * the application.\n *\n * @category Bootstrapping and Configuration\n */\nexport type PublicContainer = Container<PublicServices>;\n\n/**\n * Bootstrap CameraKit. This will download the WebAssembly code which powers CameraKit's rendering engine, and return\n * an instance of {@link CameraKit}.\n *\n * CameraKit must be provided with some configuration (the application's API token), and there are some additional\n * configurations which are optional.\n *\n * Descriptions of the available configurations can be found in the documentation for\n * {@link CameraKitBootstrapConfiguration}\n *\n * ---\n *\n * There is also a second, more advanced way to modify CameraKit to provide greater flexibility to support less common\n * use cases.\n *\n * This requires some knowledge of CameraKit's dependency injection system, and allows applications to provide their\n * own custom implementations of certain CameraKit components. This functionality will only be needed by applications\n * with very specific, more advanced requirements.\n *\n * @example\n * ```ts\n * // The most common way to bootstrap:\n * const cameraKit = await bootstrapCameraKit({ apiToken: myApiToken })\n *\n * // For special advanced use-cases, it is possible to provide custom implementations for certain CameraKit components.\n * const cameraKit = await bootstrapCameraKit(config, (container) => {\n * return container.provides(myCustomRemoteMediaAssetLoaderFactory)\n * })\n * ```\n *\n * @param configuration Configure CameraKit with e.g. credentials, global resource endpoints, etc.\n * @param provide Optional function that can make modifications to CameraKit's root DI container.\n * @returns A {@link CameraKit} instance, which is the entry point to CameraKit's API.\n *\n * @throws\n * - {@link ConfigurationError} when provided configuration object is invalid\n * - {@link PlatformNotSupportedError} when current platform is not supported by CameraKit\n * - {@link BootstrapError} when a failure occurs while initializing CameraKit and downloading the render engine\n * WebAssembly binary.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function bootstrapCameraKit(\n configuration: CameraKitBootstrapConfiguration,\n provide?: (c: PublicContainer) => PublicContainer\n): Promise<CameraKit> {\n try {\n const startTimeMs = performance.now();\n\n assert(isSafeString(configuration.apiToken), configurationError(\"Invalid or unsafe apiToken provided.\"));\n\n const configurationFactory = createCameraKitConfigurationFactory(configuration);\n\n // Public container holds services which applications can overwrite with their own implementations.\n const defaultPublicContainer = Container.provides(configurationFactory)\n .provides(pageVisibilityFactory)\n .provides(defaultFetchHandlerFactory)\n .provides(remoteMediaAssetLoaderFactory)\n .provides(lensSourcesFactory)\n .provides(remoteApiServicesFactory)\n .provides(uriHandlersFactory);\n\n const publicContainer = provide ? provide(defaultPublicContainer) : defaultPublicContainer;\n\n // Now that the client's provide() function has completed and the configuration override is ready,\n // we create another container to initialize the logger. This ensures that logging is available\n // as we continue bootstrapping. We don't initialize the logger as part of the defaultPublicContainer\n // because we don't want applications to provide their own logger implementations,\n // and we're not interested in errors thrown by their provide() function.\n // Below is the minimum required container to report errors to Blizzard.\n const telemetryContainer = Container.provides(publicContainer)\n .provides(logEntriesFactory)\n .run(registerLogEntriesSubscriber)\n .provides(cameraKitServiceFetchHandlerFactory)\n .provides(requestStateEventTargetFactory)\n .provides(metricsEventTargetFactory)\n .provides(metricsHandlerFactory)\n .provides(operationalMetricReporterFactory)\n .provides(reportGlobalException)\n .provides(cofHandlerFactory)\n .provides(remoteConfigurationFactory)\n .provides(legalPromptFactory)\n .provides(legalStateFactory)\n // We'll run a PartialContainer containing reporters for globally-scoped metrics. Running this container\n // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain\n // actions occur). This PartialContainer also includes the service which listens to locally-reported metrics\n // and sends them to our backend.\n .run(reportGloballyScopedMetrics)\n .run(businessEventsReporterFactory);\n\n // Run the exception logger so that it can subscribe to log events -- we can't use `Container.run()` because\n // reportGlobalException is also used as a dependency by other Services (and run does not provide Services,\n // it just runs them once).\n telemetryContainer.get(reportGlobalException.token);\n\n // At this point, logger is configured to report to console and Blizzard.\n\n await assertPlatformSupported();\n\n // LensCore is a foundational component which must be created asynchronously.\n // But it's annoying for every consumer of LensCore to have to wait on Promise<LensCore>\n // (which means they become async themselves). So we'll create a DI container which provides Promise<LensCore>,\n // wait for that promise once here, then create a new DI container that just contains LensCore.\n const lensCore = await telemetryContainer.provides(lensCoreFactory).get(lensCoreFactory.token);\n\n const container = telemetryContainer\n .provides(Injectable(lensCoreFactory.token, () => lensCore))\n .provides(lensPersistenceStoreFactory)\n .provides(deviceDependentAssetLoaderFactory)\n .provides(staticAssetLoaderFactory)\n .provides(lensAssetRepositoryFactory)\n .provides(lensRepositoryFactory)\n\n .provides(cameraKitFactory);\n const cameraKit = container.get(cameraKitFactory.token);\n\n const bootstrapTimeMs = performance.now() - startTimeMs;\n const reporter = container.get(operationalMetricReporterFactory.token);\n reporter.timer(\"bootstrap_time\", bootstrapTimeMs);\n\n return cameraKit;\n } catch (error) {\n if (shouldWrapError(error)) {\n error = bootstrapError(\"Error occurred during Camera Kit bootstrapping.\", error);\n }\n logger.error(error);\n throw error;\n }\n}\n\n/**\n * Extensions offer a way to provide custom implementations of certain parts of the CameraKit SDK.\n *\n * This enables more advanced use-cases, in which the default behavior of the SDK is substantially altered. For example,\n * replacing the default implementation that loads remote lens assets with a custom implementation that returns\n * different assets based on some business logic within the application.\n *\n * An extension is implemented as a [PartialContainer] – a collection of factory functions, each with its own\n * dependencies, which each provide some \"Service.\" A Service can be of any type, and the CameraKit SDK defines its\n * own Services, some of which can be overridden by providing a custom implementation of the type via an extension.\n *\n * Here's an example of how extensions might be used:\n * ```ts\n * import { bootstrapCameraKit, createExtension, remoteMediaAssetLoaderFactory } from '@snap/camera-kit'\n *\n * const myCustomRemoteAssetLoader = Injectable(\n * remoteMediaAssetLoaderFactory.token,\n * [remoteMediaAssetLoaderFactory.token] as const,\n * (defaultLoader: AssetLoader): AssetLoader => {\n * return async (asset, lens) => {\n * if (lens?.id === MY_SPECIAL_LENS) {\n * return (await fetch('my/asset.glb')).arrayBuffer()\n * }\n * return defaultLoader(asset, lens)\n * }\n * },\n * )\n *\n * const myExtension = createExtension().provides(myCustomeRemoteAssetLoader)\n * const cameraKit = bootstrapCameraKit(config, container => container.provides(myExtension))\n * ```\n *\n * This also enables greater modularity – the person/team creating the extension can do so in their own package, which\n * could be shared by many applications that all require the same functionality.\n *\n * @returns A {@link PartialContainer} which can be used to create a collection of Services, and can later be provided\n * to CameraKit's DI container during {@link bootstrapCameraKit}.\n *\n * @category Bootstrapping and Configuration\n */\nexport function createExtension(): PartialContainer {\n return new PartialContainer({});\n}\n"]}
|
|
@@ -1,28 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* This implementation is limited by how TypeScript currently implements tag function for template literals.
|
|
3
|
-
*
|
|
4
|
-
* The way tag functions are typed by the TypeScript compiler limits their usefulness, for two reasons:
|
|
5
|
-
*
|
|
6
|
-
* 1. Specific literal types are not inferred from interpolation expressions -- the following does not work:
|
|
7
|
-
* ```ts
|
|
8
|
-
* function tag<K extends readonly string[]>(strings: readonly string[], ...keys: K): string { ... }
|
|
9
|
-
* tag`This is a ${"test"} template.` // the K type parameter is not correctly inferred as `readonly ['test']`
|
|
10
|
-
* ```
|
|
11
|
-
* 2. The return type of a function used as a tag function will always be `string` -- the following does not work:
|
|
12
|
-
* ```ts
|
|
13
|
-
* function tag<K extends readonly string[]>(
|
|
14
|
-
* strings: readonly string[],
|
|
15
|
-
* ...keys: K
|
|
16
|
-
* ): (values: {[k in K[number]]: string}) => string { ... }
|
|
17
|
-
*
|
|
18
|
-
* const template = tag`This is a ${"test"} template` // TS infers the type of `template` as `string` -- clearly wrong.
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* An attempt is made here to work around those limitations and still provide a reasonably amount of type safety without
|
|
22
|
-
* adding too much verbosity.
|
|
23
|
-
*
|
|
24
|
-
* See https://github.com/microsoft/TypeScript/pull/49552
|
|
25
|
-
*/
|
|
1
|
+
import { getPlatformInfo } from "../platform/platformInfo";
|
|
26
2
|
function makeTemplate(keys) {
|
|
27
3
|
return (template) => (values) => {
|
|
28
4
|
const tag = (readonlyStrings) => {
|
|
@@ -643,20 +619,20 @@ const synonyms = {
|
|
|
643
619
|
"zh-TW": "zh-Hant",
|
|
644
620
|
"zh-CN": "zh-Hans",
|
|
645
621
|
};
|
|
622
|
+
const isLocaleString = (value) => value in allStrings;
|
|
646
623
|
// Default locale in case a user locale cannot be found.
|
|
647
624
|
const defaultLocale = "en-US";
|
|
648
625
|
/**
|
|
649
626
|
* Gets browser locale and maps it to the closest locale that has a translation.
|
|
650
627
|
*/
|
|
651
628
|
function getSupportedLocale() {
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
const synonym = synonyms[lang];
|
|
629
|
+
const locale = getPlatformInfo().locale;
|
|
630
|
+
if (isLocaleString(locale))
|
|
631
|
+
return locale;
|
|
632
|
+
const synonym = synonyms[locale];
|
|
657
633
|
if (synonym && synonym in allStrings)
|
|
658
634
|
return synonym;
|
|
659
|
-
const langCode =
|
|
635
|
+
const langCode = locale.split("-")[0];
|
|
660
636
|
// Safety: "in" operator ensures that langCode is in allStrings, i.e. is of Locale type.
|
|
661
637
|
if (langCode && langCode in allStrings)
|
|
662
638
|
return langCode;
|