@snap/camera-kit 0.13.2 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- 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 +6 -5
- 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/README.md +1 -1
- package/docs/md/classes/CameraKit.md +1 -1
- package/docs/md/classes/CameraKitSession.md +1 -1
- package/docs/md/classes/CameraKitSource.md +1 -1
- package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
- package/docs/md/classes/LensPerformanceMetrics.md +1 -1
- package/docs/md/classes/LensRepository.md +3 -3
- package/docs/md/classes/LensSources.md +1 -1
- package/docs/md/classes/Transform2D.md +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 +122 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lens-core-module/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./loader\";\nexport * from \"./generated-types\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lens-core-module/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC","sourcesContent":["export * from \"./loader\";\nexport * from \"./generated-types\";\nexport * from \"./lensCore\";\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DefaultErrorHandler, DefaultEventHandler, LensCoreModule } from "./generated-types";
|
|
2
|
+
import { LensCoreError } from "./lensCoreError";
|
|
3
|
+
type SafeOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
4
|
+
/**
|
|
5
|
+
* LensCore methods that require additional handling.
|
|
6
|
+
*/
|
|
7
|
+
type LensCoreCustomMethods = {
|
|
8
|
+
initialize(input: PromisifiedParam<MapParamErrorCallback<"initialize", "exceptionHandler">>): Promise<void>;
|
|
9
|
+
provideRemoteAssetsResponse(input: MapParamErrorCallback<"provideRemoteAssetsResponse", "onFailure">): void;
|
|
10
|
+
};
|
|
11
|
+
type LensCoreCustomMethodNames = keyof LensCoreCustomMethods extends keyof LensCoreModule ? keyof LensCoreCustomMethods : never;
|
|
12
|
+
type PropertyKinds = "enum" | "sync method" | "promisifiable method" | "custom method";
|
|
13
|
+
type LensCorePropertyKinds = {
|
|
14
|
+
[K in keyof LensCoreModule]: LensCoreModule[K] extends (...args: any[]) => any ? K extends LensCoreCustomMethodNames ? "custom method" : Parameters<LensCoreModule[K]>[0] extends {
|
|
15
|
+
onSuccess?: DefaultEventHandler;
|
|
16
|
+
onFailuer?: DefaultErrorHandler;
|
|
17
|
+
} ? "promisifiable method" : "sync method" : "enum";
|
|
18
|
+
};
|
|
19
|
+
type PropertiesOfKind<T extends PropertyKinds> = Exclude<{
|
|
20
|
+
[K in keyof LensCorePropertyKinds]: LensCorePropertyKinds[K] extends T ? K : never;
|
|
21
|
+
}[keyof LensCorePropertyKinds], undefined>;
|
|
22
|
+
type FirstParameter<T> = T extends (first: infer P, ...rest: any[]) => any ? P : never;
|
|
23
|
+
type LensCoreEnums = Pick<LensCoreModule, PropertiesOfKind<"enum">>;
|
|
24
|
+
type LensCoreSyncMethods = Pick<LensCoreModule, PropertiesOfKind<"sync method">>;
|
|
25
|
+
type LensCorePromisifiedMethods = {
|
|
26
|
+
[K in PropertiesOfKind<"promisifiable method">]: K extends keyof LensCoreModule ? keyof SafeOmit<Parameters<LensCoreModule[K]>[0], "onSuccess" | "onFailure"> extends never ? () => Promise<FirstParameter<Parameters<LensCoreModule[K]>[0]["onSuccess"]>> : (input: SafeOmit<Parameters<LensCoreModule[K]>[0], "onSuccess" | "onFailure">) => Promise<FirstParameter<Parameters<LensCoreModule[K]>[0]["onSuccess"]>> : never;
|
|
27
|
+
};
|
|
28
|
+
type PromisifiedParam<T extends {
|
|
29
|
+
onSuccess?: DefaultEventHandler;
|
|
30
|
+
onFailure?: DefaultErrorHandler;
|
|
31
|
+
}> = {
|
|
32
|
+
[P in keyof T as P extends "onSuccess" | "onFailure" ? never : P]: T[P];
|
|
33
|
+
};
|
|
34
|
+
type MapParamErrorCallback<T extends PropertiesOfKind<"custom method">, U extends keyof LensCoreMethodFirstParam<T>> = MapErrorCallback<LensCoreMethodFirstParam<T>, U>;
|
|
35
|
+
type LensCoreMethodFirstParam<T extends PropertiesOfKind<"custom method">> = Parameters<LensCoreModule[T]>[0];
|
|
36
|
+
type MapErrorCallback<T, U extends keyof T> = {
|
|
37
|
+
[P in keyof T]: P extends U ? (err: LensCoreError) => void : T[P];
|
|
38
|
+
};
|
|
39
|
+
export type LensCore = LensCoreEnums & LensCoreSyncMethods & LensCorePromisifiedMethods & LensCoreCustomMethods;
|
|
40
|
+
export declare const createLensCore: (lensCoreModule: LensCoreModule) => LensCore;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { wrapLensCoreError } from "./lensCoreError";
|
|
2
|
+
// By using PropertiesOfKind, we can ensure a compile-time error if LensCoreModule adds a new async method,
|
|
3
|
+
// but we forget to update this list.
|
|
4
|
+
const promisifiableMethods = {
|
|
5
|
+
addLens: null,
|
|
6
|
+
clearAllLenses: null,
|
|
7
|
+
imageToYuvBuffer: null,
|
|
8
|
+
pauseCanvas: null,
|
|
9
|
+
playCanvas: null,
|
|
10
|
+
processAudioSampleBuffer: null,
|
|
11
|
+
processFrame: null,
|
|
12
|
+
removeLens: null,
|
|
13
|
+
replaceLenses: null,
|
|
14
|
+
setAudioParameters: null,
|
|
15
|
+
setDeviceClass: null,
|
|
16
|
+
setFPSLimit: null,
|
|
17
|
+
setInputTransform: null,
|
|
18
|
+
setOnFrameProcessedCallback: null,
|
|
19
|
+
setRenderLoopMode: null,
|
|
20
|
+
setRenderSize: null,
|
|
21
|
+
teardown: null,
|
|
22
|
+
useMediaElement: null,
|
|
23
|
+
yuvBufferToBitmap: null,
|
|
24
|
+
};
|
|
25
|
+
export const createLensCore = (lensCoreModule) => {
|
|
26
|
+
const customMethods = {
|
|
27
|
+
initialize(input) {
|
|
28
|
+
return new Promise((onSuccess, onFailure) => lensCoreModule.initialize(Object.assign(Object.assign({}, input), { exceptionHandler: input.exceptionHandler && wrapLensCoreError(input.exceptionHandler), onSuccess, onFailure: wrapLensCoreError(onFailure) })));
|
|
29
|
+
},
|
|
30
|
+
provideRemoteAssetsResponse(input) {
|
|
31
|
+
return lensCoreModule.provideRemoteAssetsResponse(Object.assign(Object.assign({}, input), { onFailure: input.onFailure && wrapLensCoreError(input.onFailure) }));
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
return new Proxy(lensCoreModule, {
|
|
35
|
+
get: (target, property, receiver) => {
|
|
36
|
+
// Handle special methods with custom implementations
|
|
37
|
+
if (property in customMethods) {
|
|
38
|
+
// Safety: "in" operator above ensures that property is keyof LensCoreCustomMethods
|
|
39
|
+
return customMethods[property];
|
|
40
|
+
}
|
|
41
|
+
// All other async methods return Promises
|
|
42
|
+
if (property in promisifiableMethods) {
|
|
43
|
+
const method = Reflect.get(target, property, receiver);
|
|
44
|
+
if (!method)
|
|
45
|
+
method;
|
|
46
|
+
return (input) => new Promise((onSuccess, onFailure) => method(Object.assign(Object.assign({}, input), { onSuccess, onFailure: wrapLensCoreError(onFailure) })));
|
|
47
|
+
}
|
|
48
|
+
// All other kinds of properties (enums, sync methods) are unmodified.
|
|
49
|
+
return Reflect.get(target, property, receiver);
|
|
50
|
+
},
|
|
51
|
+
// Safety: We ensured safety by defining types for both custom and promisifiable methods.
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=lensCore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lensCore.js","sourceRoot":"","sources":["../../src/lens-core-module/lensCore.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAoEnE,2GAA2G;AAC3G,qCAAqC;AACrC,MAAM,oBAAoB,GAA8D;IACpF,OAAO,EAAE,IAAI;IACb,cAAc,EAAE,IAAI;IACpB,gBAAgB,EAAE,IAAI;IACtB,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,IAAI;IAChB,wBAAwB,EAAE,IAAI;IAC9B,YAAY,EAAE,IAAI;IACl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Q,EAAE,QAAQ,CAAC,CAAC;gBACvD,IAAI,CAAC,MAAM;oBAAE,MAAM,CAAC;gBACpB,OAAO,CAAC,KAAkF,EAAE,EAAE,CAC1F,IAAI,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CACjC,MAAM,iCACC,KAAK,KACR,SAAS,EACT,SAAS,EAAE,iBAAiB,CAAC,SAAS,CAAC,IACzC,CACL,CAAC;aACT;YAED,sEAAsE;YACtE,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACnD,CAAC;QACD,yFAAyF;KAC5F,CAAa,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { DefaultErrorHandler, DefaultEventHandler, LensCoreModule } from \"./generated-types\";\nimport { LensCoreError, wrapLensCoreError } from \"./lensCoreError\";\n\n// Note: While this looks similar to Omit, Omit breaks discriminated unions:\n// https://github.com/microsoft/TypeScript/issues/31501\n// This is relevant in the case of setRenderMode().\ntype SafeOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;\n\n/**\n * LensCore methods that require additional handling.\n */\ntype LensCoreCustomMethods = {\n // initialize() param has exceptionHandler, which requires error mapping.\n initialize(input: PromisifiedParam<MapParamErrorCallback<\"initialize\", \"exceptionHandler\">>): Promise<void>;\n\n // provideRemoteAssetsResponse() param has onFailure, which requires error mapping.\n provideRemoteAssetsResponse(input: MapParamErrorCallback<\"provideRemoteAssetsResponse\", \"onFailure\">): void;\n};\n\n// Ensure method names defined in CustomLensCoreMethods are the ones that exist in LensCoreModule.\ntype LensCoreCustomMethodNames = keyof LensCoreCustomMethods extends keyof LensCoreModule\n ? keyof LensCoreCustomMethods\n : never;\n\ntype PropertyKinds = \"enum\" | \"sync method\" | \"promisifiable method\" | \"custom method\";\n\n// Create a mapping between property keys and the kind of property it is (enum, sync method, or async method)\ntype LensCorePropertyKinds = {\n [K in keyof LensCoreModule]: LensCoreModule[K] extends (...args: any[]) => any\n ? K extends LensCoreCustomMethodNames\n ? \"custom method\"\n : Parameters<LensCoreModule[K]>[0] extends {\n onSuccess?: DefaultEventHandler;\n onFailuer?: DefaultErrorHandler;\n }\n ? \"promisifiable method\"\n : \"sync method\"\n : \"enum\";\n};\n\n// Helper to select LensCoreModule properties of a particular kind.\ntype PropertiesOfKind<T extends PropertyKinds> = Exclude<\n {\n [K in keyof LensCorePropertyKinds]: LensCorePropertyKinds[K] extends T ? K : never;\n }[keyof LensCorePropertyKinds],\n undefined\n>;\ntype FirstParameter<T> = T extends (first: infer P, ...rest: any[]) => any ? P : never;\ntype LensCoreEnums = Pick<LensCoreModule, PropertiesOfKind<\"enum\">>;\ntype LensCoreSyncMethods = Pick<LensCoreModule, PropertiesOfKind<\"sync method\">>;\ntype LensCorePromisifiedMethods = {\n [K in PropertiesOfKind<\"promisifiable method\">]: K extends keyof LensCoreModule\n ? keyof SafeOmit<Parameters<LensCoreModule[K]>[0], \"onSuccess\" | \"onFailure\"> extends never\n ? () => Promise<FirstParameter<Parameters<LensCoreModule[K]>[0][\"onSuccess\"]>>\n : (\n input: SafeOmit<Parameters<LensCoreModule[K]>[0], \"onSuccess\" | \"onFailure\">\n ) => Promise<FirstParameter<Parameters<LensCoreModule[K]>[0][\"onSuccess\"]>>\n : never;\n};\ntype PromisifiedParam<T extends { onSuccess?: DefaultEventHandler; onFailure?: DefaultErrorHandler }> = {\n [P in keyof T as P extends \"onSuccess\" | \"onFailure\" ? never : P]: T[P];\n};\ntype MapParamErrorCallback<\n T extends PropertiesOfKind<\"custom method\">,\n U extends keyof LensCoreMethodFirstParam<T>\n> = MapErrorCallback<LensCoreMethodFirstParam<T>, U>;\ntype LensCoreMethodFirstParam<T extends PropertiesOfKind<\"custom method\">> = Parameters<LensCoreModule[T]>[0];\ntype MapErrorCallback<T, U extends keyof T> = { [P in keyof T]: P extends U ? (err: LensCoreError) => void : T[P] };\n\n// By using PropertiesOfKind, we can ensure a compile-time error if LensCoreModule adds a new async method,\n// but we forget to update this list.\nconst promisifiableMethods: { [K in PropertiesOfKind<\"promisifiable method\">]: null } = {\n addLens: null,\n clearAllLenses: null,\n imageToYuvBuffer: null,\n pauseCanvas: null,\n playCanvas: null,\n processAudioSampleBuffer: null,\n processFrame: null,\n removeLens: null,\n replaceLenses: null,\n setAudioParameters: null,\n setDeviceClass: null,\n setFPSLimit: null,\n setInputTransform: null,\n setOnFrameProcessedCallback: null,\n setRenderLoopMode: null,\n setRenderSize: null,\n teardown: null,\n useMediaElement: null,\n yuvBufferToBitmap: null,\n};\n\nexport type LensCore = LensCoreEnums & LensCoreSyncMethods & LensCorePromisifiedMethods & LensCoreCustomMethods;\n\nexport const createLensCore = (lensCoreModule: LensCoreModule): LensCore => {\n const customMethods: LensCoreCustomMethods = {\n initialize(input) {\n return new Promise((onSuccess, onFailure) =>\n lensCoreModule.initialize({\n ...input,\n exceptionHandler: input.exceptionHandler && wrapLensCoreError(input.exceptionHandler),\n onSuccess,\n onFailure: wrapLensCoreError(onFailure),\n })\n );\n },\n\n provideRemoteAssetsResponse(input) {\n return lensCoreModule.provideRemoteAssetsResponse({\n ...input,\n onFailure: input.onFailure && wrapLensCoreError(input.onFailure),\n });\n },\n };\n\n return new Proxy(lensCoreModule, {\n get: (target, property, receiver) => {\n // Handle special methods with custom implementations\n if (property in customMethods) {\n // Safety: \"in\" operator above ensures that property is keyof LensCoreCustomMethods\n return customMethods[property as keyof LensCoreCustomMethods];\n }\n\n // All other async methods return Promises\n if (property in promisifiableMethods) {\n const method = Reflect.get(target, property, receiver);\n if (!method) method;\n return (input: Parameters<LensCorePromisifiedMethods[keyof LensCorePromisifiedMethods]>[0]) =>\n new Promise((onSuccess, onFailure) =>\n method({\n ...input,\n onSuccess,\n onFailure: wrapLensCoreError(onFailure),\n })\n );\n }\n\n // All other kinds of properties (enums, sync methods) are unmodified.\n return Reflect.get(target, property, receiver);\n },\n // Safety: We ensured safety by defining types for both custom and promisifiable methods.\n }) as LensCore;\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DefaultErrorHandler } from "./generated-types";
|
|
2
|
+
type ErrorName = `${string}Error`;
|
|
3
|
+
type NamedError<Name extends ErrorName> = Error & {
|
|
4
|
+
name: Name;
|
|
5
|
+
};
|
|
6
|
+
export type LensCoreLensDeserializationError = NamedError<"LensCoreLensDeserializationError">;
|
|
7
|
+
export type LensCoreValidationError = NamedError<"LensCoreValidationError">;
|
|
8
|
+
export type LensCoreUncategorizedError = NamedError<"LensCoreUncategorizedError">;
|
|
9
|
+
export type LensCoreLensExecutionError = NamedError<"LensCoreLensExecutionError">;
|
|
10
|
+
export type LensCoreAbortError = NamedError<"LensCoreAbortError">;
|
|
11
|
+
export type LensCoreUninitializedError = NamedError<"LensCoreUninitializedError">;
|
|
12
|
+
export type LensCoreUnknownError = NamedError<"LensCoreUnknownError">;
|
|
13
|
+
export type LensCoreError = LensCoreLensDeserializationError | LensCoreValidationError | LensCoreUncategorizedError | LensCoreLensExecutionError | LensCoreAbortError | LensCoreUninitializedError;
|
|
14
|
+
export declare function wrapLensCoreError(fn: (e: LensCoreError) => void): DefaultErrorHandler;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Construct a map linking each LensCore error name to its value,
|
|
2
|
+
// designed to trigger a compile-time error if an error is added or removed in LensCore.
|
|
3
|
+
// eslint-disable-next-line max-len
|
|
4
|
+
// https://github.sc-corp.net/Snapchat/LensCore/blob/master/Src/PlatformSpecific/WebAssembly/ErrorType.hpp#L4
|
|
5
|
+
const lensCoreErrorValue = {
|
|
6
|
+
LensDeserialization: 0,
|
|
7
|
+
Validation: 1,
|
|
8
|
+
Uncategorized: 2,
|
|
9
|
+
LensExecution: 3,
|
|
10
|
+
Abort: 4,
|
|
11
|
+
Uninitialized: 5,
|
|
12
|
+
};
|
|
13
|
+
// The purpose of lensCoreErrorValue above is to safeguard integrity.
|
|
14
|
+
// To achieve constant lookup times, we must swap the keys with their corresponding values.
|
|
15
|
+
const lensCoreErrorName = Object.fromEntries(Object.entries(lensCoreErrorValue).map((entry) => [entry[1], entry[0]]));
|
|
16
|
+
export function wrapLensCoreError(fn) {
|
|
17
|
+
const handler = (cause) => {
|
|
18
|
+
var _a;
|
|
19
|
+
const error = new Error(cause.message.split("\n")[0], {
|
|
20
|
+
cause: cause.otherExceptions || ((_a = cause.cause) === null || _a === void 0 ? void 0 : _a.metadata)
|
|
21
|
+
? {
|
|
22
|
+
otherExceptions: cause.otherExceptions,
|
|
23
|
+
metadata: cause.cause.metadata,
|
|
24
|
+
}
|
|
25
|
+
: undefined,
|
|
26
|
+
});
|
|
27
|
+
const name = `LensCore${cause.cause ? lensCoreErrorName[cause.cause.type.value] : "Unknown"}Error`;
|
|
28
|
+
error.name = name;
|
|
29
|
+
if (cause.stack) {
|
|
30
|
+
// if cause has a stack, then we just replace the first line of it
|
|
31
|
+
// which is actually a error message with our new one, which also contains new error name
|
|
32
|
+
const [_, ...stackLines] = cause.stack.split("\n");
|
|
33
|
+
if (error.stack) {
|
|
34
|
+
stackLines.unshift(error.stack.split("\n")[0]);
|
|
35
|
+
}
|
|
36
|
+
error.stack = stackLines.join("\n");
|
|
37
|
+
}
|
|
38
|
+
// Safety: we set name above and therefore sure the type of error is correct
|
|
39
|
+
fn(error);
|
|
40
|
+
};
|
|
41
|
+
return handler;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=lensCoreError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lensCoreError.js","sourceRoot":"","sources":["../../src/lens-core-module/lensCoreError.ts"],"names":[],"mappings":"AAuBA,iEAAiE;AACjE,wFAAwF;AACxF,mCAAmC;AACnC,6GAA6G;AAC7G,MAAM,kBAAkB,GAAwC;IAC5D,mBAAmB,EAAE,CAAC;IACtB,UAAU,EAAE,CAAC;IACb,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,CAAC;IAChB,KAAK,EAAE,CAAC;IACR,aAAa,EAAE,CAAC;CACnB,CAAC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AClD;YACD,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACvC;QACD,4EAA4E;QAC5E,EAAE,CAAC,KAAsB,CAAC,CAAC;IAC/B,CAAC,CAAC;IACF,OAAO,OAAO,CAAC;AACnB,CAAC","sourcesContent":["import { DefaultErrorHandler, LensCoreModule } from \"./generated-types\";\n\ntype ErrorName = `${string}Error`;\ntype NamedError<Name extends ErrorName> = Error & { name: Name };\n\nexport type LensCoreLensDeserializationError = NamedError<\"LensCoreLensDeserializationError\">;\nexport type LensCoreValidationError = NamedError<\"LensCoreValidationError\">;\nexport type LensCoreUncategorizedError = NamedError<\"LensCoreUncategorizedError\">;\nexport type LensCoreLensExecutionError = NamedError<\"LensCoreLensExecutionError\">;\nexport type LensCoreAbortError = NamedError<\"LensCoreAbortError\">;\nexport type LensCoreUninitializedError = NamedError<\"LensCoreUninitializedError\">;\nexport type LensCoreUnknownError = NamedError<\"LensCoreUnknownError\">;\n\nexport type LensCoreError =\n | LensCoreLensDeserializationError\n | LensCoreValidationError\n | LensCoreUncategorizedError\n | LensCoreLensExecutionError\n | LensCoreAbortError\n | LensCoreUninitializedError;\n\ntype NativeLensCoreError = keyof LensCoreModule[\"ErrorType\"];\n\n// Construct a map linking each LensCore error name to its value,\n// designed to trigger a compile-time error if an error is added or removed in LensCore.\n// eslint-disable-next-line max-len\n// https://github.sc-corp.net/Snapchat/LensCore/blob/master/Src/PlatformSpecific/WebAssembly/ErrorType.hpp#L4\nconst lensCoreErrorValue: Record<NativeLensCoreError, number> = {\n LensDeserialization: 0,\n Validation: 1,\n Uncategorized: 2,\n LensExecution: 3,\n Abort: 4,\n Uninitialized: 5,\n};\n\n// The purpose of lensCoreErrorValue above is to safeguard integrity.\n// To achieve constant lookup times, we must swap the keys with their corresponding values.\nconst lensCoreErrorName = Object.fromEntries(\n Object.entries(lensCoreErrorValue).map((entry) => [entry[1], entry[0] as NativeLensCoreError] as const)\n);\n\nexport function wrapLensCoreError(fn: (e: LensCoreError) => void) {\n const handler: DefaultErrorHandler = (cause) => {\n const error = new Error(cause.message.split(\"\\n\")[0], {\n cause:\n cause.otherExceptions || cause.cause?.metadata\n ? {\n otherExceptions: cause.otherExceptions,\n metadata: cause.cause.metadata,\n }\n : undefined,\n });\n const name: (LensCoreError | LensCoreUnknownError)[\"name\"] = `LensCore${\n cause.cause ? lensCoreErrorName[cause.cause.type.value] : \"Unknown\"\n }Error` as const;\n error.name = name;\n if (cause.stack) {\n // if cause has a stack, then we just replace the first line of it\n // which is actually a error message with our new one, which also contains new error name\n const [_, ...stackLines] = cause.stack.split(\"\\n\");\n if (error.stack) {\n stackLines.unshift(error.stack.split(\"\\n\")[0]);\n }\n error.stack = stackLines.join(\"\\n\");\n }\n // Safety: we set name above and therefore sure the type of error is correct\n fn(error as LensCoreError);\n };\n return handler;\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CameraKitConfiguration } from "../../configuration";
|
|
2
2
|
import { FetchHandler } from "../../handlers/defaultFetchHandler";
|
|
3
|
-
import { InitialEmscriptenModule, LensCoreModule } from "../generated-types";
|
|
4
3
|
/**
|
|
5
4
|
* Returns a list of URLs for resources which will be fetched during {@link bootstrapCameraKit}.
|
|
6
5
|
*
|
|
@@ -24,7 +23,7 @@ export declare function getRequiredBootstrapURLs(endpointOverride?: string): Pro
|
|
|
24
23
|
* @internal
|
|
25
24
|
*/
|
|
26
25
|
export declare const lensCoreFactory: {
|
|
27
|
-
(args_0: FetchHandler, args_1: CameraKitConfiguration): Promise<
|
|
26
|
+
(args_0: FetchHandler, args_1: CameraKitConfiguration): Promise<import("../lensCore").LensCore>;
|
|
28
27
|
token: "lensCore";
|
|
29
28
|
dependencies: readonly ["defaultFetchHandler", "configuration"];
|
|
30
29
|
};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { simd, exceptions } from "wasm-feature-detect";
|
|
3
2
|
import lensCoreWasm from "../../lensCoreWasmVersions.json";
|
|
4
3
|
import { loadScript } from "../../common";
|
|
5
4
|
import { configurationToken } from "../../configuration";
|
|
6
5
|
import { Injectable } from "../../dependency-injection/Injectable";
|
|
7
6
|
import { defaultFetchHandlerFactory } from "../../handlers/defaultFetchHandler";
|
|
8
7
|
import { getLogger } from "../../logger/logger";
|
|
9
|
-
import {
|
|
8
|
+
import { WasmFeatures, getPlatformCapabilities } from "../../platform/platformCapabilities";
|
|
9
|
+
import { getPlatformInfo } from "../../platform/platformInfo";
|
|
10
|
+
import { createLensCore } from "../lensCore";
|
|
10
11
|
const logger = getLogger("lensCoreFactory");
|
|
11
12
|
const wasmAssets = ["LensCoreWebAssembly.js", "LensCoreWebAssembly.wasm"];
|
|
12
13
|
const findMatch = (regex, strings) => strings.find((s) => regex.test(s));
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[PlatformFeatures.Default]: "release",
|
|
14
|
+
/**
|
|
15
|
+
* Map various combinations of WebAssembly capabilities to the corresponding LensCore build flavours which make use
|
|
16
|
+
* of them.
|
|
17
|
+
*/
|
|
18
|
+
const wasmCapabilitiesToLensCoreBuildFlavor = {
|
|
19
|
+
[WasmFeatures.Default]: "release",
|
|
20
|
+
[WasmFeatures.ExceptionHandling]: "rel-neh",
|
|
21
|
+
[WasmFeatures.SIMD]: "release-simd",
|
|
22
|
+
[WasmFeatures.ExceptionHandling | WasmFeatures.SIMD]: "rel-simd-neh",
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Returns a list of URLs for resources which will be fetched during {@link bootstrapCameraKit}.
|
|
@@ -36,22 +36,20 @@ export function getRequiredBootstrapURLs(endpointOverride) {
|
|
|
36
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
// If we have an endpoint override, remove trailing `/` so we can construct a valid URL.
|
|
38
38
|
const endpoint = endpointOverride === null || endpointOverride === void 0 ? void 0 : endpointOverride.replace(/[\/]+$/, "");
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const version = lensCoreWasm.version;
|
|
50
|
-
const buildNumber = lensCoreWasm.buildNumber;
|
|
39
|
+
const { wasm } = yield getPlatformCapabilities();
|
|
40
|
+
if (!wasm.supported)
|
|
41
|
+
throw wasm.error;
|
|
42
|
+
const { lensCore } = getPlatformInfo();
|
|
43
|
+
const flavor = wasmCapabilitiesToLensCoreBuildFlavor[wasm.wasmFeatures];
|
|
44
|
+
if (!flavor)
|
|
45
|
+
throw new Error(`Could not determine a LensCore build flavor corresponding to the bitstring ` +
|
|
46
|
+
`${wasm.wasmFeatures.toString(2)}. CameraKit cannot be bootstrapped.`);
|
|
47
|
+
const version = lensCore.version;
|
|
48
|
+
const buildNumber = lensCore.buildNumber;
|
|
51
49
|
return wasmAssets.map((asset) => {
|
|
52
50
|
if (endpoint)
|
|
53
51
|
return `${endpoint}/${asset}`;
|
|
54
|
-
const { origin, pathname, search } = new URL(
|
|
52
|
+
const { origin, pathname, search } = new URL(lensCore.baseUrl);
|
|
55
53
|
return `${origin}${pathname}/${version}/${buildNumber}/${flavor}/${asset}${search}`;
|
|
56
54
|
});
|
|
57
55
|
});
|
|
@@ -118,6 +116,6 @@ export const lensCoreFactory = Injectable("lensCore", [defaultFetchHandlerFactor
|
|
|
118
116
|
if (lensCoreWasm.version != `${lensCore.getCoreVersion()}`) {
|
|
119
117
|
logger.warn(`Loaded LensCore version (${lensCore.getCoreVersion()}) differs from expected one (${lensCoreWasm.version})`);
|
|
120
118
|
}
|
|
121
|
-
return lensCore;
|
|
119
|
+
return createLensCore(lensCore);
|
|
122
120
|
}));
|
|
123
121
|
//# sourceMappingURL=lensCoreFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1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,CAA2C,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7F,IAAI,aAA+C,CAAC;QACpD,qDAAqD;QACrD,mEAAmE;QACnE,wCAAwC;QACxC,mCAAmC;QACnC,mKAAmK;QACnK,MAAM,UAAU,GAAG,UAAU,CAAC,kBAAkB,CAC5C,CAAC,aAAa,GAAG;YACb,kEAAkE;YAClE,mBAAmB,EAAE,UAAU;YAC/B,4DAA4D;YAC5D,eAAe,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,EAAE;gBAC/C,WAAW,CAAC,oBAAoB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;qBAChE,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE;oBAChC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;oBAClC,2CAA2C;oBAC3C,aAAa,CAAC,cAAc,GAAG,MAAM,CAAC;oBACtC,OAAO,CAAC,UAAU,CAAC,CAAC;gBACxB,CAAC,CAAC;qBACD,KAAK,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;SACJ,CAAC,CACL,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,6EAA6E;IAC7E,aAAa,CAAC,MAAM,EAAE,CAAC;IAEvB,6DAA6D;IAC7D,IAAI,YAAY,CAAC,OAAO,IAAI,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,EAAE;QACxD,MAAM,CAAC,IAAI,CACP,4BAA4B,QAAQ,CAAC,cAAc,EAAE,gCACjD,YAAY,CAAC,OACjB,GAAG,CACN,CAAC;KACL;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAA,CACJ,CAAC","sourcesContent":["import { simd, exceptions } from \"wasm-feature-detect\";\nimport lensCoreWasm from \"../../lensCoreWasmVersions.json\";\nimport { loadScript } from \"../../common\";\nimport { CameraKitConfiguration, configurationToken } from \"../../configuration\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { InitialEmscriptenModule, LensCoreModule } from \"../generated-types\";\nimport { getLogger } from \"../../logger/logger\";\nimport { cameraKitUserAgent } from \"../../common/cameraKitUserAgent\";\n\nconst logger = getLogger(\"lensCoreFactory\");\n\nconst wasmAssets = [\"LensCoreWebAssembly.js\", \"LensCoreWebAssembly.wasm\"];\n\nconst findMatch = (regex: RegExp, strings: string[]) => strings.find((s) => regex.test(s));\n\nconst PlatformFeatures = {\n Default: 0,\n Simd: 0b01,\n Exceptions: 0b10,\n};\n\nconst platformFeaturesToFlavour = {\n [PlatformFeatures.Exceptions | PlatformFeatures.Simd]: \"rel-simd-neh\",\n [PlatformFeatures.Simd]: \"release-simd\",\n [PlatformFeatures.Exceptions]: \"rel-neh\",\n [PlatformFeatures.Default]: \"release\",\n};\n\n/**\n * Returns a list of URLs for resources which will be fetched during {@link bootstrapCameraKit}.\n *\n * When CameraKit is used on a website, these URLs much be reachable in order for CameraKit to be successfully\n * bootstrapped.\n *\n * @param endpointOverride Optional endpoint override to load the assets from.\n * @returns An array of asset URLs.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function getRequiredBootstrapURLs(endpointOverride?: string): Promise<string[]> {\n // If we have an endpoint override, remove trailing `/` so we can construct a valid URL.\n const endpoint = endpointOverride?.replace(/[\\/]+$/, \"\");\n\n let [simdFeature, exceptionsFeature] = await Promise.all([\n simd().then((supported) => (supported ? PlatformFeatures.Simd : PlatformFeatures.Default)),\n exceptions().then((supported) => (supported ? PlatformFeatures.Exceptions : PlatformFeatures.Default)),\n ]);\n\n // Although Safari 16.4 reports SIMD support, LensCore encounters rendering bugs when using SIMD in Safari 16.4.\n // Therefore, we have made the decision to disable SIMD for now until Safari stabilizes the feature.\n const { brand } = cameraKitUserAgent.browser;\n if (brand === \"Safari\") simdFeature = PlatformFeatures.Default;\n\n const flavor = platformFeaturesToFlavour[simdFeature | exceptionsFeature];\n\n const version = lensCoreWasm.version;\n const buildNumber = lensCoreWasm.buildNumber;\n return wasmAssets.map((asset) => {\n if (endpoint) return `${endpoint}/${asset}`;\n const { origin, pathname, search } = new URL(lensCoreWasm.baseUrl);\n return `${origin}${pathname}/${version}/${buildNumber}/${flavor}/${asset}${search}`;\n });\n}\n\n/**\n * This component is responsible for:\n * 1) Loading LensCore WebAssembly (WASM) assets\n * 2) Using the WASM assets to initialize the LensCore WASM module\n *\n * By default, WASM assets will be loaded from the Bolt CDN – but if `endpoint` is provided, assets will be loaded\n * using it as a base URL.\n *\n * @internal\n */\nexport const lensCoreFactory = Injectable(\n \"lensCore\",\n [defaultFetchHandlerFactory.token, configurationToken] as const,\n async (handler: FetchHandler, { lensCoreOverrideUrls, wasmEndpointOverride }: CameraKitConfiguration) => {\n let lensCoreJS: string;\n let lensCoreWASM: string;\n\n if (lensCoreOverrideUrls) {\n lensCoreJS = lensCoreOverrideUrls.js;\n lensCoreWASM = lensCoreOverrideUrls.wasm;\n } else {\n const endpointOverride = wasmEndpointOverride ?? undefined;\n const assetURLs = await getRequiredBootstrapURLs(endpointOverride);\n\n lensCoreJS = findMatch(/\\.js/, assetURLs) ?? \"\";\n lensCoreWASM = findMatch(/\\.wasm/, assetURLs) ?? \"\";\n\n if (!lensCoreJS || !lensCoreWASM) {\n throw new Error(\n `Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +\n `this list: ${assetURLs}.`\n );\n }\n\n // Fetching here and creating an Object URL lets LensCore optimized loading itself in a WebWorker,\n // otherwise the glue script would need to be downloaded again.\n const glueScript = await handler(lensCoreJS).then((r) => r.blob());\n lensCoreJS = URL.createObjectURL(glueScript);\n }\n\n const scriptElement = await loadScript(lensCoreJS);\n\n const lensCore = await new Promise<InitialEmscriptenModule & LensCoreModule>((resolve, reject) => {\n let initialModule: Partial<InitialEmscriptenModule>;\n // will trigger WASM initialization and data loading,\n // after completion it will be safe to call imported WASM functions\n // More about emscripten initialization:\n // eslint-disable-next-line max-len\n // https://emscripten.org/docs/getting_started/FAQ.html?highlight=modularize#how-can-i-tell-when-the-page-is-fully-loaded-and-it-is-safe-to-call-compiled-functions\n const moduleInit = globalThis.createLensesModule(\n (initialModule = {\n // url will be used for loading glue JS during Worker inialization\n mainScriptUrlOrBlob: lensCoreJS,\n // will be triggered by Emscripten during the initialization\n instantiateWasm: (importObject, receiveInstance) => {\n WebAssembly.instantiateStreaming(handler(lensCoreWASM), importObject)\n .then(function ({ instance, module }) {\n receiveInstance(instance, module);\n // compiled module will be reused in Worker\n initialModule.compiledModule = module;\n resolve(moduleInit);\n })\n .catch(reject);\n },\n })\n );\n });\n\n // now when we have LensCore WASM in memory we can release the script element\n scriptElement.remove();\n\n // print warning if loaded version differs from hardcoded one\n if (lensCoreWasm.version != `${lensCore.getCoreVersion()}`) {\n logger.warn(\n `Loaded LensCore version (${lensCore.getCoreVersion()}) differs from expected one (${\n lensCoreWasm.version\n })`\n );\n }\n\n return lensCore;\n }\n);\n"]}
|
|
1
|
+
{"version":3,"file":"lensCoreFactory.js","sourceRoot":"","sources":["../../../src/lens-core-module/loader/lensCoreFactory.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAA0B,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAgB,MAAM,oCAAoC,CAAC;AAE9F,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAE5C,MAAM,UAAU,GAAG,CAAC,wBAAwB,E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AED,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC,CAAA,CACJ,CAAC","sourcesContent":["import lensCoreWasm from \"../../lensCoreWasmVersions.json\";\nimport { loadScript } from \"../../common\";\nimport { CameraKitConfiguration, configurationToken } from \"../../configuration\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { InitialEmscriptenModule, LensCoreModule } from \"../generated-types\";\nimport { getLogger } from \"../../logger/logger\";\nimport { WasmFeatures, getPlatformCapabilities } from \"../../platform/platformCapabilities\";\nimport { getPlatformInfo } from \"../../platform/platformInfo\";\nimport { createLensCore } from \"../lensCore\";\n\nconst logger = getLogger(\"lensCoreFactory\");\n\nconst wasmAssets = [\"LensCoreWebAssembly.js\", \"LensCoreWebAssembly.wasm\"];\n\nconst findMatch = (regex: RegExp, strings: string[]) => strings.find((s) => regex.test(s));\n\n/**\n * Map various combinations of WebAssembly capabilities to the corresponding LensCore build flavours which make use\n * of them.\n */\nconst wasmCapabilitiesToLensCoreBuildFlavor = {\n [WasmFeatures.Default]: \"release\",\n [WasmFeatures.ExceptionHandling]: \"rel-neh\",\n [WasmFeatures.SIMD]: \"release-simd\",\n [WasmFeatures.ExceptionHandling | WasmFeatures.SIMD]: \"rel-simd-neh\",\n};\n\n/**\n * Returns a list of URLs for resources which will be fetched during {@link bootstrapCameraKit}.\n *\n * When CameraKit is used on a website, these URLs much be reachable in order for CameraKit to be successfully\n * bootstrapped.\n *\n * @param endpointOverride Optional endpoint override to load the assets from.\n * @returns An array of asset URLs.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function getRequiredBootstrapURLs(endpointOverride?: string): Promise<string[]> {\n // If we have an endpoint override, remove trailing `/` so we can construct a valid URL.\n const endpoint = endpointOverride?.replace(/[\\/]+$/, \"\");\n\n const { wasm } = await getPlatformCapabilities();\n if (!wasm.supported) throw wasm.error;\n\n const { lensCore } = getPlatformInfo();\n const flavor = wasmCapabilitiesToLensCoreBuildFlavor[wasm.wasmFeatures];\n if (!flavor)\n throw new Error(\n `Could not determine a LensCore build flavor corresponding to the bitstring ` +\n `${wasm.wasmFeatures.toString(2)}. CameraKit cannot be bootstrapped.`\n );\n const version = lensCore.version;\n const buildNumber = lensCore.buildNumber;\n return wasmAssets.map((asset) => {\n if (endpoint) return `${endpoint}/${asset}`;\n const { origin, pathname, search } = new URL(lensCore.baseUrl);\n return `${origin}${pathname}/${version}/${buildNumber}/${flavor}/${asset}${search}`;\n });\n}\n\n/**\n * This component is responsible for:\n * 1) Loading LensCore WebAssembly (WASM) assets\n * 2) Using the WASM assets to initialize the LensCore WASM module\n *\n * By default, WASM assets will be loaded from the Bolt CDN – but if `endpoint` is provided, assets will be loaded\n * using it as a base URL.\n *\n * @internal\n */\nexport const lensCoreFactory = Injectable(\n \"lensCore\",\n [defaultFetchHandlerFactory.token, configurationToken] as const,\n async (handler: FetchHandler, { lensCoreOverrideUrls, wasmEndpointOverride }: CameraKitConfiguration) => {\n let lensCoreJS: string;\n let lensCoreWASM: string;\n\n if (lensCoreOverrideUrls) {\n lensCoreJS = lensCoreOverrideUrls.js;\n lensCoreWASM = lensCoreOverrideUrls.wasm;\n } else {\n const endpointOverride = wasmEndpointOverride ?? undefined;\n const assetURLs = await getRequiredBootstrapURLs(endpointOverride);\n\n lensCoreJS = findMatch(/\\.js/, assetURLs) ?? \"\";\n lensCoreWASM = findMatch(/\\.wasm/, assetURLs) ?? \"\";\n\n if (!lensCoreJS || !lensCoreWASM) {\n throw new Error(\n `Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +\n `this list: ${assetURLs}.`\n );\n }\n\n // Fetching here and creating an Object URL lets LensCore optimized loading itself in a WebWorker,\n // otherwise the glue script would need to be downloaded again.\n const glueScript = await handler(lensCoreJS).then((r) => r.blob());\n lensCoreJS = URL.createObjectURL(glueScript);\n }\n\n const scriptElement = await loadScript(lensCoreJS);\n\n const lensCore = await new Promise<InitialEmscriptenModule & LensCoreModule>((resolve, reject) => {\n let initialModule: Partial<InitialEmscriptenModule>;\n // will trigger WASM initialization and data loading,\n // after completion it will be safe to call imported WASM functions\n // More about emscripten initialization:\n // eslint-disable-next-line max-len\n // https://emscripten.org/docs/getting_started/FAQ.html?highlight=modularize#how-can-i-tell-when-the-page-is-fully-loaded-and-it-is-safe-to-call-compiled-functions\n const moduleInit = globalThis.createLensesModule(\n (initialModule = {\n // url will be used for loading glue JS during Worker inialization\n mainScriptUrlOrBlob: lensCoreJS,\n // will be triggered by Emscripten during the initialization\n instantiateWasm: (importObject, receiveInstance) => {\n WebAssembly.instantiateStreaming(handler(lensCoreWASM), importObject)\n .then(function ({ instance, module }) {\n receiveInstance(instance, module);\n // compiled module will be reused in Worker\n initialModule.compiledModule = module;\n resolve(moduleInit);\n })\n .catch(reject);\n },\n })\n );\n });\n\n // now when we have LensCore WASM in memory we can release the script element\n scriptElement.remove();\n\n // print warning if loaded version differs from hardcoded one\n if (lensCoreWasm.version != `${lensCore.getCoreVersion()}`) {\n logger.warn(\n `Loaded LensCore version (${lensCore.getCoreVersion()}) differs from expected one (${\n lensCoreWasm.version\n })`\n );\n }\n\n return createLensCore(lensCore);\n }\n);\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
3
|
-
"buildNumber": "
|
|
4
|
-
"baseUrl": "https://cf-st.sc-cdn.net/d/
|
|
2
|
+
"version": "239",
|
|
3
|
+
"buildNumber": "148",
|
|
4
|
+
"baseUrl": "https://cf-st.sc-cdn.net/d/vzrhSjRylX02Y8J6eVgUV?go=IgsKCTIBBEgBUFxgAQ%3D%3D&uc=92"
|
|
5
5
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { filter } from "rxjs";
|
|
2
|
-
import { cameraKitUserAgent } from "../common/cameraKitUserAgent";
|
|
3
2
|
import { stringifyError } from "../common/errorHelpers";
|
|
4
3
|
import { configurationToken } from "../configuration";
|
|
5
4
|
import { Injectable } from "../dependency-injection/Injectable";
|
|
5
|
+
import { getPlatformInfo } from "../platform/platformInfo";
|
|
6
6
|
import { logEntriesFactory } from "./logEntries";
|
|
7
7
|
import { logLevelMap } from "./logger";
|
|
8
8
|
/**
|
|
@@ -19,7 +19,7 @@ export const registerLogEntriesSubscriber = Injectable("registerLogEntriesSubscr
|
|
|
19
19
|
case "console":
|
|
20
20
|
// Chrome doesn't print the `cause` Error property, so we need to manually construct a complete
|
|
21
21
|
// stack trace using our `stringifyError` helper.
|
|
22
|
-
const messages =
|
|
22
|
+
const messages = getPlatformInfo().browser.brand === "Chrome"
|
|
23
23
|
? logEntry.messages.map((message) => {
|
|
24
24
|
if (!(message instanceof Error))
|
|
25
25
|
return message;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerLogEntriesSubscriber.js","sourceRoot":"","sources":["../../src/logger/registerLogEntriesSubscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"registerLogEntriesSubscriber.js","sourceRoot":"","sources":["../../src/logger/registerLogEntriesSubscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAA0B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAY,WAAW,EAAE,MAAM,UAAU,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,UAAU,CAClD,8BAA8B,EAC9B,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,KAAK,CAAU,EACtD,CAAC,aAAqC,EAAE,UAAgC,EAAE,EAAE;IACxE,UAAU;SACL,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;SACxF,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE;QACpB,QAAQ,aAAa,CAAC,MAAM,EAAE;YAC1B,KAAK,SAAS;gBACV,+FAA+F;gBAC/F,iDAAiD;gBACjD,MAAM,QAAQ,GACV,eAAe,EAAE,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ;oBACxC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;wBAC9B,IAAI,CAAC,CAAC,OAAO,YAAY,KAAK,CAAC;4BAAE,OAAO,OAAO,CAAC;wBAChD,OAAO,CAAC,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;wBACxC,OAAO,OAAO,CAAC;oBACnB,CAAC,CAAC;oBACJ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAE5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,cAAc,QAAQ,CAAC,MAAM,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAC;gBACvE,MAAM;SACb;IACL,CAAC,CAAC,CAAC;AACX,CAAC,CACJ,CAAC","sourcesContent":["import { filter, Observable } from \"rxjs\";\nimport { stringifyError } from \"../common/errorHelpers\";\nimport { CameraKitConfiguration, configurationToken } from \"../configuration\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { getPlatformInfo } from \"../platform/platformInfo\";\nimport { logEntriesFactory } from \"./logEntries\";\nimport { LogEntry, logLevelMap } from \"./logger\";\n\n/**\n * The factory subscribes to log entry events and, based on the configured log level,\n * forwards matching log entries to the logger specified in the CameraKit configuration object.\n *\n * @internal\n */\nexport const registerLogEntriesSubscriber = Injectable(\n \"registerLogEntriesSubscriber\",\n [configurationToken, logEntriesFactory.token] as const,\n (configuration: CameraKitConfiguration, logEntries: Observable<LogEntry>) => {\n logEntries\n .pipe(filter((entry) => logLevelMap[entry.level] >= logLevelMap[configuration.logLevel]))\n .subscribe((logEntry) => {\n switch (configuration.logger) {\n case \"console\":\n // Chrome doesn't print the `cause` Error property, so we need to manually construct a complete\n // stack trace using our `stringifyError` helper.\n const messages =\n getPlatformInfo().browser.brand === \"Chrome\"\n ? logEntry.messages.map((message) => {\n if (!(message instanceof Error)) return message;\n message.stack = stringifyError(message);\n return message;\n })\n : logEntry.messages;\n\n console[logEntry.level](`[CameraKit.${logEntry.module}]`, ...messages);\n break;\n }\n });\n }\n);\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LensCore, UseMediaElementInput } from "../lens-core-module";
|
|
2
2
|
import { Transform2D } from "../transforms";
|
|
3
3
|
/**
|
|
4
4
|
* When creating a {@link CameraKitSource}, passing a CameraKitSourceSubscriber allows logic to implemented which will
|
|
@@ -7,7 +7,7 @@ import { Transform2D } from "../transforms";
|
|
|
7
7
|
* @category Rendering
|
|
8
8
|
*/
|
|
9
9
|
export interface CameraKitSourceSubscriber {
|
|
10
|
-
readonly onAttach?: (source: CameraKitSource, lensCore:
|
|
10
|
+
readonly onAttach?: (source: CameraKitSource, lensCore: LensCore, reportError: (error: Error) => void) => void | Promise<void>;
|
|
11
11
|
readonly onDetach?: (reportError: (error: Error) => void) => void | Promise<void>;
|
|
12
12
|
}
|
|
13
13
|
/** @category Rendering
|
|
@@ -51,7 +51,7 @@ export declare class CameraKitSource {
|
|
|
51
51
|
* @returns Rejects if any calls to LensCore or CameraKitSource.subscriber.onAttach fail.
|
|
52
52
|
* @internal
|
|
53
53
|
*/
|
|
54
|
-
attach(lensCore:
|
|
54
|
+
attach(lensCore: LensCore, reportError: (error: Error) => void): Promise<void>;
|
|
55
55
|
/**
|
|
56
56
|
* Make a copy of the source, sharing the same {@link CameraKitSourceSubscriber}.
|
|
57
57
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/member-ordering */
|
|
2
2
|
import { __awaiter, __decorate, __metadata } from "tslib";
|
|
3
|
+
import { copyDefinedProperties } from "../common/copyDefinedProperties";
|
|
3
4
|
import { validate } from "../common/validate";
|
|
4
5
|
import { Transform2D } from "../transforms";
|
|
5
6
|
const defaultDeviceInfo = {
|
|
@@ -22,7 +23,7 @@ export class CameraKitSource {
|
|
|
22
23
|
constructor(sourceInfo, subscriber = {}, deviceInfo = {}) {
|
|
23
24
|
this.sourceInfo = sourceInfo;
|
|
24
25
|
this.subscriber = subscriber;
|
|
25
|
-
this.deviceInfo = Object.assign(Object.assign({}, defaultDeviceInfo), deviceInfo);
|
|
26
|
+
this.deviceInfo = Object.assign(Object.assign({}, defaultDeviceInfo), copyDefinedProperties(deviceInfo));
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Called by {@link CameraKitSession} when this source is set as that session's source.
|
|
@@ -39,25 +40,19 @@ export class CameraKitSource {
|
|
|
39
40
|
"a CameraKitSession. To re-attach, create a copy of this CameraKitCustomSource.");
|
|
40
41
|
}
|
|
41
42
|
this.lensCore = lensCore;
|
|
42
|
-
yield
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
useManualFrameProcessing: this.sourceInfo.useManualFrameProcessing,
|
|
52
|
-
onSuccess,
|
|
53
|
-
onFailure,
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
yield new Promise((onSuccess, onFailure) => {
|
|
57
|
-
// LensCore uses 0 to remove the limit.
|
|
58
|
-
const fps = this.deviceInfo.fpsLimit < Number.POSITIVE_INFINITY ? this.deviceInfo.fpsLimit : 0;
|
|
59
|
-
lensCore.setFPSLimit({ fps, onSuccess, onFailure });
|
|
43
|
+
yield lensCore.useMediaElement({
|
|
44
|
+
autoplayNewMedia: false,
|
|
45
|
+
autoplayPreviewCanvas: false,
|
|
46
|
+
media: this.sourceInfo.media,
|
|
47
|
+
pauseExistingMedia: false,
|
|
48
|
+
replayTrackingData: this.sourceInfo.replayTrackingData,
|
|
49
|
+
requestWebcam: false,
|
|
50
|
+
startOnFrontCamera: ["user", "front"].includes(this.deviceInfo.cameraType),
|
|
51
|
+
useManualFrameProcessing: this.sourceInfo.useManualFrameProcessing,
|
|
60
52
|
});
|
|
53
|
+
// LensCore uses 0 to remove the limit.
|
|
54
|
+
const fps = this.deviceInfo.fpsLimit < Number.POSITIVE_INFINITY ? this.deviceInfo.fpsLimit : 0;
|
|
55
|
+
yield lensCore.setFPSLimit({ fps });
|
|
61
56
|
if (this.subscriber.onAttach)
|
|
62
57
|
yield this.subscriber.onAttach(this, lensCore, reportError);
|
|
63
58
|
});
|
|
@@ -98,12 +93,10 @@ export class CameraKitSource {
|
|
|
98
93
|
* @returns Promise resolves when the render size has been successfully updated.
|
|
99
94
|
*/
|
|
100
95
|
setRenderSize(width, height) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.lensCore.setRenderSize({ mode: "explicit", target, onSuccess, onFailure });
|
|
106
|
-
});
|
|
96
|
+
if (!this.lensCore)
|
|
97
|
+
return Promise.reject(createNotAttachedError("Cannot setRenderSize"));
|
|
98
|
+
const target = { width, height };
|
|
99
|
+
return this.lensCore.setRenderSize({ mode: "explicit", target });
|
|
107
100
|
}
|
|
108
101
|
/**
|
|
109
102
|
* Apply a 2D transformation to the source (e.g. translation, rotation, scale).
|
|
@@ -111,12 +104,10 @@ export class CameraKitSource {
|
|
|
111
104
|
* @param transform Specifies the 3x3 matrix describing the transformation.
|
|
112
105
|
*/
|
|
113
106
|
setTransform(transform) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.lensCore.setInputTransform({ matrix, onSuccess, onFailure });
|
|
119
|
-
});
|
|
107
|
+
if (!this.lensCore)
|
|
108
|
+
return Promise.reject(createNotAttachedError("Cannot setTransform"));
|
|
109
|
+
const matrix = new Float32Array(transform.matrix);
|
|
110
|
+
return this.lensCore.setInputTransform({ matrix });
|
|
120
111
|
}
|
|
121
112
|
}
|
|
122
113
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CameraKitSource.js","sourceRoot":"","sources":["../../src/media-sources/CameraKitSource.ts"],"names":[],"mappings":"AAAA,uDAAuD;;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,iBAAiB,GAA2B;IAC9C,UAAU,EAAE,MAAM;IAClB,QAAQ,EAAE,MAAM,CAAC,iBAAiB;CACrC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,OAAe,EAAE,EAAE,CAC/C,IAAI,KAAK,CAAC,GAAG,OAAO,+DAA+D,CAAC,CAAC;AAwCzF;;;;;;;;;;GAUG;AACH,MAAM,OAAO,eAAe;IAIxB,YACqB,UAA+B,EAC/B,aAAwC,EAAE,EAC3D,aAAoE,EAAE;QAFrD,eAAU,GAAV,UAAU,CAAqB;QAC/B,eAAU,GAAV,UAAU,CAAgC;QAG3D,IAAI,CAAC,UAAU,mCAAQ,iBAAiB,GAAK,UAAU,CAAE,CAAC;IAC9D,CAAC;IAED;;;;;;;OAOG;IACG,MAAM,CAAC,QAAwB,EAAE,WAAmC;;YACtE,IAAI,IAAI,CAAC,QAAQ,EAAE;gBACf,MAAM,IAAI,KAAK,CACX,yEAAyE;oBACrE,gFAAgF,CACvF,CAAC;aACL;YAED,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAEzB,MAAM,IAAI,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE;gBACvC,QAAQ,CAAC,eAAe,CAAC;o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AC,sBAAsB,CAAC,eAAe,CAAC,CAAC,CAAC;QACnF,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC/E,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IAEH,aAAa,CAAC,KAAa,EAAE,MAAc;QACvC,OAAO,IAAI,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE;YACxC,IAAI,CAAC,IAAI,CAAC,QAAQ;gBAAE,OAAO,SAAS,CAAC,sBAAsB,CAAC,sBAAsB,CAAC,CAAC,CAAC;YACrF,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IAEH,YAAY,CAAC,SAAsB;QAC/B,OAAO,IAAI,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE;YACxC,IAAI,CAAC,IAAI,CAAC,QAAQ;gBAAE,OAAO,SAAS,CAAC,sBAAsB,CAAC,qBAAqB,CAAC,CAAC,CAAC;YACpF,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAClD,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AArBG;IADC,QAAQ;;;;oDAOR;AAQD;IADC,QAAQ;;qCACe,WAAW;;mDAMlC","sourcesContent":["/* eslint-disable @typescript-eslint/member-ordering */\n\nimport { validate } from \"../common/validate\";\nimport { LensCoreModule, UseMediaElementInput } from \"../lens-core-module/generated-types\";\nimport { Transform2D } from \"../transforms\";\n\nconst defaultDeviceInfo: CameraKitDeviceOptions = {\n cameraType: \"user\",\n fpsLimit: Number.POSITIVE_INFINITY,\n};\n\nconst createNotAttachedError = (message: string) =>\n new Error(`${message}. This CameraKitSource is not attached to a CameraKitSession.`);\n\n/**\n * When creating a {@link CameraKitSource}, passing a CameraKitSourceSubscriber allows logic to implemented which will\n * run whenever that source is attached/detached from a CameraKitSession.\n *\n * @category Rendering\n */\nexport interface CameraKitSourceSubscriber {\n readonly onAttach?: (\n source: CameraKitSource,\n lensCore: LensCoreModule,\n reportError: (error: Error) => void\n ) => void | Promise<void>;\n readonly onDetach?: (reportError: (error: Error) => void) => void | Promise<void>;\n}\n\n/** @category Rendering\n * @deprecated use {@link CameraKitDeviceOptions}\n */\nexport type CameraKitDeviceInfo = {\n /** @deprecated \"front\" and \"back\" are deprecated please use \"user\" or \"enviroment\" for cameraType instead */\n cameraType: \"front\" | \"back\";\n fpsLimit: number;\n};\n\n/** @category Rendering */\nexport type CameraKitDeviceOptions = {\n cameraType: \"user\" | \"environment\";\n fpsLimit: number;\n};\n\nexport type CameraKitSourceInfo = Pick<\n UseMediaElementInput,\n \"media\" | \"replayTrackingData\" | \"useManualFrameProcessing\"\n>;\n\n/** @category Rendering */\nexport type CameraKitSourceOptions<T = {}> = Partial<T> & Partial<CameraKitDeviceInfo | CameraKitDeviceOptions>;\n\n/**\n * This general-purpose class represents a source of media for a {@link CameraKitSession}.\n *\n * When an instance is passed to {@link CameraKitSession.setSource | CameraKitSession.setSource}, it will be \"attached\"\n * to the session. Later it may be \"detached\" from the session.\n *\n * Passing a {@link CameraKitSourceSubscriber} to the constructor allows callers to specify behavior\n * that will occur when the source is attached and detached. This can be used to e.g. update the render size.\n *\n * @category Rendering\n */\nexport class CameraKitSource {\n private lensCore?: LensCoreModule;\n private readonly deviceInfo: CameraKitDeviceInfo | CameraKitDeviceOptions;\n\n constructor(\n private readonly sourceInfo: CameraKitSourceInfo,\n private readonly subscriber: CameraKitSourceSubscriber = {},\n deviceInfo: Partial<CameraKitDeviceInfo | CameraKitDeviceOptions> = {}\n ) {\n this.deviceInfo = { ...defaultDeviceInfo, ...deviceInfo };\n }\n\n /**\n * Called by {@link CameraKitSession} when this source is set as that session's source.\n *\n * @param lensCore\n * @param reportError Calling this function will report an error back to the session.\n * @returns Rejects if any calls to LensCore or CameraKitSource.subscriber.onAttach fail.\n * @internal\n */\n async attach(lensCore: LensCoreModule, reportError: (error: Error) => void): Promise<void> {\n if (this.lensCore) {\n throw new Error(\n \"Cannot attach. This CameraKitCustomSource has already been attached to \" +\n \"a CameraKitSession. To re-attach, create a copy of this CameraKitCustomSource.\"\n );\n }\n\n this.lensCore = lensCore;\n\n await new Promise((onSuccess, onFailure) => {\n lensCore.useMediaElement({\n autoplayNewMedia: false,\n autoplayPreviewCanvas: false,\n media: this.sourceInfo.media,\n pauseExistingMedia: false,\n replayTrackingData: this.sourceInfo.replayTrackingData,\n requestWebcam: false,\n startOnFrontCamera: [\"user\", \"front\"].includes(this.deviceInfo.cameraType),\n useManualFrameProcessing: this.sourceInfo.useManualFrameProcessing,\n onSuccess,\n onFailure,\n });\n });\n\n await new Promise<void>((onSuccess, onFailure) => {\n // LensCore uses 0 to remove the limit.\n const fps = this.deviceInfo.fpsLimit < Number.POSITIVE_INFINITY ? this.deviceInfo.fpsLimit : 0;\n lensCore.setFPSLimit({ fps, onSuccess, onFailure });\n });\n\n if (this.subscriber.onAttach) await this.subscriber.onAttach(this, lensCore, reportError);\n }\n\n /**\n * Make a copy of the source, sharing the same {@link CameraKitSourceSubscriber}.\n *\n * @param deviceInfo Optionally provide new device info for the copy (e.g. to change the camera type).\n * @returns The new {@link CameraKitSource}\n */\n /** @deprecated Use {@link CameraKitDeviceOptions} where cameraType is either \"environment\" or \"user\" */\n copy(deviceInfo?: Partial<CameraKitDeviceInfo>): CameraKitSource;\n copy(deviceInfo?: Partial<CameraKitDeviceOptions>): CameraKitSource;\n copy(deviceInfo: Partial<CameraKitDeviceOptions | CameraKitDeviceInfo> = {}): CameraKitSource {\n return new CameraKitSource(this.sourceInfo, this.subscriber, { ...this.deviceInfo, ...deviceInfo });\n }\n\n /**\n * Called by {@link CameraKitSession} when it must remove this source.\n *\n * @param reportError Calling this function will report an error back to the session.\n * @returns\n * @internal\n */\n detach(reportError: (error: Error) => void): void | Promise<void> {\n if (!this.lensCore) return Promise.reject(createNotAttachedError(\"Cannot detach\"));\n if (this.subscriber.onDetach) return this.subscriber.onDetach(reportError);\n }\n\n /**\n * Set the resolution used to render this source.\n *\n * It’s important to distinguish render size from display size. The size at which the output canvases are displayed\n * on a web page is determined by the CSS of the page. It is distinct from the size at which LensCore renders\n * Lenses. Performance is dominated by render size, while any display scaling can most often be thought of as free.\n *\n * If greater performance is required, a smaller render size may boost frame-rate. It does come at a cost, including\n * loss of accuracy in various tracking and computer-vision algorithms (since they'll be operating on fewer pixels).\n *\n * The size of the Live and Capture {@link RenderTarget} is always the same.\n *\n * @todo Currently it's only valid to call `setRenderSize` after `CameraKitSession.play` has been called. This\n * constraint should be removed, so callers don't have to understand the underlying LensCore state machine.\n *\n * @param width pixels\n * @param height pixels\n * @returns Promise resolves when the render size has been successfully updated.\n */\n @validate\n setRenderSize(width: number, height: number): Promise<void> {\n return new Promise((onSuccess, onFailure) => {\n if (!this.lensCore) return onFailure(createNotAttachedError(\"Cannot setRenderSize\"));\n const target = { width, height };\n this.lensCore.setRenderSize({ mode: \"explicit\", target, onSuccess, onFailure });\n });\n }\n\n /**\n * Apply a 2D transformation to the source (e.g. translation, rotation, scale).\n *\n * @param transform Specifies the 3x3 matrix describing the transformation.\n */\n @validate\n setTransform(transform: Transform2D): Promise<void> {\n return new Promise((onSuccess, onFailure) => {\n if (!this.lensCore) return onFailure(createNotAttachedError(\"Cannot setTransform\"));\n const matrix = new Float32Array(transform.matrix);\n this.lensCore.setInputTransform({ matrix, onSuccess, onFailure });\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CameraKitSource.js","sourceR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Q,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;IACrE,CAAC;IAED;;;;OAIG;IAEH,YAAY,CAAC,SAAsB;QAC/B,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,OAAO,OAAO,CAAC,MAAM,CAAC,sBAAsB,CAAC,qBAAqB,CAAC,CAAC,CAAC;QACzF,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC;CACJ;AAjBG;IADC,QAAQ;;;;oDAKR;AAQD;IADC,QAAQ;;qCACe,WAAW;;mDAIlC","sourcesContent":["/* eslint-disable @typescript-eslint/member-ordering */\n\nimport { copyDefinedProperties } from \"../common/copyDefinedProperties\";\nimport { validate } from \"../common/validate\";\nimport { LensCore, UseMediaElementInput } from \"../lens-core-module\";\nimport { Transform2D } from \"../transforms\";\n\nconst defaultDeviceInfo: CameraKitDeviceOptions = {\n cameraType: \"user\",\n fpsLimit: Number.POSITIVE_INFINITY,\n};\n\nconst createNotAttachedError = (message: string) =>\n new Error(`${message}. This CameraKitSource is not attached to a CameraKitSession.`);\n\n/**\n * When creating a {@link CameraKitSource}, passing a CameraKitSourceSubscriber allows logic to implemented which will\n * run whenever that source is attached/detached from a CameraKitSession.\n *\n * @category Rendering\n */\nexport interface CameraKitSourceSubscriber {\n readonly onAttach?: (\n source: CameraKitSource,\n lensCore: LensCore,\n reportError: (error: Error) => void\n ) => void | Promise<void>;\n readonly onDetach?: (reportError: (error: Error) => void) => void | Promise<void>;\n}\n\n/** @category Rendering\n * @deprecated use {@link CameraKitDeviceOptions}\n */\nexport type CameraKitDeviceInfo = {\n /** @deprecated \"front\" and \"back\" are deprecated please use \"user\" or \"enviroment\" for cameraType instead */\n cameraType: \"front\" | \"back\";\n fpsLimit: number;\n};\n\n/** @category Rendering */\nexport type CameraKitDeviceOptions = {\n cameraType: \"user\" | \"environment\";\n fpsLimit: number;\n};\n\nexport type CameraKitSourceInfo = Pick<\n UseMediaElementInput,\n \"media\" | \"replayTrackingData\" | \"useManualFrameProcessing\"\n>;\n\n/** @category Rendering */\nexport type CameraKitSourceOptions<T = {}> = Partial<T> & Partial<CameraKitDeviceInfo | CameraKitDeviceOptions>;\n\n/**\n * This general-purpose class represents a source of media for a {@link CameraKitSession}.\n *\n * When an instance is passed to {@link CameraKitSession.setSource | CameraKitSession.setSource}, it will be \"attached\"\n * to the session. Later it may be \"detached\" from the session.\n *\n * Passing a {@link CameraKitSourceSubscriber} to the constructor allows callers to specify behavior\n * that will occur when the source is attached and detached. This can be used to e.g. update the render size.\n *\n * @category Rendering\n */\nexport class CameraKitSource {\n private lensCore?: LensCore;\n private readonly deviceInfo: CameraKitDeviceInfo | CameraKitDeviceOptions;\n\n constructor(\n private readonly sourceInfo: CameraKitSourceInfo,\n private readonly subscriber: CameraKitSourceSubscriber = {},\n deviceInfo: Partial<CameraKitDeviceInfo | CameraKitDeviceOptions> = {}\n ) {\n this.deviceInfo = { ...defaultDeviceInfo, ...copyDefinedProperties(deviceInfo) };\n }\n\n /**\n * Called by {@link CameraKitSession} when this source is set as that session's source.\n *\n * @param lensCore\n * @param reportError Calling this function will report an error back to the session.\n * @returns Rejects if any calls to LensCore or CameraKitSource.subscriber.onAttach fail.\n * @internal\n */\n async attach(lensCore: LensCore, reportError: (error: Error) => void): Promise<void> {\n if (this.lensCore) {\n throw new Error(\n \"Cannot attach. This CameraKitCustomSource has already been attached to \" +\n \"a CameraKitSession. To re-attach, create a copy of this CameraKitCustomSource.\"\n );\n }\n\n this.lensCore = lensCore;\n\n await lensCore.useMediaElement({\n autoplayNewMedia: false,\n autoplayPreviewCanvas: false,\n media: this.sourceInfo.media,\n pauseExistingMedia: false,\n replayTrackingData: this.sourceInfo.replayTrackingData,\n requestWebcam: false,\n startOnFrontCamera: [\"user\", \"front\"].includes(this.deviceInfo.cameraType),\n useManualFrameProcessing: this.sourceInfo.useManualFrameProcessing,\n });\n\n // LensCore uses 0 to remove the limit.\n const fps = this.deviceInfo.fpsLimit < Number.POSITIVE_INFINITY ? this.deviceInfo.fpsLimit : 0;\n await lensCore.setFPSLimit({ fps });\n\n if (this.subscriber.onAttach) await this.subscriber.onAttach(this, lensCore, reportError);\n }\n\n /**\n * Make a copy of the source, sharing the same {@link CameraKitSourceSubscriber}.\n *\n * @param deviceInfo Optionally provide new device info for the copy (e.g. to change the camera type).\n * @returns The new {@link CameraKitSource}\n */\n /** @deprecated Use {@link CameraKitDeviceOptions} where cameraType is either \"environment\" or \"user\" */\n copy(deviceInfo?: Partial<CameraKitDeviceInfo>): CameraKitSource;\n copy(deviceInfo?: Partial<CameraKitDeviceOptions>): CameraKitSource;\n copy(deviceInfo: Partial<CameraKitDeviceOptions | CameraKitDeviceInfo> = {}): CameraKitSource {\n return new CameraKitSource(this.sourceInfo, this.subscriber, { ...this.deviceInfo, ...deviceInfo });\n }\n\n /**\n * Called by {@link CameraKitSession} when it must remove this source.\n *\n * @param reportError Calling this function will report an error back to the session.\n * @returns\n * @internal\n */\n detach(reportError: (error: Error) => void): void | Promise<void> {\n if (!this.lensCore) return Promise.reject(createNotAttachedError(\"Cannot detach\"));\n if (this.subscriber.onDetach) return this.subscriber.onDetach(reportError);\n }\n\n /**\n * Set the resolution used to render this source.\n *\n * It’s important to distinguish render size from display size. The size at which the output canvases are displayed\n * on a web page is determined by the CSS of the page. It is distinct from the size at which LensCore renders\n * Lenses. Performance is dominated by render size, while any display scaling can most often be thought of as free.\n *\n * If greater performance is required, a smaller render size may boost frame-rate. It does come at a cost, including\n * loss of accuracy in various tracking and computer-vision algorithms (since they'll be operating on fewer pixels).\n *\n * The size of the Live and Capture {@link RenderTarget} is always the same.\n *\n * @todo Currently it's only valid to call `setRenderSize` after `CameraKitSession.play` has been called. This\n * constraint should be removed, so callers don't have to understand the underlying LensCore state machine.\n *\n * @param width pixels\n * @param height pixels\n * @returns Promise resolves when the render size has been successfully updated.\n */\n @validate\n setRenderSize(width: number, height: number): Promise<void> {\n if (!this.lensCore) return Promise.reject(createNotAttachedError(\"Cannot setRenderSize\"));\n const target = { width, height };\n return this.lensCore.setRenderSize({ mode: \"explicit\", target });\n }\n\n /**\n * Apply a 2D transformation to the source (e.g. translation, rotation, scale).\n *\n * @param transform Specifies the 3x3 matrix describing the transformation.\n */\n @validate\n setTransform(transform: Transform2D): Promise<void> {\n if (!this.lensCore) return Promise.reject(createNotAttachedError(\"Cannot setTransform\"));\n const matrix = new Float32Array(transform.matrix);\n return this.lensCore.setInputTransform({ matrix });\n }\n}\n"]}
|