@snap/camera-kit 0.14.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +5921 -1485
- package/README.md +1 -1
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/CameraKit.html +7 -7
- package/docs/html/classes/CameraKitSession.html +17 -25
- package/docs/html/classes/CameraKitSource.html +15 -10
- package/docs/html/classes/LensPerformanceMeasurement.html +7 -7
- package/docs/html/classes/LensPerformanceMetrics.html +7 -7
- package/docs/html/classes/LensRepository.html +7 -7
- package/docs/html/classes/Transform2D.html +7 -7
- package/docs/html/classes/TypedCustomEvent.html +7 -7
- package/docs/html/classes/TypedEventTarget.html +7 -7
- package/docs/html/functions/ConcatInjectable.html +202 -0
- package/docs/html/functions/Injectable.html +15 -16
- package/docs/html/functions/bootstrapCameraKit.html +7 -7
- package/docs/html/functions/createExtension.html +7 -7
- package/docs/html/functions/createImageSource.html +7 -7
- package/docs/html/functions/createMediaStreamSource.html +7 -7
- package/docs/html/functions/createUserMediaSource.html +7 -7
- package/docs/html/functions/createVideoSource.html +7 -7
- package/docs/html/functions/estimateLensPerformance.html +7 -7
- package/docs/html/functions/getRequiredBootstrapURLs.html +7 -7
- package/docs/html/functions/lensSourcesFactory.html +17 -9
- package/docs/html/functions/remoteApiServicesFactory.html +7 -7
- package/docs/html/index.html +9 -9
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +7 -7
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +7 -7
- package/docs/html/interfaces/ComputedFrameMetrics.html +7 -7
- package/docs/html/interfaces/CreateSessionOptions.html +7 -7
- package/docs/html/interfaces/EstimatedLensPerformance.html +7 -7
- package/docs/html/interfaces/Lens.html +7 -7
- package/docs/html/interfaces/LensLaunchData.html +183 -0
- package/docs/html/interfaces/LensSource.html +28 -46
- package/docs/html/interfaces/MediaStreamSourceOptions.html +7 -7
- package/docs/html/interfaces/Preview.html +7 -7
- package/docs/html/interfaces/RemoteApiRequest.html +7 -7
- package/docs/html/interfaces/RemoteApiResponse.html +7 -7
- package/docs/html/interfaces/RemoteApiService.html +7 -7
- package/docs/html/interfaces/Snapcode.html +7 -7
- package/docs/html/interfaces/UriCancelRequest.html +7 -7
- package/docs/html/interfaces/UriRequest.html +7 -7
- package/docs/html/interfaces/UriResponse.html +7 -7
- package/docs/html/interfaces/VideoSourceOptions.html +7 -7
- package/docs/html/modules.html +12 -12
- package/docs/html/types/AssetLoader.html +7 -7
- package/docs/html/types/AssetTiming.html +7 -7
- package/docs/html/types/BenchmarkError.html +7 -7
- package/docs/html/types/BootstrapError.html +7 -7
- package/docs/html/types/CacheKeyNotFoundError.html +7 -7
- package/docs/html/types/CameraKitDeviceInfo.html +7 -7
- package/docs/html/types/CameraKitDeviceOptions.html +7 -7
- package/docs/html/types/CameraKitSessionEventListener.html +7 -7
- package/docs/html/types/CameraKitSessionEvents.html +7 -7
- package/docs/html/types/CameraKitSourceError.html +7 -7
- package/docs/html/types/CameraKitSourceInfo.html +7 -7
- package/docs/html/types/CameraKitSourceOptions.html +7 -7
- package/docs/html/types/ConfigurationError.html +7 -7
- package/docs/html/types/Keyboard.html +7 -7
- package/docs/html/types/KeyboardEvents.html +7 -7
- package/docs/html/types/LegalError.html +7 -7
- package/docs/html/types/LensAbortError.html +7 -7
- package/docs/html/types/LensAssetError.html +7 -7
- package/docs/html/types/LensContentValidationError.html +7 -7
- package/docs/html/types/LensError.html +7 -7
- package/docs/html/types/LensExecutionError.html +7 -7
- package/docs/html/types/LensImagePickerError.html +7 -7
- package/docs/html/types/LensMetricsEvents.html +7 -7
- package/docs/html/types/LensPerformanceCluster.html +7 -7
- package/docs/html/types/LensView.html +7 -7
- package/docs/html/types/LensWait.html +7 -7
- package/docs/html/types/PersistentStoreError.html +7 -7
- package/docs/html/types/PlatformNotSupportedError.html +7 -7
- package/docs/html/types/PublicContainer.html +7 -7
- package/docs/html/types/RemoteApiRequestHandler.html +7 -7
- package/docs/html/types/RemoteApiServices.html +7 -7
- package/docs/html/types/RemoteApiStatus.html +7 -7
- package/docs/html/types/RenderTarget.html +7 -7
- package/docs/html/types/Uri.html +7 -7
- package/docs/html/types/WebGLError.html +7 -7
- package/docs/html/variables/extensionRequestContext.html +7 -7
- package/docs/md/README.md +1 -1
- package/docs/md/classes/CameraKit.md +1 -1
- package/docs/md/classes/CameraKitSession.md +11 -22
- package/docs/md/classes/CameraKitSource.md +11 -5
- package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
- package/docs/md/classes/LensPerformanceMetrics.md +1 -1
- package/docs/md/classes/LensRepository.md +1 -1
- package/docs/md/classes/Transform2D.md +1 -1
- package/docs/md/classes/TypedCustomEvent.md +1 -1
- package/docs/md/classes/TypedEventTarget.md +1 -1
- package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +1 -1
- package/docs/md/interfaces/CameraKitSourceSubscriber.md +1 -1
- package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
- package/docs/md/interfaces/CreateSessionOptions.md +1 -1
- package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
- package/docs/md/interfaces/Lens.md +1 -1
- package/docs/md/interfaces/LensLaunchData.md +53 -0
- package/docs/md/interfaces/LensSource.md +23 -25
- 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 +125 -28
- package/lib/CameraKit.d.ts +14 -6
- package/lib/__tests__/data.d.ts +2 -2
- package/lib/__tests__/data.js +2 -2
- package/lib/__tests__/data.js.map +1 -1
- package/lib/bootstrapCameraKit.js +12 -3
- package/lib/bootstrapCameraKit.js.map +1 -1
- package/lib/clients/createTsProtoClient.d.ts +47 -0
- package/lib/clients/createTsProtoClient.js +53 -0
- package/lib/clients/createTsProtoClient.js.map +1 -0
- package/lib/clients/grpcHandler.d.ts +23 -0
- package/lib/clients/grpcHandler.js +87 -0
- package/lib/clients/grpcHandler.js.map +1 -0
- package/lib/clients/lensesClient.d.ts +9 -0
- package/lib/clients/lensesClient.js +6 -0
- package/lib/clients/lensesClient.js.map +1 -0
- package/lib/common/entries.d.ts +1 -0
- package/lib/common/entries.js +2 -0
- package/lib/common/entries.js.map +1 -1
- package/lib/common/result.d.ts +36 -0
- package/lib/common/result.js +40 -0
- package/lib/common/result.js.map +1 -0
- package/lib/common/unionBy.d.ts +28 -0
- package/lib/common/unionBy.js +46 -0
- package/lib/common/unionBy.js.map +1 -0
- package/lib/configuration.js +14 -1
- package/lib/configuration.js.map +1 -1
- package/lib/dependency-injection/Injectable.d.ts +67 -11
- package/lib/dependency-injection/Injectable.js +21 -2
- package/lib/dependency-injection/Injectable.js.map +1 -1
- package/lib/dependency-injection/RootServices.d.ts +5 -1
- package/lib/dependency-injection/RootServices.js.map +1 -1
- package/lib/environment.json +1 -1
- package/lib/extensions/RemoteApiServices.d.ts +1 -1
- package/lib/extensions/RemoteApiServices.js +7 -7
- package/lib/extensions/RemoteApiServices.js.map +1 -1
- package/lib/extensions/uriHandlersRegister.d.ts +6 -6
- package/lib/extensions/uriHandlersRegister.js +1 -1
- package/lib/extensions/uriHandlersRegister.js.map +1 -1
- package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +15 -17
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +62 -69
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +6 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +68 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +5 -6
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +11 -25
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +19 -14
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +145 -64
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +2 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +30 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +15 -16
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +36 -62
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +1294 -12
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +200 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +4 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +39 -45
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +74 -192
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -1
- package/lib/handlers/defaultFetchHandler.js +1 -5
- package/lib/handlers/defaultFetchHandler.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -6
- package/lib/index.js.map +1 -1
- package/lib/lens/Lens.d.ts +2 -12
- package/lib/lens/Lens.js +2 -2
- package/lib/lens/Lens.js.map +1 -1
- package/lib/lens/LensLaunchData.d.ts +37 -0
- package/lib/lens/LensLaunchData.js +35 -0
- package/lib/lens/LensLaunchData.js.map +1 -0
- package/lib/lens/LensRepository.d.ts +4 -7
- package/lib/lens/LensRepository.js +24 -35
- package/lib/lens/LensRepository.js.map +1 -1
- package/lib/lens/LensSource.d.ts +43 -0
- package/lib/lens/LensSource.js +42 -0
- package/lib/lens/LensSource.js.map +1 -0
- package/lib/lens/assets/LensAssetRepository.js +2 -4
- package/lib/lens/assets/LensAssetRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetsProvider.d.ts +1 -1
- package/lib/lens/cameraKitLensSource.d.ts +16 -0
- package/lib/lens/cameraKitLensSource.js +59 -0
- package/lib/lens/cameraKitLensSource.js.map +1 -0
- package/lib/lens-core-module/lensCore.d.ts +2 -1
- package/lib/lens-core-module/lensCore.js +6 -1
- package/lib/lens-core-module/lensCore.js.map +1 -1
- package/lib/lens-core-module/lensCoreError.js +1 -1
- package/lib/lens-core-module/lensCoreError.js.map +1 -1
- package/lib/lensCoreWasmVersions.json +3 -3
- package/lib/media-sources/CameraKitSource.d.ts +10 -4
- package/lib/media-sources/CameraKitSource.js +11 -4
- package/lib/media-sources/CameraKitSource.js.map +1 -1
- package/lib/media-sources/ImageSource.js +1 -11
- package/lib/media-sources/ImageSource.js.map +1 -1
- package/lib/media-sources/MediaStreamSource.js +1 -5
- package/lib/media-sources/MediaStreamSource.js.map +1 -1
- package/lib/media-sources/VideoSource.js +1 -11
- package/lib/media-sources/VideoSource.js.map +1 -1
- package/lib/metrics/businessEventsReporter.js +1 -1
- package/lib/metrics/businessEventsReporter.js.map +1 -1
- package/lib/metrics/reporters/reportGlobalException.d.ts +7 -0
- package/lib/metrics/reporters/reportGlobalException.js +22 -4
- package/lib/metrics/reporters/reportGlobalException.js.map +1 -1
- package/lib/metrics/reporters/reportHttpMetrics.js +14 -0
- package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
- package/lib/metrics/reporters/reportLensValidationFailed.d.ts +1 -1
- package/lib/metrics/reporters/reportLensView.d.ts +1 -1
- package/lib/metrics/reporters/reportLensWait.d.ts +1 -1
- package/lib/metrics/reporters/reportSessionException.d.ts +1 -1
- package/lib/metrics/reporters/reporters.d.ts +1 -1
- package/lib/persistence/ExpiringPersistence.js +3 -4
- package/lib/persistence/ExpiringPersistence.js.map +1 -1
- package/lib/platform/platformInfo.js +1 -1
- package/lib/platform/platformInfo.js.map +1 -1
- package/lib/remote-configuration/cofHandler.d.ts +1 -0
- package/lib/remote-configuration/cofHandler.js +61 -50
- package/lib/remote-configuration/cofHandler.js.map +1 -1
- package/lib/session/CameraKitSession.d.ts +9 -11
- package/lib/session/CameraKitSession.js +22 -18
- package/lib/session/CameraKitSession.js.map +1 -1
- package/lib/session/CameraKitSessionEvents.d.ts +1 -1
- package/lib/session/CameraKitSessionEvents.js.map +1 -1
- package/lib/session/LensKeyboard.d.ts +7 -1
- package/lib/session/lensState.d.ts +3 -3
- package/lib/session/lensState.js +40 -15
- package/lib/session/lensState.js.map +1 -1
- package/package.json +2 -2
- package/docs/html/classes/LensSources.html +0 -160
- package/docs/html/types/LensLaunchParams.html +0 -115
- package/docs/md/classes/LensSources.md +0 -29
- package/lib/common/any.d.ts +0 -19
- package/lib/common/any.js +0 -53
- package/lib/common/any.js.map +0 -1
- package/lib/extensions/LensSources.d.ts +0 -58
- package/lib/extensions/LensSources.js +0 -54
- package/lib/extensions/LensSources.js.map +0 -1
- package/lib/lens/LensLaunchParams.d.ts +0 -19
- package/lib/lens/LensLaunchParams.js +0 -40
- package/lib/lens/LensLaunchParams.js.map +0 -1
- package/lib/lens/index.d.ts +0 -7
- package/lib/lens/index.js +0 -7
- package/lib/lens/index.js.map +0 -1
- package/lib/lens/lensEnvelopeUtil.d.ts +0 -5
- package/lib/lens/lensEnvelopeUtil.js +0 -19
- package/lib/lens/lensEnvelopeUtil.js.map +0 -1
- package/lib/lens/lensHttpUtil.d.ts +0 -5
- package/lib/lens/lensHttpUtil.js +0 -52
- package/lib/lens/lensHttpUtil.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaStreamSource.js","sourceRoot":"","sources":["../../src/media-sources/MediaStreamSource.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAE5E,MAAM,cAAc,GAA6B;IAC7C,SAAS,EAAE,WAAW,CAAC,QAAQ;IAC/B,kBAAkB,EAAE,KAAK;CAC5B,CAAC;AAEF,SAAS,YAAY,CAAC,OAAqC;IACvD,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,UAAU,EAAE,CAAC;AACzB,CAAC;AAED,SAAe,iBAAiB,CAAC,YAAsC;;QACnE,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,KAAK,KAAK,QAAQ;YAAE,OAAO;QAC7D,OAAO,YAAY,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CAAA;AAQD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAgB,qBAAqB,CACvC,cAAsC,EAAE,KAAK,EAAE,IAAI,EAAE,EACrD,UAA4D,EAAE;;QAE9D,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QACtE,OAAO,uBAAuB,CAAC,MAAM,kBAAI,SAAS,EAAE,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,IAAK,OAAO,EAAG,CAAC;IAChH,CAAC;CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAA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EAAE;gBACb,WAAW,CAAC,UAAU,EAAE,CAAC;gBACzB,WAAW,GAAG,SAAS,CAAC;aAC3B;YACD,IAAI,YAAY,EAAE;gBACd,MAAM,iBAAiB,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;gBACzD,YAAY,GAAG,SAAS,CAAC;aAC5B;QACL,CAAC,CAAA;KACJ,EACD,mBAAmB,CACtB,CAAC;AACN,CAAC","sourcesContent":["import { ensureError } from \"../common/errorHelpers\";\nimport { Transform2D } from \"../transforms\";\nimport { CameraKitSource, CameraKitSourceOptions } from \"./CameraKitSource\";\n\nconst defaultOptions: MediaStreamSourceOptions = {\n transform: Transform2D.Identity,\n disableSourceAudio: false,\n};\n\nfunction closeWorklet(worklet: AudioWorkletNode | undefined) {\n if (!worklet) return;\n worklet.port.close();\n worklet.port.onmessage = null;\n worklet.disconnect();\n}\n\nasync function closeAudioContext(audioContext: AudioContext | undefined) {\n if (!audioContext || audioContext.state === \"closed\") return;\n return audioContext.close();\n}\n\n/** @category Rendering */\nexport interface MediaStreamSourceOptions {\n transform: Transform2D;\n disableSourceAudio: boolean; // defaults to false\n}\n\n/**\n * Create a {@link CameraKitSource} from a user's media device -- this calls\n * [MediaDevices.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) to get a\n * MediaStream and then calls {@link createMediaStreamSource}.\n *\n * @param constraints Specify contraints used to get a MediaStream from a media device. By default we simply request\n * a video stream.\n * @param options\n * @param options.transform By default we horizontally mirror the video stream. The most common use-case is to obtain a\n * stream from a front-facing web cam, which requires mirroring to be viewed naturally.\n * @param options.cameraType By default we set this to 'front' to indicate a camera pointed at the user (e.g. a webcam).\n * @param options.fpsLimit By default we set no limit on FPS – if the source device has a known FPS setting this limit\n * may prevent CameraKit from using more compute resources than strictly necessary.\n * @returns A Promise, resolving to {@link CameraKitSource}\n *\n * @category Rendering\n *\n * @deprecated The helper will be removed in one of the future releases.\n * Consumer apps are responsible for acquiring a media stream,\n * which can then be supplied to {@link createMediaStreamSource}.\n */\nexport async function createUserMediaSource(\n constraints: MediaStreamConstraints = { video: true },\n options: CameraKitSourceOptions<MediaStreamSourceOptions> = {}\n): Promise<CameraKitSource> {\n const stream = await navigator.mediaDevices.getUserMedia(constraints);\n return createMediaStreamSource(stream, { transform: Transform2D.MirrorX, cameraType: \"front\", ...options });\n}\n\n/**\n * Create a {@link CameraKitSource} from any\n * [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).\n *\n * @param stream Any MediaStream, such as obtained via `canvas.captureStream()` or `mediaDevices.getUserMedia()`.\n * @param options\n * @param options.transform We apply no transformation by default.\n * @param options.disableSourceAudio By default we pass audio to lens. Settings this to true will disable sending audio\n * to the lens.\n * @param options.cameraType By default we set this to 'user', which is the camera type most Lenses expect.\n * @param options.fpsLimit By default we set no limit on FPS – if the MediaStream has a known FPS setting this limit\n * may prevent CameraKit from using more compute resources than strictly necessary.\n *\n * @category Rendering\n */\nexport function createMediaStreamSource(\n stream: MediaStream,\n options: CameraKitSourceOptions<MediaStreamSourceOptions> = {}\n): CameraKitSource {\n const { width, height, facingMode } =\n stream.getVideoTracks().length > 0\n ? stream.getVideoTracks()[0].getSettings()\n : { width: 0, height: 0, facingMode: undefined };\n\n const detectedCameraType = facingMode === \"user\" || facingMode === \"environment\" ? facingMode : undefined;\n\n const optionsWithDefaults = {\n ...defaultOptions,\n ...options,\n cameraType: options.cameraType ?? detectedCameraType,\n };\n\n const enableSourceAudio: boolean = stream.getAudioTracks().length > 0 && !optionsWithDefaults.disableSourceAudio;\n\n const simulateStereoAudio = true;\n const sampleRate: number = 44100;\n\n let audioContext: AudioContext | undefined = undefined;\n let audioSource: MediaStreamAudioSourceNode | undefined = undefined;\n let worklet: AudioWorkletNode | undefined = undefined;\n let microphoneRecorderUrl: string;\n\n if (enableSourceAudio) {\n // https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_AudioWorklet\n const microphoneRecorderWorklet = `\n class MicrophoneWorkletProcessor extends AudioWorkletProcessor {\n process(inputs, outputs, parameters) {\n this.port.postMessage({\n eventType: 'data',\n buffer: inputs\n });\n return true;\n }\n }\n registerProcessor('microphone-worklet', MicrophoneWorkletProcessor);`;\n const microphoneRecorderBlob = new Blob([microphoneRecorderWorklet], {\n type: \"application/javascript\",\n });\n microphoneRecorderUrl = URL.createObjectURL(microphoneRecorderBlob);\n }\n\n return new CameraKitSource(\n { media: stream },\n {\n onAttach: async (source, lensCore, reportError) => {\n if (width !== undefined && height !== undefined) await source.setRenderSize(width, height);\n await source.setTransform(optionsWithDefaults.transform);\n\n if (enableSourceAudio) {\n // Audio paramters set has to be called before lens is applied\n await lensCore.setAudioParameters({\n parameters: {\n numChannels: simulateStereoAudio ? 2 : 1,\n sampleRate,\n },\n });\n\n try {\n // There is a possibility of the onAttach method being called twice in a row due to a bug.\n // To ensure there are not leaks, it is better to close any existing connections.\n closeWorklet(worklet);\n audioSource?.disconnect();\n await closeAudioContext(audioContext);\n } catch (error) {\n // We still want to continue if anything above failed\n reportError(ensureError(error));\n }\n\n audioContext = new AudioContext();\n audioSource = audioContext.createMediaStreamSource(stream);\n const scopedAudioSource = audioSource;\n audioContext.audioWorklet\n .addModule(microphoneRecorderUrl)\n .then(() => {\n if (audioContext) {\n worklet = new AudioWorkletNode(audioContext, \"microphone-worklet\");\n scopedAudioSource.connect(worklet);\n worklet.connect(audioContext.destination);\n // NOTE: We subscribe to messages here, and they will continue to arrive\n // even after audioContext.close() is called. To disconnect the audio worklets\n // created here, we need to track two variables - worklet and audioSource.\n // By calling disconnect() on them, we can properly\n // disconnect the audio worklets.\n worklet.port.onmessage = (e) => {\n if (e.data.eventType === \"data\") {\n // developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor/process\n // inputs[n][m] is the list of samples in the n-th input at the m-th channel.\n const leftSamples = e.data.buffer[0][0] as Float32Array;\n\n // Firefox might have leftSamples undefined:\n // https://jira.sc-corp.net/browse/CAMKIT-5189\n if (!leftSamples) return;\n\n let inputBuffers = [leftSamples];\n if (simulateStereoAudio) {\n const rightSamples =\n e.data.buffer[0].length > 1 ? e.data.buffer[0][1] : leftSamples.slice();\n inputBuffers.push(rightSamples);\n }\n\n lensCore.processAudioSampleBuffer({ input: inputBuffers }).catch(reportError);\n }\n };\n }\n })\n .catch((error: Error) => {\n reportError(error);\n });\n }\n },\n onDetach: async (reportError) => {\n if (worklet) {\n closeWorklet(worklet);\n worklet = undefined;\n }\n if (audioSource) {\n audioSource.disconnect();\n audioSource = undefined;\n }\n if (audioContext) {\n await closeAudioContext(audioContext).catch(reportError);\n audioContext = undefined;\n }\n },\n },\n optionsWithDefaults\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MediaStreamSource.js","sourceRoot":"","sources":["../../src/media-sources/MediaStreamSource.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAE5E,MAAM,cAAc,GAA6B;IAC7C,SAAS,EAAE,WAAW,CAAC,QAAQ;IAC/B,kBAAkB,EAAE,KAAK;CAC5B,CAAC;AAEF,SAAS,YAAY,CAAC,OAAqC;IACvD,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,UAAU,EAAE,CAAC;AACzB,CAAC;AAED,SAAe,iBAAiB,CAAC,YAAsC;;QACnE,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,KAAK,KAAK,QAAQ;YAAE,OAAO;QAC7D,OAAO,YAAY,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CAAA;AAQD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAgB,qBAAqB,CACvC,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EAAE;YAC5B,IAAI,OAAO,EAAE;gBACT,YAAY,CAAC,OAAO,CAAC,CAAC;gBACtB,OAAO,GAAG,SAAS,CAAC;aACvB;YACD,IAAI,WAAW,EAAE;gBACb,WAAW,CAAC,UAAU,EAAE,CAAC;gBACzB,WAAW,GAAG,SAAS,CAAC;aAC3B;YACD,IAAI,YAAY,EAAE;gBACd,MAAM,iBAAiB,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;gBACzD,YAAY,GAAG,SAAS,CAAC;aAC5B;QACL,CAAC,CAAA;KACJ,EACD,mBAAmB,CACtB,CAAC;AACN,CAAC","sourcesContent":["import { ensureError } from \"../common/errorHelpers\";\nimport { Transform2D } from \"../transforms\";\nimport { CameraKitSource, CameraKitSourceOptions } from \"./CameraKitSource\";\n\nconst defaultOptions: MediaStreamSourceOptions = {\n transform: Transform2D.Identity,\n disableSourceAudio: false,\n};\n\nfunction closeWorklet(worklet: AudioWorkletNode | undefined) {\n if (!worklet) return;\n worklet.port.close();\n worklet.port.onmessage = null;\n worklet.disconnect();\n}\n\nasync function closeAudioContext(audioContext: AudioContext | undefined) {\n if (!audioContext || audioContext.state === \"closed\") return;\n return audioContext.close();\n}\n\n/** @category Rendering */\nexport interface MediaStreamSourceOptions {\n transform: Transform2D;\n disableSourceAudio: boolean; // defaults to false\n}\n\n/**\n * Create a {@link CameraKitSource} from a user's media device -- this calls\n * [MediaDevices.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) to get a\n * MediaStream and then calls {@link createMediaStreamSource}.\n *\n * @param constraints Specify contraints used to get a MediaStream from a media device. By default we simply request\n * a video stream.\n * @param options\n * @param options.transform By default we horizontally mirror the video stream. The most common use-case is to obtain a\n * stream from a front-facing web cam, which requires mirroring to be viewed naturally.\n * @param options.cameraType By default we set this to 'front' to indicate a camera pointed at the user (e.g. a webcam).\n * @param options.fpsLimit By default we set no limit on FPS – if the source device has a known FPS setting this limit\n * may prevent CameraKit from using more compute resources than strictly necessary.\n * @returns A Promise, resolving to {@link CameraKitSource}\n *\n * @category Rendering\n *\n * @deprecated The helper will be removed in one of the future releases.\n * Consumer apps are responsible for acquiring a media stream,\n * which can then be supplied to {@link createMediaStreamSource}.\n */\nexport async function createUserMediaSource(\n constraints: MediaStreamConstraints = { video: true },\n options: CameraKitSourceOptions<MediaStreamSourceOptions> = {}\n): Promise<CameraKitSource> {\n const stream = await navigator.mediaDevices.getUserMedia(constraints);\n return createMediaStreamSource(stream, { transform: Transform2D.MirrorX, cameraType: \"front\", ...options });\n}\n\n/**\n * Create a {@link CameraKitSource} from any\n * [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).\n *\n * @param stream Any MediaStream, such as obtained via `canvas.captureStream()` or `mediaDevices.getUserMedia()`.\n * @param options\n * @param options.transform We apply no transformation by default.\n * @param options.disableSourceAudio By default we pass audio to lens. Settings this to true will disable sending audio\n * to the lens.\n * @param options.cameraType By default we set this to 'user', which is the camera type most Lenses expect.\n * @param options.fpsLimit By default we set no limit on FPS – if the MediaStream has a known FPS setting this limit\n * may prevent CameraKit from using more compute resources than strictly necessary.\n *\n * @category Rendering\n */\nexport function createMediaStreamSource(\n stream: MediaStream,\n options: CameraKitSourceOptions<MediaStreamSourceOptions> = {}\n): CameraKitSource {\n const { facingMode } =\n stream.getVideoTracks().length > 0 ? stream.getVideoTracks()[0].getSettings() : { facingMode: undefined };\n\n const detectedCameraType = facingMode === \"user\" || facingMode === \"environment\" ? facingMode : undefined;\n\n const optionsWithDefaults = {\n ...defaultOptions,\n ...options,\n cameraType: options.cameraType ?? detectedCameraType,\n };\n\n const enableSourceAudio: boolean = stream.getAudioTracks().length > 0 && !optionsWithDefaults.disableSourceAudio;\n\n const simulateStereoAudio = true;\n const sampleRate: number = 44100;\n\n let audioContext: AudioContext | undefined = undefined;\n let audioSource: MediaStreamAudioSourceNode | undefined = undefined;\n let worklet: AudioWorkletNode | undefined = undefined;\n let microphoneRecorderUrl: string;\n\n if (enableSourceAudio) {\n // https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_AudioWorklet\n const microphoneRecorderWorklet = `\n class MicrophoneWorkletProcessor extends AudioWorkletProcessor {\n process(inputs, outputs, parameters) {\n this.port.postMessage({\n eventType: 'data',\n buffer: inputs\n });\n return true;\n }\n }\n registerProcessor('microphone-worklet', MicrophoneWorkletProcessor);`;\n const microphoneRecorderBlob = new Blob([microphoneRecorderWorklet], {\n type: \"application/javascript\",\n });\n microphoneRecorderUrl = URL.createObjectURL(microphoneRecorderBlob);\n }\n\n return new CameraKitSource(\n { media: stream },\n {\n onAttach: async (source, lensCore, reportError) => {\n await source.setTransform(optionsWithDefaults.transform);\n\n if (enableSourceAudio) {\n // Audio paramters set has to be called before lens is applied\n await lensCore.setAudioParameters({\n parameters: {\n numChannels: simulateStereoAudio ? 2 : 1,\n sampleRate,\n },\n });\n\n try {\n // There is a possibility of the onAttach method being called twice in a row due to a bug.\n // To ensure there are not leaks, it is better to close any existing connections.\n closeWorklet(worklet);\n audioSource?.disconnect();\n await closeAudioContext(audioContext);\n } catch (error) {\n // We still want to continue if anything above failed\n reportError(ensureError(error));\n }\n\n audioContext = new AudioContext();\n audioSource = audioContext.createMediaStreamSource(stream);\n const scopedAudioSource = audioSource;\n audioContext.audioWorklet\n .addModule(microphoneRecorderUrl)\n .then(() => {\n if (audioContext) {\n worklet = new AudioWorkletNode(audioContext, \"microphone-worklet\");\n scopedAudioSource.connect(worklet);\n worklet.connect(audioContext.destination);\n // NOTE: We subscribe to messages here, and they will continue to arrive\n // even after audioContext.close() is called. To disconnect the audio worklets\n // created here, we need to track two variables - worklet and audioSource.\n // By calling disconnect() on them, we can properly\n // disconnect the audio worklets.\n worklet.port.onmessage = (e) => {\n if (e.data.eventType === \"data\") {\n // developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor/process\n // inputs[n][m] is the list of samples in the n-th input at the m-th channel.\n const leftSamples = e.data.buffer[0][0] as Float32Array;\n\n // Firefox might have leftSamples undefined:\n // https://jira.sc-corp.net/browse/CAMKIT-5189\n if (!leftSamples) return;\n\n let inputBuffers = [leftSamples];\n if (simulateStereoAudio) {\n const rightSamples =\n e.data.buffer[0].length > 1 ? e.data.buffer[0][1] : leftSamples.slice();\n inputBuffers.push(rightSamples);\n }\n\n lensCore.processAudioSampleBuffer({ input: inputBuffers }).catch(reportError);\n }\n };\n }\n })\n .catch((error: Error) => {\n reportError(error);\n });\n }\n },\n onDetach: async (reportError) => {\n if (worklet) {\n closeWorklet(worklet);\n worklet = undefined;\n }\n if (audioSource) {\n audioSource.disconnect();\n audioSource = undefined;\n }\n if (audioContext) {\n await closeAudioContext(audioContext).catch(reportError);\n audioContext = undefined;\n }\n },\n },\n optionsWithDefaults\n );\n}\n"]}
|
|
@@ -23,16 +23,6 @@ export function createVideoSource(video, options = {}) {
|
|
|
23
23
|
return new CameraKitSource({
|
|
24
24
|
media: video,
|
|
25
25
|
replayTrackingData,
|
|
26
|
-
}, {
|
|
27
|
-
onAttach: (source) => {
|
|
28
|
-
// If the video element has no explicit width/height (which may be the case for elements that have not
|
|
29
|
-
// been added to the DOM or had their size set explicitly), we'll render at the video's native
|
|
30
|
-
// resolution.
|
|
31
|
-
const [width, height] = video.width === 0 || video.height === 0
|
|
32
|
-
? [video.videoWidth, video.videoHeight]
|
|
33
|
-
: [video.width, video.height];
|
|
34
|
-
return source.setRenderSize(width, height);
|
|
35
|
-
},
|
|
36
|
-
}, options);
|
|
26
|
+
}, {}, options);
|
|
37
27
|
}
|
|
38
28
|
//# sourceMappingURL=VideoSource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VideoSource.js","sourceRoot":"","sources":["../../src/media-sources/VideoSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAE5E,MAAM,cAAc,GAAuB;IACvC,YAAY,EAAE,IAAI,WAAW,CAAC,CAAC,CAAC;CACnC,CAAC;AAOF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAC7B,KAAuB,EACvB,UAAsD,EAAE;IAExD,MAAM,EAAE,YAAY,EAAE,mCAAQ,cAAc,GAAK,OAAO,CAAE,CAAC;IAC3D,MAAM,kBAAkB,GAAG,YAAY,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9F,OAAO,IAAI,eAAe,CACtB;QACI,KAAK,EAAE,KAAK;QACZ,kBAAkB;KACrB,EACD
|
|
1
|
+
{"version":3,"file":"VideoSource.js","sourceRoot":"","sources":["../../src/media-sources/VideoSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAE5E,MAAM,cAAc,GAAuB;IACvC,YAAY,EAAE,IAAI,WAAW,CAAC,CAAC,CAAC;CACnC,CAAC;AAOF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAC7B,KAAuB,EACvB,UAAsD,EAAE;IAExD,MAAM,EAAE,YAAY,EAAE,mCAAQ,cAAc,GAAK,OAAO,CAAE,CAAC;IAC3D,MAAM,kBAAkB,GAAG,YAAY,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9F,OAAO,IAAI,eAAe,CACtB;QACI,KAAK,EAAE,KAAK;QACZ,kBAAkB;KACrB,EACD,EAAE,EACF,OAAO,CACV,CAAC;AACN,CAAC","sourcesContent":["import { CameraKitSource, CameraKitSourceOptions } from \"./CameraKitSource\";\n\nconst defaultOptions: VideoSourceOptions = {\n trackingData: new ArrayBuffer(0),\n};\n\n/** @category Rendering */\nexport interface VideoSourceOptions {\n trackingData: ArrayBuffer;\n}\n\n/**\n * Create a {@link CameraKitSource} from an\n * [HTMLVideoElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement).\n *\n * @param video CameraKit performs best when the source video is 720p – arbitrary resolutions are supported, but very\n * high resolutions may not perform well.\n * @param options\n * @param options.trackingData If pre-computed tracking data exists for this video, it may be provided in order to boost\n * rendering performance (it is not typical or expected for this to be provided).\n * @param options.cameraType By default we set this to 'user', which is the camera type most Lenses expect.\n * @param options.fpsLimit By default we set no limit on FPS – if the video has a known FPS setting this limit\n * may prevent CameraKit from using more compute resources than strictly necessary.\n *\n * @category Rendering\n */\nexport function createVideoSource(\n video: HTMLVideoElement,\n options: CameraKitSourceOptions<VideoSourceOptions> = {}\n): CameraKitSource {\n const { trackingData } = { ...defaultOptions, ...options };\n const replayTrackingData = trackingData.byteLength > 0 ? { buffer: trackingData } : undefined;\n\n return new CameraKitSource(\n {\n media: video,\n replayTrackingData,\n },\n {},\n options\n );\n}\n"]}
|
|
@@ -149,7 +149,7 @@ function listenAndReport(metricsEventTarget, metricsHandler, pageVisibility, eve
|
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
function getAppVendorAndPartnerUuid(configuration, remoteConfiguration) {
|
|
152
|
-
const vendorAnalyticsPersistence = new ExpiringPersistence(() => vendorUuidExpiry, new IndexedDBPersistence({ databaseName: "
|
|
152
|
+
const vendorAnalyticsPersistence = new ExpiringPersistence(() => vendorUuidExpiry, new IndexedDBPersistence({ databaseName: "VendorAnalytics" }));
|
|
153
153
|
return remoteConfiguration.getInitializationConfig().pipe(take(1), switchMap(({ appVendorUuidOptIn }) => {
|
|
154
154
|
const partnerUuid = configuration.analyticsId;
|
|
155
155
|
if (appVendorUuidOptIn) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"businessEventsReporter.js","sourceRoot":"","sources":["../../src/metrics/businessEventsReporter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAc,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,SAAS,EAAE,G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QAAQ,CAAC,kBAAkB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SACzE;QACD,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACpB,yBAAyB;YACzB,EAAE,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SAC7E;QACD,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACrB,0BAA0B;YAC1B,EAAE,qBAAqB,EAAE,QAAQ,CAAC,qBAAqB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SAC/E;QACD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACjB,2BAA2B;YAC3B,EAAE,qBAAqB,EAAE,QAAQ,CAAC,qBAAqB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SAC/E;QACD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACjB,sBAAsB;YACtB,EAAE,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SACvE;QACD,2BAA2B,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YACpC,2CAA2C;YAC3C;gBACI,oCAAoC,EAChC,QAAQ,CAAC,oCAAoC,CAAC,WAAW,CAAC,KAAK,CAAC;aACvE;SACJ;QACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YAChB,oBAAoB;YACpB,EAAE,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SACrE;KACJ,EACD,aAAa,CAAC,WAAW,EACzB,uBAAuB,CAC1B,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["import { v4 } from \"uuid\";\nimport { Observable, catchError, combineLatestWith, from, fromEvent, map, merge, of, switchMap, take } from \"rxjs\";\nimport { entries } from \"../common/entries\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { EventOfType } from \"../events/TypedCustomEvent\";\nimport { EventsFromTarget } from \"../events/TypedEventTarget\";\nimport { FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { createBatchingHandler } from \"../handlers/batchingHandler\";\nimport { HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport { createMappingHandler } from \"../handlers/mappingHandler\";\nimport * as blizzard from \"../generated-proto/blizzard/cameraKitEvents\";\nimport { getLogger } from \"../logger/logger\";\nimport { PageVisibility, pageVisibilityFactory } from \"../common/pageVisibility\";\nimport { CameraKitApiHostname, CameraKitConfiguration, configurationToken } from \"../configuration\";\nimport { remoteConfigurationFactory, RemoteConfiguration } from \"../remote-configuration/remoteConfiguration\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\nimport { ExpiringPersistence } from \"../persistence/ExpiringPersistence\";\nimport { convertDaysToSeconds } from \"../common/time\";\nimport { ConnectionType, getPlatformInfo } from \"../platform/platformInfo\";\nimport { metricsHandlerFactory } from \"./metricsHandler\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"./metricsEventTarget\";\n\nconst logger = getLogger(\"BusinessEventsReporter\");\n\ntype Nullables<T> = { [K in keyof T]-?: undefined extends T[K] ? K : never }[keyof T];\ntype UndefinedToOptional<T> = Partial<Pick<T, Nullables<T>>> & Omit<T, Nullables<T>>;\n\ntype CameraKitBusinessEvents = EventsFromTarget<MetricsEventTarget>[\"detail\"];\n\ntype MakeBlizzardEvent<E> = Omit<E, \"name\"> & { cameraKitEventBase: blizzard.CameraKitEventBase };\n\ntype CreateEventData<EventType extends EventsFromTarget<MetricsEventTarget>[\"type\"]> = (\n event: MakeBlizzardEvent<EventOfType<EventType, EventsFromTarget<MetricsEventTarget>>[\"detail\"]>\n) => [string, UndefinedToOptional<blizzard.ServerEventData>];\n\ntype EventHandlers = {\n [EventType in EventsFromTarget<MetricsEventTarget>[\"type\"]]: CreateEventData<EventType>;\n};\n\n/**\n * Translate between an external metric name, which is exposed to SDK users, and an internal Blizzard event name,\n * property name, and constructor.\n *\n * It is very important that we do this, since the naming of these internal business events are unintuitive and will\n * not make sense to SDK users.\n *\n * For a full list of business events (using their internal names), see:\n * https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/\n */\ntype CameraKitBusinessEventMap = {\n assetDownload: MakeBusinessEvent<blizzard.CameraKitAssetDownload>;\n assetValidationFailed: MakeBusinessEvent<blizzard.CameraKitAssetValidationFailed>;\n benchmarkComplete: MakeBusinessEvent<blizzard.CameraKitWebBenchmarkComplete>;\n exception: MakeBusinessEvent<blizzard.CameraKitException>;\n legalPrompt: MakeBusinessEvent<blizzard.CameraKitLegalPrompt>;\n lensDownload: MakeBusinessEvent<blizzard.CameraKitLensDownload>;\n lensView: MakeBusinessEvent<blizzard.CameraKitWebLensSwipe>;\n lensWait: MakeBusinessEvent<blizzard.CameraKitLensSpin>;\n lensContentValidationFailed: MakeBusinessEvent<blizzard.CameraKitLensContentValidationFailed>;\n session: MakeBusinessEvent<blizzard.CameraKitSession>;\n};\n\n/**\n * This interface is defined in the CameraKit pb_schema proto definition – but the generated TypeScript does not handle\n * the `Any` type properly. It does not conform to the Proto3 canonical JSON mapping scheme, as defined here:\n * https://developers.google.com/protocol-buffers/docs/proto3#json\n *\n * To solve this (since we only need one message from the CameraKit schema), we'll just manually define the correct\n * interface here.\n */\ninterface SetBusinessEventsRequest {\n batchEvents: {\n \"@type\": \"com.snapchat.analytics.blizzard.ServerEventBatch\";\n serverEvents: blizzard.ServerEvent[];\n };\n}\n\ninterface AppVendorAndPartnerUuid {\n appVendorUuid: string | undefined;\n partnerUuid: string | undefined;\n}\n\n// CameraKit's prod metrics endpoint.\n// See: https://github.sc-corp.net/Snapchat/pb_schema/blob/2a966db/proto/camera_kit/v3/service.proto#L133\nconst relativePath = \"/com.snap.camerakit.v3.Metrics/metrics/business_events\";\n\n// It is rather cumbersome to check the actual final size of a batch, but we can easily limit the number of events we\n// include in each batch -- looking at historical data, typical events average ~1.3kb per event. But there are some\n// events (like CAMERA_KIT_EXCEPTION, which includes a stack trace) that can be much larger.\n//\n// To prevent us running over the 64kibibyte limit imposed by browsers on `keep-alive` requests, we'll set quite a low\n// limit to ensure we don't lose events which are larger in size than we expect.\nconst BUSINESS_EVENT_BATCH_MAX_SIZE = 10;\nconst BUSINESS_EVENT_BATCH_MAX_AGE_MS = 5000;\n\nconst connectivityTypeMapping: Partial<Record<ConnectionType, blizzard.CameraKitConnectivityType>> = {\n cellular: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_MOBILE,\n bluetooth: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_BLUETOOTH,\n wifi: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_WIFI,\n unknown: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_UNKNOWN,\n none: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_UNREACHABLE,\n};\n\nconst vendorUuidKey = \"vendorUuid\";\nconst vendorUuidExpiry = convertDaysToSeconds(60);\n\n/**\n * Retrieves or generates a vendor UUID (Universally Unique Identifier).\n *\n * @param persistence - The persistence storage interface where UUID is stored.\n * @returns {Promise<string | undefined>} - A Promise that resolves to the vendor UUID or undefined,\n * if any failure occurs or opt-in is not enabled.\n */\nconst getOrGenerateVendorUuid = async (persistence: ExpiringPersistence<string>): Promise<string | undefined> => {\n try {\n const storedUuid = await persistence.retrieve(vendorUuidKey);\n if (storedUuid) {\n return storedUuid;\n }\n\n const newUuid = v4();\n await persistence.store(vendorUuidKey, newUuid);\n\n return newUuid;\n } catch (error) {\n throw new Error(\"Failed to generate vendor UUID\");\n }\n};\n\nfunction listenAndReport(\n metricsEventTarget: MetricsEventTarget,\n metricsHandler: FetchHandler,\n pageVisibility: PageVisibility,\n eventHandlers: EventHandlers,\n apiHostname: CameraKitApiHostname,\n appVendorAndPartnerUuid: Observable<AppVendorAndPartnerUuid>\n): void {\n const sessionId = v4();\n logger.log(`Session ID: ${sessionId}`);\n\n // Blizzard convention is to start the sequenceId at 1.\n let sequenceId = 1;\n\n const handler = new HandlerChainBuilder(metricsHandler)\n .map(\n createMappingHandler((events: blizzard.ServerEvent[]) => {\n const body: SetBusinessEventsRequest = {\n batchEvents: {\n \"@type\": \"com.snapchat.analytics.blizzard.ServerEventBatch\",\n serverEvents: events,\n },\n };\n\n return new Request(`https://${apiHostname}${relativePath}`, {\n method: \"POST\",\n body: JSON.stringify(body),\n credentials: \"include\",\n\n // When this is true it makes fetch behave like `Navigator.sendBeacon` – that is, the request\n // will still be made even if the page terminates.\n // https://developer.mozilla.org/en-US/docs/Web/API/fetch\n keepalive: pageVisibility.isDuringVisibilityTransition(\"hidden\"),\n });\n }, pageVisibility)\n )\n .map(\n createBatchingHandler({\n batchReduce: (\n previousBundle: blizzard.ServerEvent[] | undefined,\n businessEvent: blizzard.ServerEvent\n ) => {\n const bundle = previousBundle ?? [];\n bundle.push(businessEvent);\n return bundle;\n },\n isBatchComplete: (bundle) => bundle.length >= BUSINESS_EVENT_BATCH_MAX_SIZE,\n maxBatchAge: BUSINESS_EVENT_BATCH_MAX_AGE_MS,\n pageVisibility,\n })\n ).handler;\n\n const makeBlizzardEvent = <E extends CameraKitBusinessEvents>(\n event: E,\n appVendorUuid: string | undefined,\n partnerUuid: string | undefined\n ): MakeBlizzardEvent<E> => {\n const { sdkShortVersion, sdkLongVersion, lensCore, locale, origin, deviceModel, connectionType } =\n getPlatformInfo();\n\n const deviceConnectivity =\n connectivityTypeMapping[connectionType!] ??\n blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_UNKNOWN;\n\n return {\n ...event,\n cameraKitEventBase: blizzard.CameraKitEventBase.fromPartial({\n kitEventBase: blizzard.KitEventBase.fromPartial({\n locale,\n kitVariant: blizzard.KitType.CAMERA_KIT_WEB,\n kitVariantVersion: sdkShortVersion,\n kitClientTimestampMillis: Date.now(),\n }),\n deviceCluster: 0,\n cameraKitVersion: sdkLongVersion,\n lensCoreVersion: lensCore.version,\n deviceModel,\n cameraKitVariant: blizzard.CameraKitVariant.CAMERA_KIT_VARIANT_PARTNER,\n cameraKitFlavor: blizzard.CameraKitFlavor.CAMERA_KIT_FLAVOR_DEBUG,\n // We overload appId, using the origin instead because it's nice and human-readable (our backed adds\n // the true appId as oauth_client_id before forwarding events to Blizzard).\n appId: origin,\n deviceConnectivity,\n sessionId,\n appVendorUuid,\n partnerUuid,\n }),\n };\n };\n\n const sendServerEvent = (\n eventName: string,\n eventData: UndefinedToOptional<blizzard.ServerEventData>\n ): Promise<void> => {\n const { osName: osType, osVersion } = getPlatformInfo();\n return handler(\n blizzard.ServerEvent.fromPartial({\n eventName,\n osType,\n osVersion,\n maxSequenceIdOnInstance: 0,\n sequenceId: sequenceId++,\n eventData,\n })\n );\n };\n\n // Add event listeners for each event type and turn those listeners into Observables\n const metricsEvents = entries(eventHandlers).map(([eventType, createEventData]) =>\n fromEvent(metricsEventTarget, eventType).pipe(map((event) => ({ event, createEventData })))\n );\n\n // Subscribe to all the metrics events and combine them with the app/partner IDs obtained\n // from remote configuration -- this means we'll queue up any metrics events that occur\n // before remote config is downloaded, and send them once that config is available.\n merge(...metricsEvents)\n .pipe(combineLatestWith(appVendorAndPartnerUuid))\n .subscribe(([{ event, createEventData }, { appVendorUuid, partnerUuid }]) => {\n // Safety: When iterating over object keys in a mapped type, we lose the association between the key type\n // and the value type – at each iteration, the key type is a union of all possible keys and the value type\n // is a union of all possible values. When the value is a function with an argument, and that argument\n // depends on the key type (which is a union), the contravariance of the argument type means that the union\n // becomes an intersection. In our case here, this means the compiler expects each argument to contain all\n // properties from all event types. The cast is safe because the mapped `EventHandlers` type ensures that\n // `createEventData` takes an argument of the type corresponding its key's `eventType`'s event detail.\n const [eventName, eventData] = createEventData(\n makeBlizzardEvent(event.detail, appVendorUuid, partnerUuid) as any\n );\n sendServerEvent(eventName, eventData);\n });\n}\n\nexport type MakeBusinessEvent<E> = Omit<\n {\n [K in keyof E]: Exclude<E[K], undefined> extends Record<keyof any, any>\n ? MakeBusinessEvent<Exclude<E[K], undefined>>\n : E[K];\n },\n \"cameraKitEventBase\"\n>;\n\nfunction getAppVendorAndPartnerUuid(\n configuration: CameraKitConfiguration,\n remoteConfiguration: RemoteConfiguration\n): Observable<AppVendorAndPartnerUuid> {\n const vendorAnalyticsPersistence = new ExpiringPersistence<string>(\n () => vendorUuidExpiry,\n new IndexedDBPersistence({ databaseName: \"SessionHistory\" })\n );\n\n return remoteConfiguration.getInitializationConfig().pipe(\n take(1),\n\n switchMap(({ appVendorUuidOptIn }) => {\n const partnerUuid = configuration.analyticsId;\n if (appVendorUuidOptIn) {\n return from(getOrGenerateVendorUuid(vendorAnalyticsPersistence)).pipe(\n map((appVendorUuid) => ({ appVendorUuid, partnerUuid }))\n );\n }\n return of({ appVendorUuid: undefined, partnerUuid });\n }),\n\n catchError((error) => {\n logger.warn(`Failed to retrieve or generate vendor UUID.`, error);\n return of({ appVendorUuid: undefined, partnerUuid: configuration.analyticsId });\n })\n );\n}\n\nexport type MakeTaggedBusinessEvent<K extends keyof CameraKitBusinessEventMap> = {\n name: K;\n} & CameraKitBusinessEventMap[K];\n\nexport const businessEventsReporterFactory = Injectable(\n \"businessEventsReporter\",\n [\n metricsEventTargetFactory.token,\n metricsHandlerFactory.token,\n pageVisibilityFactory.token,\n configurationToken,\n remoteConfigurationFactory.token,\n ] as const,\n (\n metricsEventTarget: MetricsEventTarget,\n metricsHandler: FetchHandler,\n pageVisibility: PageVisibility,\n configuration: CameraKitConfiguration,\n remoteConfiguration: RemoteConfiguration\n ) => {\n const appVendorAndPartnerUuid = getAppVendorAndPartnerUuid(configuration, remoteConfiguration);\n\n /**\n * This defines a mapping from a business event's external name (the name we document in public\n * API docs), to its internal representation as a Blizzard ServerEvent.\n *\n * It is important that we do this, since the naming of these internal business events are\n * unintuitive and will not make sense to SDK users.\n *\n * To specify the internal event, we must give the ServerEvent's eventName, the specific property\n * name which contains the event data (this is a \"oneof\" property on ServerEvent), and use the\n * correct event type's `fromPartial` method (this is generated from the ServerEvent protobuf).\n *\n * These events are documented here:\n * https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/\n *\n * They are defined in code here:\n * https://github.sc-corp.net/Snapchat/snapchat/tree/master/blizzard/schema/blizzard-schema/\n * codeGen/src/main/java/com/snapchat/analytics/schema/events/cameraKit\n */\n listenAndReport(\n metricsEventTarget,\n metricsHandler,\n pageVisibility,\n {\n assetDownload: (event) => [\n \"CAMERA_KIT_ASSET_DOWNLOAD\",\n { cameraKitAssetDownload: blizzard.CameraKitAssetDownload.fromPartial(event) },\n ],\n assetValidationFailed: (event) => [\n \"CAMERA_KIT_ASSET_VALIDATION_FAILED\",\n {\n cameraKitAssetValidationFailed: blizzard.CameraKitAssetValidationFailed.fromPartial(event),\n },\n ],\n benchmarkComplete: (event) => [\n \"CAMERA_KIT_WEB_BENCHMARK_COMPLETE\",\n {\n cameraKitWebBenchmarkComplete: blizzard.CameraKitWebBenchmarkComplete.fromPartial(event),\n },\n ],\n exception: (event) => [\n \"CAMERA_KIT_EXCEPTION\",\n { cameraKitException: blizzard.CameraKitException.fromPartial(event) },\n ],\n legalPrompt: (event) => [\n \"CAMERA_KIT_LEGAL_PROMPT\",\n { cameraKitLegalPrompt: blizzard.CameraKitLegalPrompt.fromPartial(event) },\n ],\n lensDownload: (event) => [\n \"CAMERA_KIT_LENS_DOWNLOAD\",\n { cameraKitLensDownload: blizzard.CameraKitLensDownload.fromPartial(event) },\n ],\n lensView: (event) => [\n \"CAMERA_KIT_WEB_LENS_SWIPE\",\n { cameraKitWebLensSwipe: blizzard.CameraKitWebLensSwipe.fromPartial(event) },\n ],\n lensWait: (event) => [\n \"CAMERA_KIT_LENS_SPIN\",\n { cameraKitLensSpin: blizzard.CameraKitLensSpin.fromPartial(event) },\n ],\n lensContentValidationFailed: (event) => [\n \"CAMERA_KIT_LENS_CONTENT_VALIDATION_FAILED\",\n {\n cameraKitLensContentValidationFailed:\n blizzard.CameraKitLensContentValidationFailed.fromPartial(event),\n },\n ],\n session: (event) => [\n \"CAMERA_KIT_SESSION\",\n { cameraKitSession: blizzard.CameraKitSession.fromPartial(event) },\n ],\n },\n configuration.apiHostname,\n appVendorAndPartnerUuid\n );\n }\n);\n"]}
|
|
1
|
+
{"version":3,"file":"businessEventsReporter.js","sourceRoot":"","sources":["../../src/metrics/businessEventsReporter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAc,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACnH,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAIhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,QAAQ,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAkB,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAgD,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAuB,MAAM,6CAA6C,CAAC;AAC9G,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAkB,eAAe,E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oC,CAAC,WAAW,CAAC,KAAK,CAAC;aACvE;SACJ;QACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YAChB,oBAAoB;YACpB,EAAE,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;SACrE;KACJ,EACD,aAAa,CAAC,WAAW,EACzB,uBAAuB,CAC1B,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["import { v4 } from \"uuid\";\nimport { Observable, catchError, combineLatestWith, from, fromEvent, map, merge, of, switchMap, take } from \"rxjs\";\nimport { entries } from \"../common/entries\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { EventOfType } from \"../events/TypedCustomEvent\";\nimport { EventsFromTarget } from \"../events/TypedEventTarget\";\nimport { FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { createBatchingHandler } from \"../handlers/batchingHandler\";\nimport { HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport { createMappingHandler } from \"../handlers/mappingHandler\";\nimport * as blizzard from \"../generated-proto/blizzard/cameraKitEvents\";\nimport { getLogger } from \"../logger/logger\";\nimport { PageVisibility, pageVisibilityFactory } from \"../common/pageVisibility\";\nimport { CameraKitApiHostname, CameraKitConfiguration, configurationToken } from \"../configuration\";\nimport { remoteConfigurationFactory, RemoteConfiguration } from \"../remote-configuration/remoteConfiguration\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\nimport { ExpiringPersistence } from \"../persistence/ExpiringPersistence\";\nimport { convertDaysToSeconds } from \"../common/time\";\nimport { ConnectionType, getPlatformInfo } from \"../platform/platformInfo\";\nimport { metricsHandlerFactory } from \"./metricsHandler\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"./metricsEventTarget\";\n\nconst logger = getLogger(\"BusinessEventsReporter\");\n\ntype Nullables<T> = { [K in keyof T]-?: undefined extends T[K] ? K : never }[keyof T];\ntype UndefinedToOptional<T> = Partial<Pick<T, Nullables<T>>> & Omit<T, Nullables<T>>;\n\ntype CameraKitBusinessEvents = EventsFromTarget<MetricsEventTarget>[\"detail\"];\n\ntype MakeBlizzardEvent<E> = Omit<E, \"name\"> & { cameraKitEventBase: blizzard.CameraKitEventBase };\n\ntype CreateEventData<EventType extends EventsFromTarget<MetricsEventTarget>[\"type\"]> = (\n event: MakeBlizzardEvent<EventOfType<EventType, EventsFromTarget<MetricsEventTarget>>[\"detail\"]>\n) => [string, UndefinedToOptional<blizzard.ServerEventData>];\n\ntype EventHandlers = {\n [EventType in EventsFromTarget<MetricsEventTarget>[\"type\"]]: CreateEventData<EventType>;\n};\n\n/**\n * Translate between an external metric name, which is exposed to SDK users, and an internal Blizzard event name,\n * property name, and constructor.\n *\n * It is very important that we do this, since the naming of these internal business events are unintuitive and will\n * not make sense to SDK users.\n *\n * For a full list of business events (using their internal names), see:\n * https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/\n */\ntype CameraKitBusinessEventMap = {\n assetDownload: MakeBusinessEvent<blizzard.CameraKitAssetDownload>;\n assetValidationFailed: MakeBusinessEvent<blizzard.CameraKitAssetValidationFailed>;\n benchmarkComplete: MakeBusinessEvent<blizzard.CameraKitWebBenchmarkComplete>;\n exception: MakeBusinessEvent<blizzard.CameraKitException>;\n legalPrompt: MakeBusinessEvent<blizzard.CameraKitLegalPrompt>;\n lensDownload: MakeBusinessEvent<blizzard.CameraKitLensDownload>;\n lensView: MakeBusinessEvent<blizzard.CameraKitWebLensSwipe>;\n lensWait: MakeBusinessEvent<blizzard.CameraKitLensSpin>;\n lensContentValidationFailed: MakeBusinessEvent<blizzard.CameraKitLensContentValidationFailed>;\n session: MakeBusinessEvent<blizzard.CameraKitSession>;\n};\n\n/**\n * This interface is defined in the CameraKit pb_schema proto definition – but the generated TypeScript does not handle\n * the `Any` type properly. It does not conform to the Proto3 canonical JSON mapping scheme, as defined here:\n * https://developers.google.com/protocol-buffers/docs/proto3#json\n *\n * To solve this (since we only need one message from the CameraKit schema), we'll just manually define the correct\n * interface here.\n */\ninterface SetBusinessEventsRequest {\n batchEvents: {\n \"@type\": \"com.snapchat.analytics.blizzard.ServerEventBatch\";\n serverEvents: blizzard.ServerEvent[];\n };\n}\n\ninterface AppVendorAndPartnerUuid {\n appVendorUuid: string | undefined;\n partnerUuid: string | undefined;\n}\n\n// CameraKit's prod metrics endpoint.\n// See: https://github.sc-corp.net/Snapchat/pb_schema/blob/2a966db/proto/camera_kit/v3/service.proto#L133\nconst relativePath = \"/com.snap.camerakit.v3.Metrics/metrics/business_events\";\n\n// It is rather cumbersome to check the actual final size of a batch, but we can easily limit the number of events we\n// include in each batch -- looking at historical data, typical events average ~1.3kb per event. But there are some\n// events (like CAMERA_KIT_EXCEPTION, which includes a stack trace) that can be much larger.\n//\n// To prevent us running over the 64kibibyte limit imposed by browsers on `keep-alive` requests, we'll set quite a low\n// limit to ensure we don't lose events which are larger in size than we expect.\nconst BUSINESS_EVENT_BATCH_MAX_SIZE = 10;\nconst BUSINESS_EVENT_BATCH_MAX_AGE_MS = 5000;\n\nconst connectivityTypeMapping: Partial<Record<ConnectionType, blizzard.CameraKitConnectivityType>> = {\n cellular: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_MOBILE,\n bluetooth: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_BLUETOOTH,\n wifi: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_WIFI,\n unknown: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_UNKNOWN,\n none: blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_UNREACHABLE,\n};\n\nconst vendorUuidKey = \"vendorUuid\";\nconst vendorUuidExpiry = convertDaysToSeconds(60);\n\n/**\n * Retrieves or generates a vendor UUID (Universally Unique Identifier).\n *\n * @param persistence - The persistence storage interface where UUID is stored.\n * @returns {Promise<string | undefined>} - A Promise that resolves to the vendor UUID or undefined,\n * if any failure occurs or opt-in is not enabled.\n */\nconst getOrGenerateVendorUuid = async (persistence: ExpiringPersistence<string>): Promise<string | undefined> => {\n try {\n const storedUuid = await persistence.retrieve(vendorUuidKey);\n if (storedUuid) {\n return storedUuid;\n }\n\n const newUuid = v4();\n await persistence.store(vendorUuidKey, newUuid);\n\n return newUuid;\n } catch (error) {\n throw new Error(\"Failed to generate vendor UUID\");\n }\n};\n\nfunction listenAndReport(\n metricsEventTarget: MetricsEventTarget,\n metricsHandler: FetchHandler,\n pageVisibility: PageVisibility,\n eventHandlers: EventHandlers,\n apiHostname: CameraKitApiHostname,\n appVendorAndPartnerUuid: Observable<AppVendorAndPartnerUuid>\n): void {\n const sessionId = v4();\n logger.log(`Session ID: ${sessionId}`);\n\n // Blizzard convention is to start the sequenceId at 1.\n let sequenceId = 1;\n\n const handler = new HandlerChainBuilder(metricsHandler)\n .map(\n createMappingHandler((events: blizzard.ServerEvent[]) => {\n const body: SetBusinessEventsRequest = {\n batchEvents: {\n \"@type\": \"com.snapchat.analytics.blizzard.ServerEventBatch\",\n serverEvents: events,\n },\n };\n\n return new Request(`https://${apiHostname}${relativePath}`, {\n method: \"POST\",\n body: JSON.stringify(body),\n credentials: \"include\",\n\n // When this is true it makes fetch behave like `Navigator.sendBeacon` – that is, the request\n // will still be made even if the page terminates.\n // https://developer.mozilla.org/en-US/docs/Web/API/fetch\n keepalive: pageVisibility.isDuringVisibilityTransition(\"hidden\"),\n });\n }, pageVisibility)\n )\n .map(\n createBatchingHandler({\n batchReduce: (\n previousBundle: blizzard.ServerEvent[] | undefined,\n businessEvent: blizzard.ServerEvent\n ) => {\n const bundle = previousBundle ?? [];\n bundle.push(businessEvent);\n return bundle;\n },\n isBatchComplete: (bundle) => bundle.length >= BUSINESS_EVENT_BATCH_MAX_SIZE,\n maxBatchAge: BUSINESS_EVENT_BATCH_MAX_AGE_MS,\n pageVisibility,\n })\n ).handler;\n\n const makeBlizzardEvent = <E extends CameraKitBusinessEvents>(\n event: E,\n appVendorUuid: string | undefined,\n partnerUuid: string | undefined\n ): MakeBlizzardEvent<E> => {\n const { sdkShortVersion, sdkLongVersion, lensCore, locale, origin, deviceModel, connectionType } =\n getPlatformInfo();\n\n const deviceConnectivity =\n connectivityTypeMapping[connectionType!] ??\n blizzard.CameraKitConnectivityType.CAMERA_KIT_CONNECTIVITY_TYPE_UNKNOWN;\n\n return {\n ...event,\n cameraKitEventBase: blizzard.CameraKitEventBase.fromPartial({\n kitEventBase: blizzard.KitEventBase.fromPartial({\n locale,\n kitVariant: blizzard.KitType.CAMERA_KIT_WEB,\n kitVariantVersion: sdkShortVersion,\n kitClientTimestampMillis: Date.now(),\n }),\n deviceCluster: 0,\n cameraKitVersion: sdkLongVersion,\n lensCoreVersion: lensCore.version,\n deviceModel,\n cameraKitVariant: blizzard.CameraKitVariant.CAMERA_KIT_VARIANT_PARTNER,\n cameraKitFlavor: blizzard.CameraKitFlavor.CAMERA_KIT_FLAVOR_DEBUG,\n // We overload appId, using the origin instead because it's nice and human-readable (our backed adds\n // the true appId as oauth_client_id before forwarding events to Blizzard).\n appId: origin,\n deviceConnectivity,\n sessionId,\n appVendorUuid,\n partnerUuid,\n }),\n };\n };\n\n const sendServerEvent = (\n eventName: string,\n eventData: UndefinedToOptional<blizzard.ServerEventData>\n ): Promise<void> => {\n const { osName: osType, osVersion } = getPlatformInfo();\n return handler(\n blizzard.ServerEvent.fromPartial({\n eventName,\n osType,\n osVersion,\n maxSequenceIdOnInstance: 0,\n sequenceId: sequenceId++,\n eventData,\n })\n );\n };\n\n // Add event listeners for each event type and turn those listeners into Observables\n const metricsEvents = entries(eventHandlers).map(([eventType, createEventData]) =>\n fromEvent(metricsEventTarget, eventType).pipe(map((event) => ({ event, createEventData })))\n );\n\n // Subscribe to all the metrics events and combine them with the app/partner IDs obtained\n // from remote configuration -- this means we'll queue up any metrics events that occur\n // before remote config is downloaded, and send them once that config is available.\n merge(...metricsEvents)\n .pipe(combineLatestWith(appVendorAndPartnerUuid))\n .subscribe(([{ event, createEventData }, { appVendorUuid, partnerUuid }]) => {\n // Safety: When iterating over object keys in a mapped type, we lose the association between the key type\n // and the value type – at each iteration, the key type is a union of all possible keys and the value type\n // is a union of all possible values. When the value is a function with an argument, and that argument\n // depends on the key type (which is a union), the contravariance of the argument type means that the union\n // becomes an intersection. In our case here, this means the compiler expects each argument to contain all\n // properties from all event types. The cast is safe because the mapped `EventHandlers` type ensures that\n // `createEventData` takes an argument of the type corresponding its key's `eventType`'s event detail.\n const [eventName, eventData] = createEventData(\n makeBlizzardEvent(event.detail, appVendorUuid, partnerUuid) as any\n );\n sendServerEvent(eventName, eventData);\n });\n}\n\nexport type MakeBusinessEvent<E> = Omit<\n {\n [K in keyof E]: Exclude<E[K], undefined> extends Record<keyof any, any>\n ? MakeBusinessEvent<Exclude<E[K], undefined>>\n : E[K];\n },\n \"cameraKitEventBase\"\n>;\n\nfunction getAppVendorAndPartnerUuid(\n configuration: CameraKitConfiguration,\n remoteConfiguration: RemoteConfiguration\n): Observable<AppVendorAndPartnerUuid> {\n const vendorAnalyticsPersistence = new ExpiringPersistence<string>(\n () => vendorUuidExpiry,\n new IndexedDBPersistence({ databaseName: \"VendorAnalytics\" })\n );\n\n return remoteConfiguration.getInitializationConfig().pipe(\n take(1),\n\n switchMap(({ appVendorUuidOptIn }) => {\n const partnerUuid = configuration.analyticsId;\n if (appVendorUuidOptIn) {\n return from(getOrGenerateVendorUuid(vendorAnalyticsPersistence)).pipe(\n map((appVendorUuid) => ({ appVendorUuid, partnerUuid }))\n );\n }\n return of({ appVendorUuid: undefined, partnerUuid });\n }),\n\n catchError((error) => {\n logger.warn(`Failed to retrieve or generate vendor UUID.`, error);\n return of({ appVendorUuid: undefined, partnerUuid: configuration.analyticsId });\n })\n );\n}\n\nexport type MakeTaggedBusinessEvent<K extends keyof CameraKitBusinessEventMap> = {\n name: K;\n} & CameraKitBusinessEventMap[K];\n\nexport const businessEventsReporterFactory = Injectable(\n \"businessEventsReporter\",\n [\n metricsEventTargetFactory.token,\n metricsHandlerFactory.token,\n pageVisibilityFactory.token,\n configurationToken,\n remoteConfigurationFactory.token,\n ] as const,\n (\n metricsEventTarget: MetricsEventTarget,\n metricsHandler: FetchHandler,\n pageVisibility: PageVisibility,\n configuration: CameraKitConfiguration,\n remoteConfiguration: RemoteConfiguration\n ) => {\n const appVendorAndPartnerUuid = getAppVendorAndPartnerUuid(configuration, remoteConfiguration);\n\n /**\n * This defines a mapping from a business event's external name (the name we document in public\n * API docs), to its internal representation as a Blizzard ServerEvent.\n *\n * It is important that we do this, since the naming of these internal business events are\n * unintuitive and will not make sense to SDK users.\n *\n * To specify the internal event, we must give the ServerEvent's eventName, the specific property\n * name which contains the event data (this is a \"oneof\" property on ServerEvent), and use the\n * correct event type's `fromPartial` method (this is generated from the ServerEvent protobuf).\n *\n * These events are documented here:\n * https://docs.google.com/document/d/1-kSzFWCWw9Qo3D08FR1_cqeHTsUtk9p3p3uOptzWDTY/\n *\n * They are defined in code here:\n * https://github.sc-corp.net/Snapchat/snapchat/tree/master/blizzard/schema/blizzard-schema/\n * codeGen/src/main/java/com/snapchat/analytics/schema/events/cameraKit\n */\n listenAndReport(\n metricsEventTarget,\n metricsHandler,\n pageVisibility,\n {\n assetDownload: (event) => [\n \"CAMERA_KIT_ASSET_DOWNLOAD\",\n { cameraKitAssetDownload: blizzard.CameraKitAssetDownload.fromPartial(event) },\n ],\n assetValidationFailed: (event) => [\n \"CAMERA_KIT_ASSET_VALIDATION_FAILED\",\n {\n cameraKitAssetValidationFailed: blizzard.CameraKitAssetValidationFailed.fromPartial(event),\n },\n ],\n benchmarkComplete: (event) => [\n \"CAMERA_KIT_WEB_BENCHMARK_COMPLETE\",\n {\n cameraKitWebBenchmarkComplete: blizzard.CameraKitWebBenchmarkComplete.fromPartial(event),\n },\n ],\n exception: (event) => [\n \"CAMERA_KIT_EXCEPTION\",\n { cameraKitException: blizzard.CameraKitException.fromPartial(event) },\n ],\n legalPrompt: (event) => [\n \"CAMERA_KIT_LEGAL_PROMPT\",\n { cameraKitLegalPrompt: blizzard.CameraKitLegalPrompt.fromPartial(event) },\n ],\n lensDownload: (event) => [\n \"CAMERA_KIT_LENS_DOWNLOAD\",\n { cameraKitLensDownload: blizzard.CameraKitLensDownload.fromPartial(event) },\n ],\n lensView: (event) => [\n \"CAMERA_KIT_WEB_LENS_SWIPE\",\n { cameraKitWebLensSwipe: blizzard.CameraKitWebLensSwipe.fromPartial(event) },\n ],\n lensWait: (event) => [\n \"CAMERA_KIT_LENS_SPIN\",\n { cameraKitLensSpin: blizzard.CameraKitLensSpin.fromPartial(event) },\n ],\n lensContentValidationFailed: (event) => [\n \"CAMERA_KIT_LENS_CONTENT_VALIDATION_FAILED\",\n {\n cameraKitLensContentValidationFailed:\n blizzard.CameraKitLensContentValidationFailed.fromPartial(event),\n },\n ],\n session: (event) => [\n \"CAMERA_KIT_SESSION\",\n { cameraKitSession: blizzard.CameraKitSession.fromPartial(event) },\n ],\n },\n configuration.apiHostname,\n appVendorAndPartnerUuid\n );\n }\n);\n"]}
|
|
@@ -3,6 +3,12 @@ import { LogEntry } from "../../logger/logger";
|
|
|
3
3
|
import { LensState } from "../../session/lensState";
|
|
4
4
|
import { MetricsEventTarget } from "../metricsEventTarget";
|
|
5
5
|
import { OperationalMetricsReporter } from "../operational/operationalMetricsReporter";
|
|
6
|
+
interface RepeatableLogEntry {
|
|
7
|
+
entry: LogEntry;
|
|
8
|
+
count: number;
|
|
9
|
+
lastTime: Date;
|
|
10
|
+
}
|
|
11
|
+
export declare function getContextString(logEntries: RepeatableLogEntry[]): string;
|
|
6
12
|
export declare function reportExceptionToBlizzard(logEntries: Observable<LogEntry>, metricsEventTarget: MetricsEventTarget, reporter: OperationalMetricsReporter, lensState?: LensState): void;
|
|
7
13
|
export interface GlobalExceptionReporter {
|
|
8
14
|
attachLensContext: (lensState: LensState) => void;
|
|
@@ -17,3 +23,4 @@ export declare const reportGlobalException: {
|
|
|
17
23
|
token: "reportGlobalException";
|
|
18
24
|
dependencies: readonly ["logEntries", "metricsEventTarget", "operationalMetricsReporter"];
|
|
19
25
|
};
|
|
26
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isState } from "@snap/state-management";
|
|
2
2
|
import { filter, map, scan, Subject, takeUntil } from "rxjs";
|
|
3
3
|
import { entries } from "../../common/entries";
|
|
4
|
-
import {
|
|
4
|
+
import { ensureError } from "../../common/errorHelpers";
|
|
5
5
|
import { Injectable } from "../../dependency-injection/Injectable";
|
|
6
6
|
import { TypedCustomEvent } from "../../events/TypedCustomEvent";
|
|
7
7
|
import { logEntriesFactory } from "../../logger/logEntries";
|
|
@@ -13,18 +13,36 @@ const logMethods = entries(logLevelMap).map(([level]) => level);
|
|
|
13
13
|
const maxBufferedEntries = 15;
|
|
14
14
|
const contextSeparator = "\n\n----------------- Context -----------------\n\n";
|
|
15
15
|
const methodLength = logMethods.reduce((max, method) => Math.max(max, method.length), 0);
|
|
16
|
-
function getContextString(logEntries) {
|
|
16
|
+
export function getContextString(logEntries) {
|
|
17
17
|
const result = [];
|
|
18
18
|
for (const { entry, count, lastTime } of logEntries) {
|
|
19
19
|
const time = entry.time.toISOString();
|
|
20
20
|
const method = entry.level.padStart(methodLength);
|
|
21
|
-
|
|
22
|
-
const messages = entry.messages.map((m) => m + "").join(" ");
|
|
21
|
+
const messages = entry.messages.map(prettyPrintMessage).join(" ");
|
|
23
22
|
let dupSuffix = count > 1 ? ` (Repeated ${count} times with the last occurrence at ${lastTime.toISOString()})` : "";
|
|
24
23
|
result.push(`${time} [${entry.module}] ${method}: ${messages}${dupSuffix}`);
|
|
25
24
|
}
|
|
26
25
|
return result.join("\n");
|
|
27
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Pretty print a log message.
|
|
29
|
+
*/
|
|
30
|
+
function prettyPrintMessage(message) {
|
|
31
|
+
if (message instanceof Error)
|
|
32
|
+
return stringifyError(message);
|
|
33
|
+
if (message instanceof Date)
|
|
34
|
+
return message.toISOString();
|
|
35
|
+
return message + "";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns an error message for a given error, and also appends the error message of any nested error, if one exists.
|
|
39
|
+
* @param error Error to stringify.
|
|
40
|
+
* @returns Error message including nested error messages.
|
|
41
|
+
*/
|
|
42
|
+
function stringifyError(error) {
|
|
43
|
+
const cause = error.cause ? `; Caused by ${stringifyError(ensureError(error.cause))}` : "";
|
|
44
|
+
return `${error.name}: ${error.message}${cause}`;
|
|
45
|
+
}
|
|
28
46
|
export function reportExceptionToBlizzard(logEntries, metricsEventTarget, reporter, lensState) {
|
|
29
47
|
logEntries
|
|
30
48
|
.pipe(scan(({ entries }, newEntry) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reportGlobalException.js","sourceRoot":"","sources":["../../../src/metrics/reporters/reportGlobalException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAc,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAY,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAsB,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EACH,gCAAgC,GAEnC,MAAM,2CAA2C,CAAC;AAEnD,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,E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AkB,EAAE,QAAQ,CAAC,CAAC;IAEzG,uEAAuE;IACvE,wDAAwD;IACxD,OAAO;QACH,iBAAiB,EAAE,CAAC,SAAoB,EAAE,EAAE;YACxC,mBAAmB,CAAC,IAAI,EAAE,CAAC;YAC3B,yBAAyB,CAAC,UAAU,EAAE,kBAAkB,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QACnF,CAAC;KACJ,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["import { isState } from \"@snap/state-management\";\nimport { filter, map, Observable, scan, Subject, takeUntil } from \"rxjs\";\nimport { entries } from \"../../common/entries\";\nimport { stringifyError } from \"../../common/errorHelpers\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { TypedCustomEvent } from \"../../events/TypedCustomEvent\";\nimport { logEntriesFactory } from \"../../logger/logEntries\";\nimport { LogEntry, logLevelMap } from \"../../logger/logger\";\nimport { LensState } from \"../../session/lensState\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"../metricsEventTarget\";\nimport {\n operationalMetricReporterFactory,\n OperationalMetricsReporter,\n} from \"../operational/operationalMetricsReporter\";\n\nconst logMethods = entries(logLevelMap).map(([level]) => level);\n\n// How many log entries to include as the error context\nconst maxBufferedEntries = 15;\nconst contextSeparator = \"\\n\\n----------------- Context -----------------\\n\\n\";\nconst methodLength = logMethods.reduce((max, method) => Math.max(max, method.length), 0);\n\ninterface RepeatableLogEntry {\n entry: LogEntry;\n count: number;\n lastTime: Date;\n}\n\ninterface EntriesBuffer {\n /**\n * LogEntries grouped by their message.\n */\n entries: RepeatableLogEntry[];\n /**\n * The recent log entry.\n */\n recent: LogEntry;\n}\n\nfunction getContextString(logEntries: RepeatableLogEntry[]) {\n const result = [];\n for (const { entry, count, lastTime } of logEntries) {\n const time = entry.time.toISOString();\n const method = entry.level.padStart(methodLength);\n // TODO: improve pretty printing\n const messages = entry.messages.map((m) => m + \"\").join(\" \");\n let dupSuffix =\n count > 1 ? ` (Repeated ${count} times with the last occurrence at ${lastTime.toISOString()})` : \"\";\n\n result.push(`${time} [${entry.module}] ${method}: ${messages}${dupSuffix}`);\n }\n return result.join(\"\\n\");\n}\n\nexport function reportExceptionToBlizzard(\n logEntries: Observable<LogEntry>,\n metricsEventTarget: MetricsEventTarget,\n reporter: OperationalMetricsReporter,\n lensState?: LensState\n) {\n logEntries\n .pipe(\n scan<LogEntry, EntriesBuffer>(\n ({ entries }, newEntry) => {\n const lastEntry = entries[entries.length - 1];\n const isNewEntryRepeated =\n lastEntry &&\n lastEntry.entry.messages.join() === newEntry.messages.join() &&\n lastEntry.entry.level === newEntry.level;\n if (isNewEntryRepeated) {\n lastEntry.count += 1;\n lastEntry.lastTime = newEntry.time;\n } else {\n entries.push({\n entry: newEntry,\n count: 1,\n lastTime: newEntry.time,\n });\n }\n return {\n entries: entries.slice(-maxBufferedEntries),\n recent: newEntry,\n };\n },\n // Start with a dummy recent entry -- it gets overridden each time we handle a log entry.\n { entries: [], recent: { time: new Date(), module: \"any\", level: \"debug\", messages: [] } }\n ),\n filter(({ recent }) => recent.level === \"error\"),\n map(({ entries, recent }) => ({\n context: entries,\n error: recent.messages.find((e) => e instanceof Error) as Error,\n })),\n filter(({ error }) => !!error)\n )\n .subscribe(({ error, context }) => {\n const currentLensState = lensState?.getState();\n const lensId =\n currentLensState && !isState(currentLensState, \"noLensApplied\") ? currentLensState.data.id : \"none\";\n metricsEventTarget.dispatchEvent(\n new TypedCustomEvent(\"exception\", {\n name: \"exception\",\n lensId,\n type: error.name,\n reason: `${stringifyError(error)}${contextSeparator}${getContextString(context)}`,\n })\n );\n\n reporter.count(\"handled_exception\", 1, new Map([[\"type\", error.name]]));\n });\n}\n\nexport interface GlobalExceptionReporter {\n attachLensContext: (lensState: LensState) => void;\n}\n\n/**\n * Reports log entries to Blizzard when there is no CameraKit session yet.\n *\n * @internal\n */\nexport const reportGlobalException = Injectable(\n \"reportGlobalException\",\n [logEntriesFactory.token, metricsEventTargetFactory.token, operationalMetricReporterFactory.token] as const,\n (\n logEntries: Observable<LogEntry>,\n metricsEventTarget: MetricsEventTarget,\n reporter: OperationalMetricsReporter\n ): GlobalExceptionReporter => {\n // Initially we log exceptions without any lens context\n const cancellationSubject = new Subject<void>();\n reportExceptionToBlizzard(logEntries.pipe(takeUntil(cancellationSubject)), metricsEventTarget, reporter);\n\n // Later session scope reporter triggers cancellation of the global one\n // and initiates exception reporting with a lens context\n return {\n attachLensContext: (lensState: LensState) => {\n cancellationSubject.next();\n reportExceptionToBlizzard(logEntries, metricsEventTarget, reporter, lensState);\n },\n };\n }\n);\n"]}
|
|
1
|
+
{"version":3,"file":"reportGlobalException.js","sourceRoot":"","sources":["../../../src/metrics/reporters/reportGlobalException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAc,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAY,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAsB,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EACH,gCAAgC,GAEnC,MAAM,2CAA2C,CAAC;AAEnD,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;AAEhE,uDAAuD;AACvD,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,gBAAgB,GAAG,qDA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;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAC3C,uBAAuB,EACvB,CAAC,iBAAiB,CAAC,KAAK,EAAE,yBAAyB,CAAC,KAAK,EAAE,gCAAgC,CAAC,KAAK,CAAU,EAC3G,CACI,UAAgC,EAChC,kBAAsC,EACtC,QAAoC,EACb,EAAE;IACzB,uDAAuD;IACvD,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAQ,CAAC;IAChD,yBAAyB,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC,EAAE,kBAAkB,EAAE,QAAQ,CAAC,CAAC;IAEzG,uEAAuE;IACvE,wDAAwD;IACxD,OAAO;QACH,iBAAiB,EAAE,CAAC,SAAoB,EAAE,EAAE;YACxC,mBAAmB,CAAC,IAAI,EAAE,CAAC;YAC3B,yBAAyB,CAAC,UAAU,EAAE,kBAAkB,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QACnF,CAAC;KACJ,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["import { isState } from \"@snap/state-management\";\nimport { filter, map, Observable, scan, Subject, takeUntil } from \"rxjs\";\nimport { entries } from \"../../common/entries\";\nimport { ensureError } from \"../../common/errorHelpers\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { TypedCustomEvent } from \"../../events/TypedCustomEvent\";\nimport { logEntriesFactory } from \"../../logger/logEntries\";\nimport { LogEntry, logLevelMap } from \"../../logger/logger\";\nimport { LensState } from \"../../session/lensState\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"../metricsEventTarget\";\nimport {\n operationalMetricReporterFactory,\n OperationalMetricsReporter,\n} from \"../operational/operationalMetricsReporter\";\n\nconst logMethods = entries(logLevelMap).map(([level]) => level);\n\n// How many log entries to include as the error context\nconst maxBufferedEntries = 15;\nconst contextSeparator = \"\\n\\n----------------- Context -----------------\\n\\n\";\nconst methodLength = logMethods.reduce((max, method) => Math.max(max, method.length), 0);\n\ninterface RepeatableLogEntry {\n entry: LogEntry;\n count: number;\n lastTime: Date;\n}\n\ninterface EntriesBuffer {\n /**\n * LogEntries grouped by their message.\n */\n entries: RepeatableLogEntry[];\n /**\n * The recent log entry.\n */\n recent: LogEntry;\n}\n\nexport function getContextString(logEntries: RepeatableLogEntry[]) {\n const result = [];\n for (const { entry, count, lastTime } of logEntries) {\n const time = entry.time.toISOString();\n const method = entry.level.padStart(methodLength);\n const messages = entry.messages.map(prettyPrintMessage).join(\" \");\n let dupSuffix =\n count > 1 ? ` (Repeated ${count} times with the last occurrence at ${lastTime.toISOString()})` : \"\";\n\n result.push(`${time} [${entry.module}] ${method}: ${messages}${dupSuffix}`);\n }\n return result.join(\"\\n\");\n}\n\n/**\n * Pretty print a log message.\n */\nfunction prettyPrintMessage(message: unknown): string {\n if (message instanceof Error) return stringifyError(message);\n if (message instanceof Date) return message.toISOString();\n return message + \"\";\n}\n\n/**\n * Returns an error message for a given error, and also appends the error message of any nested error, if one exists.\n * @param error Error to stringify.\n * @returns Error message including nested error messages.\n */\nfunction stringifyError(error: Error): string {\n const cause = error.cause ? `; Caused by ${stringifyError(ensureError(error.cause))}` : \"\";\n return `${error.name}: ${error.message}${cause}`;\n}\n\nexport function reportExceptionToBlizzard(\n logEntries: Observable<LogEntry>,\n metricsEventTarget: MetricsEventTarget,\n reporter: OperationalMetricsReporter,\n lensState?: LensState\n) {\n logEntries\n .pipe(\n scan<LogEntry, EntriesBuffer>(\n ({ entries }, newEntry) => {\n const lastEntry = entries[entries.length - 1];\n const isNewEntryRepeated =\n lastEntry &&\n lastEntry.entry.messages.join() === newEntry.messages.join() &&\n lastEntry.entry.level === newEntry.level;\n if (isNewEntryRepeated) {\n lastEntry.count += 1;\n lastEntry.lastTime = newEntry.time;\n } else {\n entries.push({\n entry: newEntry,\n count: 1,\n lastTime: newEntry.time,\n });\n }\n return {\n entries: entries.slice(-maxBufferedEntries),\n recent: newEntry,\n };\n },\n // Start with a dummy recent entry -- it gets overridden each time we handle a log entry.\n { entries: [], recent: { time: new Date(), module: \"any\", level: \"debug\", messages: [] } }\n ),\n filter(({ recent }) => recent.level === \"error\"),\n map(({ entries, recent }) => ({\n context: entries,\n error: recent.messages.find((e) => e instanceof Error) as Error,\n })),\n filter(({ error }) => !!error)\n )\n .subscribe(({ error, context }) => {\n const currentLensState = lensState?.getState();\n const lensId =\n currentLensState && !isState(currentLensState, \"noLensApplied\") ? currentLensState.data.id : \"none\";\n metricsEventTarget.dispatchEvent(\n new TypedCustomEvent(\"exception\", {\n name: \"exception\",\n lensId,\n type: error.name,\n reason: `${stringifyError(error)}${contextSeparator}${getContextString(context)}`,\n })\n );\n\n reporter.count(\"handled_exception\", 1, new Map([[\"type\", error.name]]));\n });\n}\n\nexport interface GlobalExceptionReporter {\n attachLensContext: (lensState: LensState) => void;\n}\n\n/**\n * Reports log entries to Blizzard when there is no CameraKit session yet.\n *\n * @internal\n */\nexport const reportGlobalException = Injectable(\n \"reportGlobalException\",\n [logEntriesFactory.token, metricsEventTargetFactory.token, operationalMetricReporterFactory.token] as const,\n (\n logEntries: Observable<LogEntry>,\n metricsEventTarget: MetricsEventTarget,\n reporter: OperationalMetricsReporter\n ): GlobalExceptionReporter => {\n // Initially we log exceptions without any lens context\n const cancellationSubject = new Subject<void>();\n reportExceptionToBlizzard(logEntries.pipe(takeUntil(cancellationSubject)), metricsEventTarget, reporter);\n\n // Later session scope reporter triggers cancellation of the global one\n // and initiates exception reporting with a lens context\n return {\n attachLensContext: (lensState: LensState) => {\n cancellationSubject.next();\n reportExceptionToBlizzard(logEntries, metricsEventTarget, reporter, lensState);\n },\n };\n }\n);\n"]}
|
|
@@ -6,6 +6,17 @@ import { requestStateEventTargetFactory, } from "../../handlers/requestStateEmit
|
|
|
6
6
|
import { operationalMetricReporterFactory, } from "../operational/operationalMetricsReporter";
|
|
7
7
|
import { getPlatformInfo } from "../../platform/platformInfo";
|
|
8
8
|
import { isLensOrAssetRequest } from "./reportLensAndAssetDownload";
|
|
9
|
+
const getAdditionalDimensions = (dimensions) => {
|
|
10
|
+
switch (dimensions.requestType) {
|
|
11
|
+
case "lens_content":
|
|
12
|
+
case "asset":
|
|
13
|
+
return [];
|
|
14
|
+
case COF_REQUEST_TYPE:
|
|
15
|
+
return [["delta", dimensions.delta]];
|
|
16
|
+
default:
|
|
17
|
+
assertUnreachable(dimensions);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
9
20
|
const getContentType = (dimensions) => {
|
|
10
21
|
switch (dimensions.requestType) {
|
|
11
22
|
case "lens_content":
|
|
@@ -71,6 +82,9 @@ export const reportHttpMetrics = Injectable("reportHttpMetrics", [operationalMet
|
|
|
71
82
|
["network_type", (_a = getPlatformInfo().connectionType) !== null && _a !== void 0 ? _a : "unknown"],
|
|
72
83
|
["status", status],
|
|
73
84
|
]);
|
|
85
|
+
for (const [key, value] of getAdditionalDimensions(dimensions)) {
|
|
86
|
+
operationalDimensions.set(key, value);
|
|
87
|
+
}
|
|
74
88
|
return {
|
|
75
89
|
name: "completed",
|
|
76
90
|
inProgress: state.inProgress,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reportHttpMetrics.js","sourceRoot":"","sources":["../../../src/metrics/reporters/reportHttpMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAiB,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAIH,8BAA8B,GACjC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACH,gCAAgC,GAEnC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAA2B,oBAAoB,EAA0B,MAAM,8BAA8B,CAAC;AAgBrH,MAAM,cAAc,GAAG,CAAC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iBACrB,CAAC,CAAC;gBAEH,OAAO;oBACH,IAAI,EAAE,WAAW;oBACjB,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,UAAU,EAAE,qBAAqB;oBACjC,cAAc;oBACd,cAAc;iBACjB,CAAC;YACN;gBACI,iBAAiB,CAAC,KAAK,CAAC,CAAC;SAChC;IACL,CAAC,CACJ,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE;QAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW;YAAE,OAAO;QAEvC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;QAE7D,QAAQ,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;QACnD,QAAQ,CAAC,KAAK,CAAC,kBAAkB,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;QAC/D,QAAQ,CAAC,SAAS,CAAC,kBAAkB,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { assertUnreachable } from \"../../common/assertions\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { scan } from \"../../events/scan\";\nimport { CofDimensions, COF_REQUEST_TYPE } from \"../../remote-configuration/cofHandler\";\nimport {\n Dimensions,\n RequestStateEventTarget,\n RequestStateEvents,\n requestStateEventTargetFactory,\n} from \"../../handlers/requestStateEmittingHandler\";\nimport {\n operationalMetricReporterFactory,\n OperationalMetricsReporter,\n} from \"../operational/operationalMetricsReporter\";\nimport { getPlatformInfo } from \"../../platform/platformInfo\";\nimport { AssetDownloadDimensions, isLensOrAssetRequest, LensDownloadDimensions } from \"./reportLensAndAssetDownload\";\n\ntype InProgressMap = Map<number, { startTimeMs: number }>;\ninterface InProgress {\n name: \"inProgress\";\n inProgress: InProgressMap;\n}\ninterface Completed {\n name: \"completed\";\n inProgress: InProgressMap;\n dimensions: Map<string, string>;\n downloadTimeMs: number;\n downloadSizeKb: number;\n}\ntype RequestState = InProgress | Completed;\n\nconst getContentType = (dimensions: LensDownloadDimensions | AssetDownloadDimensions | CofDimensions): string => {\n switch (dimensions.requestType) {\n case \"lens_content\":\n return \"lens_content\";\n case \"asset\":\n return dimensions.assetType;\n case COF_REQUEST_TYPE:\n return COF_REQUEST_TYPE;\n default:\n assertUnreachable(dimensions);\n }\n};\n\nconst getSizeKb = (event: RequestStateEvents): number => {\n switch (event.type) {\n case \"started\":\n case \"errored\":\n return 0;\n case \"completed\":\n return event.detail.sizeByte / 1024;\n default:\n assertUnreachable(event);\n }\n};\n\nconst getStatus = (event: RequestStateEvents): string => {\n switch (event.type) {\n case \"started\":\n case \"errored\":\n // We'll use status 0 to indicate that an exception occurred during the request. This is somewhat in keeping\n // with browsers that set the response status to 0 if the request was not able to be made (e.g. CORs\n // preflight failed, or the user canceled the request).\n return \"0\";\n case \"completed\":\n return event.detail.status.toString();\n default:\n assertUnreachable(event);\n }\n};\n\nexport const isRelevantRequest = (\n value: Dimensions\n): value is LensDownloadDimensions | AssetDownloadDimensions | CofDimensions => {\n return isLensOrAssetRequest(value) || value[\"requestType\"] === COF_REQUEST_TYPE;\n};\n\nexport const reportHttpMetrics = Injectable(\n \"reportHttpMetrics\",\n [operationalMetricReporterFactory.token, requestStateEventTargetFactory.token] as const,\n (reporter: OperationalMetricsReporter, requestStateEventTarget: RequestStateEventTarget) => {\n scan<RequestState>({ name: \"inProgress\", inProgress: new Map() })(\n requestStateEventTarget,\n [\"started\", \"completed\", \"errored\"],\n (state, event) => {\n const { inProgress } = state;\n const { dimensions, requestId, timeMs } = event.detail;\n\n if (!isRelevantRequest(dimensions)) return state;\n\n switch (event.type) {\n case \"started\":\n inProgress.set(requestId, { startTimeMs: timeMs });\n return { name: \"inProgress\", inProgress };\n case \"completed\":\n case \"errored\":\n const completedRequest = inProgress.get(requestId);\n if (!completedRequest) return state;\n inProgress.delete(requestId);\n\n const downloadTimeMs = timeMs - completedRequest.startTimeMs;\n const downloadSizeKb = getSizeKb(event);\n const status = getStatus(event);\n const operationalDimensions = new Map<string, string>([\n [\"content_type\", getContentType(dimensions)],\n [\"network_type\", getPlatformInfo().connectionType ?? \"unknown\"],\n [\"status\", status],\n ]);\n\n return {\n name: \"completed\",\n inProgress: state.inProgress,\n dimensions: operationalDimensions,\n downloadSizeKb,\n downloadTimeMs,\n };\n default:\n assertUnreachable(event);\n }\n }\n ).addEventListener(\"state\", ({ detail: state }) => {\n if (state.name !== \"completed\") return;\n\n const { dimensions, downloadTimeMs, downloadSizeKb } = state;\n\n reporter.count(\"download_finished\", 1, dimensions);\n reporter.timer(\"download_latency\", downloadTimeMs, dimensions);\n reporter.histogram(\"download_size_kb\", downloadSizeKb, dimensions);\n });\n }\n);\n"]}
|
|
1
|
+
{"version":3,"file":"reportHttpMetrics.js","sourceRoot":"","sources":["../../../src/metrics/reporters/reportHttpMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAiB,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAIH,8BAA8B,GACjC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACH,gCAAgC,GAEnC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAA2B,oBAAoB,EAA0B,MAAM,8BAA8B,CAAC;AAgBrH,MAAM,uBAAuB,GAAG,CAC5B,UAA4E,EAC1D,EAAE;IACpB,QAAQ,UAAU,CAAC,WAAW,EAAE;QAC5B,KAAK,cAAc,CAAC;QACpB,KAAK,OAAO;YACR,OAAO,EAAE,CAAC;QACd,KAAK,gBAAgB;YACj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CAAC,cAAc,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;oBAC5C,CAAC,cAAc,EAAE,MAAA,eAAe,EAAE,CAAC,cAAc,mCAAI,SAAS,CAAC;oBAC/D,CAAC,QAAQ,EAAE,MAAM,CAAC;iBACrB,CAAC,CAAC;gBAEH,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,uBAAuB,CAAC,UAAU,CAAC,EAAE;oBAC5D,qBAAqB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;iBACzC;gBAED,OAAO;oBACH,IAAI,EAAE,WAAW;oBACjB,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,UAAU,EAAE,qBAAqB;oBACjC,cAAc;oBACd,cAAc;iBACjB,CAAC;YACN;gBACI,iBAAiB,CAAC,KAAK,CAAC,CAAC;SAChC;IACL,CAAC,CACJ,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE;QAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW;YAAE,OAAO;QAEvC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;QAE7D,QAAQ,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;QACnD,QAAQ,CAAC,KAAK,CAAC,kBAAkB,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;QAC/D,QAAQ,CAAC,SAAS,CAAC,kBAAkB,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { assertUnreachable } from \"../../common/assertions\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { scan } from \"../../events/scan\";\nimport { CofDimensions, COF_REQUEST_TYPE } from \"../../remote-configuration/cofHandler\";\nimport {\n Dimensions,\n RequestStateEventTarget,\n RequestStateEvents,\n requestStateEventTargetFactory,\n} from \"../../handlers/requestStateEmittingHandler\";\nimport {\n operationalMetricReporterFactory,\n OperationalMetricsReporter,\n} from \"../operational/operationalMetricsReporter\";\nimport { getPlatformInfo } from \"../../platform/platformInfo\";\nimport { AssetDownloadDimensions, isLensOrAssetRequest, LensDownloadDimensions } from \"./reportLensAndAssetDownload\";\n\ntype InProgressMap = Map<number, { startTimeMs: number }>;\ninterface InProgress {\n name: \"inProgress\";\n inProgress: InProgressMap;\n}\ninterface Completed {\n name: \"completed\";\n inProgress: InProgressMap;\n dimensions: Map<string, string>;\n downloadTimeMs: number;\n downloadSizeKb: number;\n}\ntype RequestState = InProgress | Completed;\n\nconst getAdditionalDimensions = (\n dimensions: LensDownloadDimensions | AssetDownloadDimensions | CofDimensions\n): [string, string][] => {\n switch (dimensions.requestType) {\n case \"lens_content\":\n case \"asset\":\n return [];\n case COF_REQUEST_TYPE:\n return [[\"delta\", dimensions.delta]];\n default:\n assertUnreachable(dimensions);\n }\n};\n\nconst getContentType = (dimensions: LensDownloadDimensions | AssetDownloadDimensions | CofDimensions): string => {\n switch (dimensions.requestType) {\n case \"lens_content\":\n return \"lens_content\";\n case \"asset\":\n return dimensions.assetType;\n case COF_REQUEST_TYPE:\n return COF_REQUEST_TYPE;\n default:\n assertUnreachable(dimensions);\n }\n};\n\nconst getSizeKb = (event: RequestStateEvents): number => {\n switch (event.type) {\n case \"started\":\n case \"errored\":\n return 0;\n case \"completed\":\n return event.detail.sizeByte / 1024;\n default:\n assertUnreachable(event);\n }\n};\n\nconst getStatus = (event: RequestStateEvents): string => {\n switch (event.type) {\n case \"started\":\n case \"errored\":\n // We'll use status 0 to indicate that an exception occurred during the request. This is somewhat in keeping\n // with browsers that set the response status to 0 if the request was not able to be made (e.g. CORs\n // preflight failed, or the user canceled the request).\n return \"0\";\n case \"completed\":\n return event.detail.status.toString();\n default:\n assertUnreachable(event);\n }\n};\n\nexport const isRelevantRequest = (\n value: Dimensions\n): value is LensDownloadDimensions | AssetDownloadDimensions | CofDimensions => {\n return isLensOrAssetRequest(value) || value[\"requestType\"] === COF_REQUEST_TYPE;\n};\n\nexport const reportHttpMetrics = Injectable(\n \"reportHttpMetrics\",\n [operationalMetricReporterFactory.token, requestStateEventTargetFactory.token] as const,\n (reporter: OperationalMetricsReporter, requestStateEventTarget: RequestStateEventTarget) => {\n scan<RequestState>({ name: \"inProgress\", inProgress: new Map() })(\n requestStateEventTarget,\n [\"started\", \"completed\", \"errored\"],\n (state, event) => {\n const { inProgress } = state;\n const { dimensions, requestId, timeMs } = event.detail;\n\n if (!isRelevantRequest(dimensions)) return state;\n\n switch (event.type) {\n case \"started\":\n inProgress.set(requestId, { startTimeMs: timeMs });\n return { name: \"inProgress\", inProgress };\n case \"completed\":\n case \"errored\":\n const completedRequest = inProgress.get(requestId);\n if (!completedRequest) return state;\n inProgress.delete(requestId);\n\n const downloadTimeMs = timeMs - completedRequest.startTimeMs;\n const downloadSizeKb = getSizeKb(event);\n const status = getStatus(event);\n const operationalDimensions = new Map<string, string>([\n [\"content_type\", getContentType(dimensions)],\n [\"network_type\", getPlatformInfo().connectionType ?? \"unknown\"],\n [\"status\", status],\n ]);\n\n for (const [key, value] of getAdditionalDimensions(dimensions)) {\n operationalDimensions.set(key, value);\n }\n\n return {\n name: \"completed\",\n inProgress: state.inProgress,\n dimensions: operationalDimensions,\n downloadSizeKb,\n downloadTimeMs,\n };\n default:\n assertUnreachable(event);\n }\n }\n ).addEventListener(\"state\", ({ detail: state }) => {\n if (state.name !== \"completed\") return;\n\n const { dimensions, downloadTimeMs, downloadSizeKb } = state;\n\n reporter.count(\"download_finished\", 1, dimensions);\n reporter.timer(\"download_latency\", downloadTimeMs, dimensions);\n reporter.histogram(\"download_size_kb\", downloadSizeKb, dimensions);\n });\n }\n);\n"]}
|
|
@@ -10,7 +10,7 @@ export type LensContentValidationFailed = MakeTaggedBusinessEvent<"lensContentVa
|
|
|
10
10
|
export declare const reportLensValidationFailed: {
|
|
11
11
|
(args_0: import("@snap/state-management").StateMachine<import("@snap/state-management").Action<"applyLens", {
|
|
12
12
|
lens: import("../..").Lens;
|
|
13
|
-
|
|
13
|
+
launchData?: import("../..").LensLaunchData | undefined;
|
|
14
14
|
}> | import("@snap/state-management").Action<"downloadComplete", import("../..").Lens> | import("@snap/state-management").Action<"turnedOn", import("../..").Lens> | import("@snap/state-management").Action<"resourcesLoaded", import("../..").Lens> | import("@snap/state-management").Action<"firstFrameProcessed", import("../..").Lens> | import("@snap/state-management").Action<"applyLensComplete", import("../..").Lens> | import("@snap/state-management").Action<"applyLensFailed", {
|
|
15
15
|
error: import("../../session/lensState").LensErrors;
|
|
16
16
|
lens: import("../..").Lens;
|
|
@@ -26,7 +26,7 @@ export type LensView = MakeTaggedBusinessEvent<"lensView">;
|
|
|
26
26
|
export declare const reportLensView: {
|
|
27
27
|
(args_0: CameraKitSession, args_1: import("@snap/state-management").StateMachine<import("@snap/state-management").Action<"applyLens", {
|
|
28
28
|
lens: import("../..").Lens;
|
|
29
|
-
|
|
29
|
+
launchData?: import("../..").LensLaunchData | undefined;
|
|
30
30
|
}> | import("@snap/state-management").Action<"downloadComplete", import("../..").Lens> | import("@snap/state-management").Action<"turnedOn", import("../..").Lens> | import("@snap/state-management").Action<"resourcesLoaded", import("../..").Lens> | import("@snap/state-management").Action<"firstFrameProcessed", import("../..").Lens> | import("@snap/state-management").Action<"applyLensComplete", import("../..").Lens> | import("@snap/state-management").Action<"applyLensFailed", {
|
|
31
31
|
error: import("../../session/lensState").LensErrors;
|
|
32
32
|
lens: import("../..").Lens;
|
|
@@ -23,7 +23,7 @@ export type LensWait = MakeTaggedBusinessEvent<"lensWait">;
|
|
|
23
23
|
export declare const reportLensWait: {
|
|
24
24
|
(args_0: import("@snap/state-management").StateMachine<import("@snap/state-management").Action<"applyLens", {
|
|
25
25
|
lens: import("../..").Lens;
|
|
26
|
-
|
|
26
|
+
launchData?: import("../..").LensLaunchData | undefined;
|
|
27
27
|
}> | import("@snap/state-management").Action<"downloadComplete", import("../..").Lens> | import("@snap/state-management").Action<"turnedOn", import("../..").Lens> | import("@snap/state-management").Action<"resourcesLoaded", import("../..").Lens> | import("@snap/state-management").Action<"firstFrameProcessed", import("../..").Lens> | import("@snap/state-management").Action<"applyLensComplete", import("../..").Lens> | import("@snap/state-management").Action<"applyLensFailed", {
|
|
28
28
|
error: import("../../session/lensState").LensErrors;
|
|
29
29
|
lens: import("../..").Lens;
|
|
@@ -7,7 +7,7 @@ import { GlobalExceptionReporter } from "./reportGlobalException";
|
|
|
7
7
|
export declare const reportSessionException: {
|
|
8
8
|
(args_0: GlobalExceptionReporter, args_1: import("@snap/state-management").StateMachine<import("@snap/state-management").Action<"applyLens", {
|
|
9
9
|
lens: import("../..").Lens;
|
|
10
|
-
|
|
10
|
+
launchData?: import("../..").LensLaunchData | undefined;
|
|
11
11
|
}> | import("@snap/state-management").Action<"downloadComplete", import("../..").Lens> | import("@snap/state-management").Action<"turnedOn", import("../..").Lens> | import("@snap/state-management").Action<"resourcesLoaded", import("../..").Lens> | import("@snap/state-management").Action<"firstFrameProcessed", import("../..").Lens> | import("@snap/state-management").Action<"applyLensComplete", import("../..").Lens> | import("@snap/state-management").Action<"applyLensFailed", {
|
|
12
12
|
error: import("../../session/lensState").LensErrors;
|
|
13
13
|
lens: import("../..").Lens;
|
|
@@ -35,7 +35,7 @@ export declare const reportSessionScopedMetrics: PartialContainer<{
|
|
|
35
35
|
metricsEventTarget: import("../metricsEventTarget").MetricsEventTarget;
|
|
36
36
|
lensState: import("@snap/state-management").StateMachine<import("@snap/state-management").Action<"applyLens", {
|
|
37
37
|
lens: import("../..").Lens;
|
|
38
|
-
|
|
38
|
+
launchData?: import("../..").LensLaunchData | undefined;
|
|
39
39
|
}> | import("@snap/state-management").Action<"downloadComplete", import("../..").Lens> | import("@snap/state-management").Action<"turnedOn", import("../..").Lens> | import("@snap/state-management").Action<"resourcesLoaded", import("../..").Lens> | import("@snap/state-management").Action<"firstFrameProcessed", import("../..").Lens> | import("@snap/state-management").Action<"applyLensComplete", import("../..").Lens> | import("@snap/state-management").Action<"applyLensFailed", {
|
|
40
40
|
error: import("../../session/lensState").LensErrors;
|
|
41
41
|
lens: import("../..").Lens;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { ensureError } from "../common/errorHelpers";
|
|
3
2
|
import { getLogger } from "../logger/logger";
|
|
4
3
|
const logger = getLogger("ExpiringPersistence");
|
|
5
4
|
/**
|
|
@@ -13,8 +12,8 @@ export class ExpiringPersistence {
|
|
|
13
12
|
constructor(expiration, persistence) {
|
|
14
13
|
this.expiration = expiration;
|
|
15
14
|
this.persistence = persistence;
|
|
16
|
-
this.removeExpired().catch(() => {
|
|
17
|
-
logger.warn("Failed to cleanup expired entries on startup.");
|
|
15
|
+
this.removeExpired().catch((error) => {
|
|
16
|
+
logger.warn("Failed to cleanup expired entries on startup.", error);
|
|
18
17
|
});
|
|
19
18
|
}
|
|
20
19
|
get size() {
|
|
@@ -28,7 +27,7 @@ export class ExpiringPersistence {
|
|
|
28
27
|
return undefined;
|
|
29
28
|
if (Date.now() > expiry) {
|
|
30
29
|
yield this.persistence.remove(key).catch((error) => {
|
|
31
|
-
logger.warn(`Key ${key} is expired, but removing it from persistence failed.`,
|
|
30
|
+
logger.warn(`Key ${key} is expired, but removing it from persistence failed.`, error);
|
|
32
31
|
});
|
|
33
32
|
return undefined;
|
|
34
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpiringPersistence.js","sourceRoot":"","sources":["../../src/persistence/ExpiringPersistence.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ExpiringPersistence.js","sourceRoot":"","sources":["../../src/persistence/ExpiringPersistence.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;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,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACvD,CAAC;CACJ","sourcesContent":["import { getLogger } from \"../logger/logger\";\nimport { Persistence, ValidKey } from \"./Persistence\";\n\nconst logger = getLogger(\"ExpiringPersistence\");\n\n/**\n * Create a Persistence that will remove entries after they expire.\n *\n * An expiration function must be provided, which is called each time a value is stored. It must return the expiration\n * time for that value, given in seconds from now. For example, to expire a value 24 hours after it is stored, the\n * expiration function should return 86400 (the number of seconds in 24 hours).\n */\nexport class ExpiringPersistence<T> implements Persistence<T> {\n constructor(\n private readonly expiration: (value: T) => number,\n private readonly persistence: Persistence<[number, T]>\n ) {\n this.removeExpired().catch((error) => {\n logger.warn(\"Failed to cleanup expired entries on startup.\", error);\n });\n }\n\n get size(): number {\n return this.persistence.size;\n }\n\n async retrieve(key: ValidKey): Promise<T | undefined> {\n const [expiry, value] = (await this.persistence.retrieve(key)) ?? [];\n if (value === undefined || expiry === undefined) return undefined;\n\n if (Date.now() > expiry) {\n await this.persistence.remove(key).catch((error) => {\n logger.warn(`Key ${key} is expired, but removing it from persistence failed.`, error);\n });\n return undefined;\n }\n return value;\n }\n\n async retrieveAll(): Promise<Array<[ValidKey, T]>> {\n const now = Date.now();\n return (await this.persistence.retrieveAll()).filter(([, [expiry]]) => expiry >= now).map(([, v]) => v);\n }\n\n remove(key: ValidKey): Promise<void> {\n return this.persistence.remove(key);\n }\n\n async removeAll(): Promise<T[]> {\n const results = await this.persistence.removeAll();\n return results.map(([, v]) => v);\n }\n\n async removeExpired(): Promise<void> {\n for (const [key, [expiry]] of await this.persistence.retrieveAll()) {\n if (Date.now() >= expiry) {\n await this.persistence\n .remove(key)\n .catch((error) => logger.warn(`Failed to remove expired key ${key}.`, error));\n }\n }\n }\n\n store(value: T): Promise<ValidKey>;\n store(key: ValidKey, value: T): Promise<ValidKey>;\n store(keyOrValue: T | ValidKey, maybeValue?: T): Promise<ValidKey> {\n const [key, value] =\n maybeValue === undefined ? [undefined, keyOrValue as T] : [keyOrValue as ValidKey, maybeValue];\n const expiry = Date.now() + this.expiration(value) * 1000;\n return key === undefined\n ? this.persistence.store([expiry, value])\n : this.persistence.store(key, [expiry, value]);\n }\n}\n"]}
|
|
@@ -25,7 +25,7 @@ function parseDeviceModel(userAgent) {
|
|
|
25
25
|
if (userAgentWithModel) {
|
|
26
26
|
return userAgentWithModel[1].trim();
|
|
27
27
|
}
|
|
28
|
-
// from user agent like "... (iPad; CPU OS 15_1 like Mac OS X) ..." extract "
|
|
28
|
+
// from user agent like "... (iPad; CPU OS 15_1 like Mac OS X) ..." extract "iPad"
|
|
29
29
|
const userAgentWithModel2 = userAgent.match(/\(([^;]+);/);
|
|
30
30
|
if (userAgentWithModel2) {
|
|
31
31
|
return userAgentWithModel2[1].trim();
|