@snap/camera-kit 0.9.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/README.md +18 -15
  2. package/docs/html/assets/search.js +1 -1
  3. package/docs/html/classes/CameraKit.html +116 -98
  4. package/docs/html/classes/CameraKitSession.html +175 -152
  5. package/docs/html/classes/CameraKitSource.html +109 -99
  6. package/docs/html/classes/LensPerformanceMeasurement.html +98 -92
  7. package/docs/html/classes/LensPerformanceMetrics.html +83 -79
  8. package/docs/html/classes/LensRepository.html +120 -107
  9. package/docs/html/classes/LensSources.html +86 -80
  10. package/docs/html/classes/Transform2D.html +98 -92
  11. package/docs/html/classes/TypedCustomEvent.html +83 -80
  12. package/docs/html/classes/TypedEventTarget.html +92 -89
  13. package/docs/html/functions/Injectable.html +87 -78
  14. package/docs/html/functions/bootstrapCameraKit.html +89 -84
  15. package/docs/html/functions/createExtension.html +76 -73
  16. package/docs/html/functions/createImageSource.html +80 -75
  17. package/docs/html/functions/createMediaStreamSource.html +81 -76
  18. package/docs/html/functions/createUserMediaSource.html +84 -75
  19. package/docs/html/functions/createVideoSource.html +80 -75
  20. package/docs/html/functions/estimateLensPerformance.html +76 -73
  21. package/docs/html/functions/getRequiredBootstrapURLs.html +78 -74
  22. package/docs/html/functions/lensSourcesFactory.html +74 -72
  23. package/docs/html/functions/uriHandlersFactory.html +76 -73
  24. package/docs/html/index.html +80 -78
  25. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +107 -98
  26. package/docs/html/interfaces/CameraKitSourceSubscriber.html +82 -79
  27. package/docs/html/interfaces/ComputedFrameMetrics.html +94 -82
  28. package/docs/html/interfaces/CreateSessionOptions.html +86 -81
  29. package/docs/html/interfaces/EstimatedLensPerformance.html +85 -82
  30. package/docs/html/interfaces/Lens.html +120 -102
  31. package/docs/html/interfaces/LensSource.html +102 -92
  32. package/docs/html/interfaces/MediaStreamSourceOptions.html +80 -78
  33. package/docs/html/interfaces/Preview.html +135 -0
  34. package/docs/html/interfaces/Snapcode.html +143 -0
  35. package/docs/html/interfaces/UriCancelRequest.html +80 -78
  36. package/docs/html/interfaces/UriHandler.html +102 -91
  37. package/docs/html/interfaces/UriRequest.html +89 -87
  38. package/docs/html/interfaces/UriResponse.html +89 -87
  39. package/docs/html/interfaces/VideoSourceOptions.html +77 -75
  40. package/docs/html/modules.html +153 -149
  41. package/docs/html/types/AssetLoader.html +75 -72
  42. package/docs/html/types/AssetTiming.html +75 -72
  43. package/docs/html/types/BenchmarkError.html +73 -71
  44. package/docs/html/types/BootstrapError.html +75 -72
  45. package/docs/html/types/CacheKeyNotFoundError.html +73 -71
  46. package/docs/html/types/CameraKitDeviceInfo.html +75 -72
  47. package/docs/html/types/CameraKitSessionEventListener.html +75 -72
  48. package/docs/html/types/CameraKitSessionEvents.html +82 -72
  49. package/docs/html/types/CameraKitSourceError.html +73 -71
  50. package/docs/html/types/CameraKitSourceInfo.html +73 -71
  51. package/docs/html/types/CameraKitSourceOptions.html +75 -72
  52. package/docs/html/types/ConfigurationError.html +75 -72
  53. package/docs/html/types/Keyboard.html +85 -78
  54. package/docs/html/types/KeyboardEvents.html +84 -72
  55. package/docs/html/types/LegalError.html +73 -71
  56. package/docs/html/types/LensAssetError.html +75 -72
  57. package/docs/html/types/LensContentValidationError.html +73 -71
  58. package/docs/html/types/LensError.html +73 -71
  59. package/docs/html/types/LensExecutionError.html +75 -72
  60. package/docs/html/types/LensImagePickerError.html +75 -72
  61. package/docs/html/types/LensLaunchParams.html +75 -72
  62. package/docs/html/types/LensMetricsEvents.html +75 -72
  63. package/docs/html/types/LensPerformanceCluster.html +75 -72
  64. package/docs/html/types/LensView.html +75 -72
  65. package/docs/html/types/LensWait.html +75 -72
  66. package/docs/html/types/PersistentStoreError.html +75 -72
  67. package/docs/html/types/PlatformNotSupportedError.html +75 -72
  68. package/docs/html/types/PublicContainer.html +75 -72
  69. package/docs/html/types/RenderTarget.html +75 -72
  70. package/docs/html/types/Uri.html +73 -71
  71. package/docs/html/types/UriHandlers.html +75 -72
  72. package/docs/html/types/WebGLError.html +73 -71
  73. package/docs/html/variables/extensionRequestContext.html +75 -72
  74. package/docs/md/README.md +18 -15
  75. package/docs/md/classes/CameraKit.md +14 -1
  76. package/docs/md/classes/CameraKitSession.md +1 -2
  77. package/docs/md/classes/CameraKitSource.md +1 -1
  78. package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
  79. package/docs/md/classes/LensPerformanceMetrics.md +1 -1
  80. package/docs/md/classes/LensRepository.md +1 -1
  81. package/docs/md/classes/LensSources.md +1 -1
  82. package/docs/md/classes/Transform2D.md +1 -1
  83. package/docs/md/classes/TypedCustomEvent.md +1 -1
  84. package/docs/md/classes/TypedEventTarget.md +1 -1
  85. package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +1 -1
  86. package/docs/md/interfaces/CameraKitSourceSubscriber.md +1 -1
  87. package/docs/md/interfaces/ComputedFrameMetrics.md +15 -1
  88. package/docs/md/interfaces/CreateSessionOptions.md +1 -1
  89. package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
  90. package/docs/md/interfaces/Lens.md +14 -3
  91. package/docs/md/interfaces/LensSource.md +1 -1
  92. package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
  93. package/docs/md/interfaces/Preview.md +19 -0
  94. package/docs/md/interfaces/Snapcode.md +28 -0
  95. package/docs/md/interfaces/UriCancelRequest.md +1 -1
  96. package/docs/md/interfaces/UriHandler.md +1 -1
  97. package/docs/md/interfaces/UriRequest.md +1 -1
  98. package/docs/md/interfaces/UriResponse.md +1 -1
  99. package/docs/md/interfaces/VideoSourceOptions.md +1 -1
  100. package/docs/md/modules.md +11 -3
  101. package/lib/CameraKit.d.ts +29 -16
  102. package/lib/CameraKit.js +34 -5
  103. package/lib/CameraKit.js.map +1 -1
  104. package/lib/__tests__/data.js +9 -1
  105. package/lib/__tests__/data.js.map +1 -1
  106. package/lib/assertPlatformSupported.js +1 -1
  107. package/lib/assertPlatformSupported.js.map +1 -1
  108. package/lib/benchmark/webglUtils.js +2 -2
  109. package/lib/benchmark/webglUtils.js.map +1 -1
  110. package/lib/bootstrapCameraKit.js +9 -5
  111. package/lib/bootstrapCameraKit.js.map +1 -1
  112. package/lib/common/__mocks__/loadScript.d.ts +1 -1
  113. package/lib/common/__mocks__/loadScript.js +1 -1
  114. package/lib/common/__mocks__/loadScript.js.map +1 -1
  115. package/lib/common/dialog.d.ts +16 -0
  116. package/lib/common/dialog.js +146 -0
  117. package/lib/common/dialog.js.map +1 -0
  118. package/lib/common/hash.d.ts +5 -0
  119. package/lib/common/hash.js +17 -0
  120. package/lib/common/hash.js.map +1 -0
  121. package/lib/common/loadScript.d.ts +6 -1
  122. package/lib/common/loadScript.js +9 -2
  123. package/lib/common/loadScript.js.map +1 -1
  124. package/lib/common/localization.d.ts +17 -10
  125. package/lib/common/localization.js +653 -18
  126. package/lib/common/localization.js.map +1 -1
  127. package/lib/common/pageVisibility.d.ts +34 -20
  128. package/lib/common/pageVisibility.js +57 -48
  129. package/lib/common/pageVisibility.js.map +1 -1
  130. package/lib/common/validate.js +2 -2
  131. package/lib/common/validate.js.map +1 -1
  132. package/lib/dependency-injection/Container.d.ts +2 -2
  133. package/lib/dependency-injection/Container.js +10 -10
  134. package/lib/dependency-injection/Container.js.map +1 -1
  135. package/lib/dependency-injection/RootServices.d.ts +5 -1
  136. package/lib/dependency-injection/RootServices.js.map +1 -1
  137. package/lib/environment.json +1 -1
  138. package/lib/events/scan.js +1 -1
  139. package/lib/events/scan.js.map +1 -1
  140. package/lib/extensions/LensSources.d.ts +5 -5
  141. package/lib/extensions/LensSources.js +9 -9
  142. package/lib/extensions/LensSources.js.map +1 -1
  143. package/lib/extensions/UriHandlers.d.ts +1 -1
  144. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +17 -0
  145. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +63 -1
  146. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -1
  147. package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +38 -1
  148. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +5 -0
  149. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +61 -0
  150. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -1
  151. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +64 -3
  152. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +70 -2
  153. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -1
  154. package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +506 -3
  155. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +125 -3
  156. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
  157. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +1917 -1852
  158. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +55 -132
  159. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -1
  160. package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +8 -1
  161. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -1
  162. package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +265 -0
  163. package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +628 -1
  164. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +140 -2
  165. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
  166. package/lib/generated-proto/pb_schema/common/ruid.d.ts +2 -0
  167. package/lib/generated-proto/pb_schema/common/ruid.js +2 -0
  168. package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -1
  169. package/lib/generated-proto/pb_schema/common/value.d.ts +22 -0
  170. package/lib/generated-proto/pb_schema/common/value.js +45 -0
  171. package/lib/generated-proto/pb_schema/common/value.js.map +1 -1
  172. package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +2 -0
  173. package/lib/generated-proto/pb_schema/lenses/launchdata.js +12 -0
  174. package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -1
  175. package/lib/handlers/HandlerChainBuilder.js +7 -2
  176. package/lib/handlers/HandlerChainBuilder.js.map +1 -1
  177. package/lib/handlers/batchingHandler.d.ts +8 -2
  178. package/lib/handlers/batchingHandler.js +5 -8
  179. package/lib/handlers/batchingHandler.js.map +1 -1
  180. package/lib/handlers/mappingHandler.d.ts +5 -1
  181. package/lib/handlers/mappingHandler.js +6 -4
  182. package/lib/handlers/mappingHandler.js.map +1 -1
  183. package/lib/handlers/rateLimitingHandler.d.ts +5 -1
  184. package/lib/handlers/rateLimitingHandler.js +6 -4
  185. package/lib/handlers/rateLimitingHandler.js.map +1 -1
  186. package/lib/handlers/requestStateEmittingHandler.d.ts +18 -5
  187. package/lib/handlers/requestStateEmittingHandler.js +12 -8
  188. package/lib/handlers/requestStateEmittingHandler.js.map +1 -1
  189. package/lib/handlers/responseCachingHandler.d.ts +1 -1
  190. package/lib/handlers/responseCachingHandler.js +1 -1
  191. package/lib/handlers/responseCachingHandler.js.map +1 -1
  192. package/lib/handlers/retryingHandler.d.ts +5 -1
  193. package/lib/handlers/retryingHandler.js +13 -9
  194. package/lib/handlers/retryingHandler.js.map +1 -1
  195. package/lib/index.d.ts +1 -1
  196. package/lib/index.js.map +1 -1
  197. package/lib/legal/legalPrompt.d.ts +7 -4
  198. package/lib/legal/legalPrompt.js +122 -133
  199. package/lib/legal/legalPrompt.js.map +1 -1
  200. package/lib/legal/legalState.d.ts +2 -2
  201. package/lib/legal/legalState.js +52 -38
  202. package/lib/legal/legalState.js.map +1 -1
  203. package/lib/lens/Lens.d.ts +32 -3
  204. package/lib/lens/Lens.js +10 -3
  205. package/lib/lens/Lens.js.map +1 -1
  206. package/lib/lens/LensLaunchParams.js +6 -4
  207. package/lib/lens/LensLaunchParams.js.map +1 -1
  208. package/lib/lens/LensPersistenceStore.js +1 -1
  209. package/lib/lens/LensPersistenceStore.js.map +1 -1
  210. package/lib/lens/LensRepository.d.ts +3 -2
  211. package/lib/lens/LensRepository.js +6 -5
  212. package/lib/lens/LensRepository.js.map +1 -1
  213. package/lib/lens/assets/LensAssetRepository.d.ts +5 -3
  214. package/lib/lens/assets/LensAssetRepository.js +21 -12
  215. package/lib/lens/assets/LensAssetRepository.js.map +1 -1
  216. package/lib/lens/assets/LensAssetsProvider.js +1 -1
  217. package/lib/lens/assets/LensAssetsProvider.js.map +1 -1
  218. package/lib/lens/lensEnvelopeUtil.js +1 -1
  219. package/lib/lens/lensEnvelopeUtil.js.map +1 -1
  220. package/lib/lens-client-interface/imagePicker.js +2 -2
  221. package/lib/lens-client-interface/imagePicker.js.map +1 -1
  222. package/lib/lens-client-interface/lensClientInterface.js +1 -1
  223. package/lib/lens-client-interface/lensClientInterface.js.map +1 -1
  224. package/lib/lens-core-module/loader/lensCoreFactory.js +4 -2
  225. package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -1
  226. package/lib/lensCoreWasmVersions.json +3 -3
  227. package/lib/logger/logEntries.d.ts +1 -1
  228. package/lib/logger/logEntries.js +3 -3
  229. package/lib/logger/logEntries.js.map +1 -1
  230. package/lib/logger/logger.d.ts +7 -2
  231. package/lib/logger/logger.js +9 -4
  232. package/lib/logger/logger.js.map +1 -1
  233. package/lib/media-sources/FunctionSource.js +1 -1
  234. package/lib/media-sources/FunctionSource.js.map +1 -1
  235. package/lib/media-sources/MediaStreamSource.d.ts +5 -1
  236. package/lib/media-sources/MediaStreamSource.js +14 -5
  237. package/lib/media-sources/MediaStreamSource.js.map +1 -1
  238. package/lib/metrics/businessEventsReporter.d.ts +3 -2
  239. package/lib/metrics/businessEventsReporter.js +16 -9
  240. package/lib/metrics/businessEventsReporter.js.map +1 -1
  241. package/lib/metrics/metricsHandler.d.ts +3 -2
  242. package/lib/metrics/metricsHandler.js +3 -3
  243. package/lib/metrics/metricsHandler.js.map +1 -1
  244. package/lib/metrics/operational/Count.d.ts +17 -0
  245. package/lib/metrics/operational/Count.js +28 -0
  246. package/lib/metrics/operational/Count.js.map +1 -0
  247. package/lib/metrics/operational/Histogram.d.ts +17 -0
  248. package/lib/metrics/operational/Histogram.js +23 -0
  249. package/lib/metrics/operational/Histogram.js.map +1 -0
  250. package/lib/metrics/operational/Metric.d.ts +20 -0
  251. package/lib/metrics/operational/Metric.js +26 -0
  252. package/lib/metrics/operational/Metric.js.map +1 -0
  253. package/lib/metrics/operational/Timer.d.ts +91 -0
  254. package/lib/metrics/operational/Timer.js +122 -0
  255. package/lib/metrics/operational/Timer.js.map +1 -0
  256. package/lib/metrics/{operationalMetricsReporter.d.ts → operational/operationalMetricsReporter.d.ts} +15 -4
  257. package/lib/metrics/{operationalMetricsReporter.js → operational/operationalMetricsReporter.js} +24 -8
  258. package/lib/metrics/operational/operationalMetricsReporter.js.map +1 -0
  259. package/lib/metrics/reporters/reportBenchmarks.d.ts +1 -1
  260. package/lib/metrics/reporters/reportBenchmarks.js +1 -1
  261. package/lib/metrics/reporters/reportBenchmarks.js.map +1 -1
  262. package/lib/metrics/reporters/reportGlobalException.d.ts +1 -1
  263. package/lib/metrics/reporters/reportGlobalException.js +1 -1
  264. package/lib/metrics/reporters/reportGlobalException.js.map +1 -1
  265. package/lib/metrics/reporters/reportHttpMetrics.d.ts +4 -4
  266. package/lib/metrics/reporters/reportHttpMetrics.js +3 -3
  267. package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
  268. package/lib/metrics/reporters/reportLegalState.d.ts +1 -1
  269. package/lib/metrics/reporters/reportLegalState.js +1 -1
  270. package/lib/metrics/reporters/reportLegalState.js.map +1 -1
  271. package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +4 -4
  272. package/lib/metrics/reporters/reportLensAndAssetDownload.js +7 -3
  273. package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -1
  274. package/lib/metrics/reporters/reportLensValidationFailed.d.ts +1 -1
  275. package/lib/metrics/reporters/reportLensView.d.ts +2 -2
  276. package/lib/metrics/reporters/reportLensView.js +23 -17
  277. package/lib/metrics/reporters/reportLensView.js.map +1 -1
  278. package/lib/metrics/reporters/reportLensWait.d.ts +2 -2
  279. package/lib/metrics/reporters/reportLensWait.js +1 -1
  280. package/lib/metrics/reporters/reportLensWait.js.map +1 -1
  281. package/lib/metrics/reporters/reportSessionException.d.ts +1 -1
  282. package/lib/metrics/reporters/reporters.d.ts +7 -6
  283. package/lib/metrics/reporters/reporters.js +3 -3
  284. package/lib/metrics/reporters/reporters.js.map +1 -1
  285. package/lib/observable-operators/unsubscribed.d.ts +12 -0
  286. package/lib/observable-operators/unsubscribed.js +27 -0
  287. package/lib/observable-operators/unsubscribed.js.map +1 -0
  288. package/lib/remote-configuration/cofHandler.d.ts +3 -2
  289. package/lib/remote-configuration/cofHandler.js +8 -4
  290. package/lib/remote-configuration/cofHandler.js.map +1 -1
  291. package/lib/remote-configuration/remoteConfiguration.d.ts +16 -4
  292. package/lib/remote-configuration/remoteConfiguration.js +32 -6
  293. package/lib/remote-configuration/remoteConfiguration.js.map +1 -1
  294. package/lib/session/CameraKitSession.d.ts +4 -4
  295. package/lib/session/CameraKitSession.js +10 -9
  296. package/lib/session/CameraKitSession.js.map +1 -1
  297. package/lib/session/LensKeyboard.d.ts +1 -1
  298. package/lib/session/LensPerformanceMeasurement.d.ts +2 -0
  299. package/lib/session/LensPerformanceMeasurement.js +27 -4
  300. package/lib/session/LensPerformanceMeasurement.js.map +1 -1
  301. package/lib/session/lensState.d.ts +5 -4
  302. package/lib/session/lensState.js +95 -41
  303. package/lib/session/lensState.js.map +1 -1
  304. package/package.json +12 -12
  305. package/lib/metrics/operationalMetricsReporter.js.map +0 -1
@@ -7,7 +7,7 @@ function decodeEnvelope(envelope) {
7
7
  return Envelope.decode(new Uint8Array(envelope)).lenses;
8
8
  }
9
9
  catch (_a) {
10
- throw new Error("Invalid lens envelope");
10
+ throw new Error("Invalid lens envelope.");
11
11
  }
12
12
  }
13
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"lensEnvelopeUtil.js","sourceRoot":"","sources":["../../src/lens/lensEnvelopeUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAG7E;;GAEG;AACH,SAAS,cAAc,CAAC,QAAqB;IACzC,IAAI;QACA,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;KAC3D;IAAC,WAAM;QACJ,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;KAC5C;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,SAAwB;IACpD,OAAO,SAAS,CAAC,MAAM,CAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7G,CAAC","sourcesContent":["import { Envelope } from \"../generated-proto/pb_schema/camera_kit/v3/export\";\nimport { LensProto } from \"./Lens\";\n\n/**\n * @internal\n */\nfunction decodeEnvelope(envelope: ArrayBuffer) {\n try {\n return Envelope.decode(new Uint8Array(envelope)).lenses;\n } catch {\n throw new Error(\"Invalid lens envelope\");\n }\n}\n\n/**\n * @internal\n */\nexport function decodeEnvelopes(envelopes: ArrayBuffer[]) {\n return envelopes.reduce<LensProto[]>((lenses, envelope) => [...lenses, ...decodeEnvelope(envelope)], []);\n}\n"]}
1
+ {"version":3,"file":"lensEnvelopeUtil.js","sourceRoot":"","sources":["../../src/lens/lensEnvelopeUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAG7E;;GAEG;AACH,SAAS,cAAc,CAAC,QAAqB;IACzC,IAAI;QACA,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;KAC3D;IAAC,WAAM;QACJ,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;KAC7C;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,SAAwB;IACpD,OAAO,SAAS,CAAC,MAAM,CAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7G,CAAC","sourcesContent":["import { Envelope } from \"../generated-proto/pb_schema/camera_kit/v3/export\";\nimport { LensProto } from \"./Lens\";\n\n/**\n * @internal\n */\nfunction decodeEnvelope(envelope: ArrayBuffer) {\n try {\n return Envelope.decode(new Uint8Array(envelope)).lenses;\n } catch {\n throw new Error(\"Invalid lens envelope.\");\n }\n}\n\n/**\n * @internal\n */\nexport function decodeEnvelopes(envelopes: ArrayBuffer[]) {\n return envelopes.reduce<LensProto[]>((lenses, envelope) => [...lenses, ...decodeEnvelope(envelope)], []);\n}\n"]}
@@ -57,7 +57,7 @@ function getMimeType({ ImageEnabled, VideoEnabled }) {
57
57
  if (VideoEnabled === "1")
58
58
  types.push(...enumerateSupportedVideoTypes(mimeTypes.video));
59
59
  if (types.length === 0) {
60
- throw new Error("Unknown media type requested");
60
+ throw new Error("Unknown media type requested.");
61
61
  }
62
62
  return types;
63
63
  }
@@ -77,7 +77,7 @@ function getOrientation(data, lensCore) {
77
77
  return orientationMap[(_a = extractJpegOrientationTag(data)) !== null && _a !== void 0 ? _a : 1 /* Orientation.TopLeft */];
78
78
  }
79
79
  catch (error) {
80
- logger.info("Error occured while reading EXIF orientation tag", error);
80
+ logger.info("Error occured while reading EXIF orientation tag.", error);
81
81
  return lensCore.ExternalMediaOrientation.CW0;
82
82
  }
83
83
  }
@@ -1 +1 @@
1
- {"version":3,"file":"imagePicker.js","sourceRoot":"","sources":["../../src/lens-client-interface/imagePicker.ts"],"names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AAC;SACN;IACL,CAAC;CAAA","sourcesContent":["import { fileOpen, FileWithHandle } from \"browser-fs-access\";\nimport { ClientInterfaceData, LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { getLogger } from \"../logger/logger\";\nimport { extractJpegOrientationTag, Orientation } from \"./exif\";\n\nconst logger = getLogger(\"lensClientInterfaceImagePicker\");\n\n// Common MIME types supported by all browsers as per:\n// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\nconst mimeTypes = {\n image: [\n \"image/avif\",\n \"image/bmp\",\n \"image/gif\",\n \"image/jpeg\",\n \"image/png\",\n \"image/svg+xml\",\n \"image/tiff\",\n \"image/webp\",\n ],\n video: [\n \"video/3gpp\",\n \"video/3gpp2\",\n \"video/mp2t\",\n \"video/mp4\",\n \"video/mpeg\",\n \"video/ogg\",\n \"video/quicktime\",\n \"video/webm\",\n \"video/x-msvideo\",\n ],\n} as const;\n\nfunction* enumerateSupportedVideoTypes(types: typeof mimeTypes.video) {\n // test video element to perform MIME types support check\n const testVideoElement = typeof document !== \"undefined\" ? document.createElement(\"video\") : undefined;\n for (const type of types) {\n if (testVideoElement?.canPlayType(type) || false) {\n yield type;\n }\n }\n}\n\nfunction readFileAsArrayBuffer(file: FileWithHandle): Promise<ArrayBuffer> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.addEventListener(\"load\", (event) => {\n // Safety: target.result is always an ArrayBuffer because we read file using readAsArrayBuffer()\n resolve(event.target!.result as ArrayBuffer);\n });\n reader.addEventListener(\"error\", (event) => {\n reject(event.target!.error);\n });\n reader.readAsArrayBuffer(file);\n });\n}\n\nfunction getMimeType({ ImageEnabled, VideoEnabled }: ClientInterfaceData) {\n const types = [];\n if (ImageEnabled === \"1\") types.push(...mimeTypes.image);\n if (VideoEnabled === \"1\") types.push(...enumerateSupportedVideoTypes(mimeTypes.video));\n if (types.length === 0) {\n throw new Error(\"Unknown media type requested\");\n }\n return types;\n}\n\nfunction getOrientation(data: ArrayBuffer, lensCore: LensCoreModule) {\n const orientationMap = {\n [Orientation.TopLeft]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.TopRight]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.BottomRight]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.BottomLeft]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.LeftTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightBottom]: lensCore.ExternalMediaOrientation.CW270,\n [Orientation.LeftBottom]: lensCore.ExternalMediaOrientation.CW270,\n };\n try {\n return orientationMap[extractJpegOrientationTag(data) ?? Orientation.TopLeft];\n } catch (error) {\n logger.info(\"Error occured while reading EXIF orientation tag\", error);\n return lensCore.ExternalMediaOrientation.CW0;\n }\n}\n\n/**\n * Shows file open dialog to allow user to select image/video and provides the selection to LensCore.\n *\n * @internal\n */\nexport async function pickClientImage(clientInterfaceData: ClientInterfaceData, lensCore: LensCoreModule) {\n const mimeTypes = getMimeType(clientInterfaceData);\n logger.debug(`Opening file dialog for MIME types: ${mimeTypes}`);\n\n const file = await fileOpen({ mimeTypes });\n logger.debug(`Selected file MIME type: ${file.type}`);\n\n const data = await readFileAsArrayBuffer(file);\n if (file.type.startsWith(\"image/\")) {\n lensCore.provideExternalImage({\n data,\n orientation: getOrientation(data, lensCore),\n // As per Corvyn: both iOS and Android clients have the ability to pick out individual faces\n // from an image to apply the effect on, using each of their native face detectors (not using LensCore).\n // That's what the faceRects is for. For now, we can just apply the effect to the whole image (so face rect\n // [[0,0][1,1]]). In future, in order to be able to pick out individual faces in the media picker, we could:\n // - hook up some external web face tracking library\n // - make LensCore to expose face tracker to external clients\n faceRects: [\n {\n origin: {\n x: 0,\n y: 0,\n },\n size: {\n width: 1,\n height: 1,\n },\n },\n ],\n });\n } else {\n lensCore.provideExternalVideo({\n data,\n orientation: lensCore.ExternalMediaOrientation.CW0,\n });\n }\n}\n"]}
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AAI;gBACJ,WAAW,EAAE,QAAQ,CAAC,wBAAwB,CAAC,GAAG;aACrD,CAAC,CAAC;SACN;IACL,CAAC;CAAA","sourcesContent":["import { fileOpen, FileWithHandle } from \"browser-fs-access\";\nimport { ClientInterfaceData, LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { getLogger } from \"../logger/logger\";\nimport { extractJpegOrientationTag, Orientation } from \"./exif\";\n\nconst logger = getLogger(\"lensClientInterfaceImagePicker\");\n\n// Common MIME types supported by all browsers as per:\n// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\nconst mimeTypes = {\n image: [\n \"image/avif\",\n \"image/bmp\",\n \"image/gif\",\n \"image/jpeg\",\n \"image/png\",\n \"image/svg+xml\",\n \"image/tiff\",\n \"image/webp\",\n ],\n video: [\n \"video/3gpp\",\n \"video/3gpp2\",\n \"video/mp2t\",\n \"video/mp4\",\n \"video/mpeg\",\n \"video/ogg\",\n \"video/quicktime\",\n \"video/webm\",\n \"video/x-msvideo\",\n ],\n} as const;\n\nfunction* enumerateSupportedVideoTypes(types: typeof mimeTypes.video) {\n // test video element to perform MIME types support check\n const testVideoElement = typeof document !== \"undefined\" ? document.createElement(\"video\") : undefined;\n for (const type of types) {\n if (testVideoElement?.canPlayType(type) || false) {\n yield type;\n }\n }\n}\n\nfunction readFileAsArrayBuffer(file: FileWithHandle): Promise<ArrayBuffer> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.addEventListener(\"load\", (event) => {\n // Safety: target.result is always an ArrayBuffer because we read file using readAsArrayBuffer()\n resolve(event.target!.result as ArrayBuffer);\n });\n reader.addEventListener(\"error\", (event) => {\n reject(event.target!.error);\n });\n reader.readAsArrayBuffer(file);\n });\n}\n\nfunction getMimeType({ ImageEnabled, VideoEnabled }: ClientInterfaceData) {\n const types = [];\n if (ImageEnabled === \"1\") types.push(...mimeTypes.image);\n if (VideoEnabled === \"1\") types.push(...enumerateSupportedVideoTypes(mimeTypes.video));\n if (types.length === 0) {\n throw new Error(\"Unknown media type requested.\");\n }\n return types;\n}\n\nfunction getOrientation(data: ArrayBuffer, lensCore: LensCoreModule) {\n const orientationMap = {\n [Orientation.TopLeft]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.TopRight]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.BottomRight]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.BottomLeft]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.LeftTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightBottom]: lensCore.ExternalMediaOrientation.CW270,\n [Orientation.LeftBottom]: lensCore.ExternalMediaOrientation.CW270,\n };\n try {\n return orientationMap[extractJpegOrientationTag(data) ?? Orientation.TopLeft];\n } catch (error) {\n logger.info(\"Error occured while reading EXIF orientation tag.\", error);\n return lensCore.ExternalMediaOrientation.CW0;\n }\n}\n\n/**\n * Shows file open dialog to allow user to select image/video and provides the selection to LensCore.\n *\n * @internal\n */\nexport async function pickClientImage(clientInterfaceData: ClientInterfaceData, lensCore: LensCoreModule) {\n const mimeTypes = getMimeType(clientInterfaceData);\n logger.debug(`Opening file dialog for MIME types: ${mimeTypes}`);\n\n const file = await fileOpen({ mimeTypes });\n logger.debug(`Selected file MIME type: ${file.type}`);\n\n const data = await readFileAsArrayBuffer(file);\n if (file.type.startsWith(\"image/\")) {\n lensCore.provideExternalImage({\n data,\n orientation: getOrientation(data, lensCore),\n // As per Corvyn: both iOS and Android clients have the ability to pick out individual faces\n // from an image to apply the effect on, using each of their native face detectors (not using LensCore).\n // That's what the faceRects is for. For now, we can just apply the effect to the whole image (so face rect\n // [[0,0][1,1]]). In future, in order to be able to pick out individual faces in the media picker, we could:\n // - hook up some external web face tracking library\n // - make LensCore to expose face tracker to external clients\n faceRects: [\n {\n origin: {\n x: 0,\n y: 0,\n },\n size: {\n width: 1,\n height: 1,\n },\n },\n ],\n });\n } else {\n lensCore.provideExternalVideo({\n data,\n orientation: lensCore.ExternalMediaOrientation.CW0,\n });\n }\n}\n"]}
@@ -22,7 +22,7 @@ export const registerLensClientInterfaceHandler = Injectable("registerLensClient
22
22
  if (interfaceControl === lensCore.InterfaceControl.ImagePicker &&
23
23
  interfaceAction === lensCore.InterfaceAction.Show) {
24
24
  yield pickClientImage(data, lensCore).catch((error) => {
25
- logger.error(lensImagePickerError("Failed to pick an image.", error));
25
+ logger.error(lensImagePickerError("Error occurred while attempting to select an image file for the lens request.", error));
26
26
  });
27
27
  }
28
28
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"lensClientInterface.js","sourceRoot":"","sources":["../../src/lens-client-interface/lensClientInterface.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,UAAU,CACxD,oCAAoC,EACpC,CAAC,eAAe,CAAC,KAAK,CAAU,EAChC,CAAC,QAAwB,EAAE,EAAE;IACzB,8DAA8D;IAC9D,IAAI,CAAC,QAAQ,CAAC,gCAAgC,EAAE;QAC5C,MAAM,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;QACvF,OAAO;KACV;IAED,QAAQ,CAAC,gCAAgC,CAAC,CAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,EAAE,EAAE;QAC5F,IACI,gBAAgB,KAAK,QAAQ,CAAC,gBAAgB,CAAC,WAAW;YAC1D,eAAe,KAAK,QAAQ,CAAC,eAAe,CAAC,IAAI,EACnD;YACE,MAAM,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBAClD,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC,CAAC;YAC1E,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { lensImagePickerError } from \"../namedErrors\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { lensCoreFactory } from \"../lens-core-module\";\nimport { LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { getLogger } from \"../logger/logger\";\nimport { pickClientImage } from \"./imagePicker\";\n\nconst logger = getLogger(\"lensClientInterface\");\n\n/**\n * Registers client interface handler in LensCore.\n *\n * @internal\n * @param lensCore LensCore instance to register in.\n * @param sessionErrors EventTarget to dispatch errors in.\n */\nexport const registerLensClientInterfaceHandler = Injectable(\n \"registerLensClientInterfaceHandler\",\n [lensCoreFactory.token] as const,\n (lensCore: LensCoreModule) => {\n // Make sure we are compatible with previous LensCore versions\n if (!lensCore.setClientInterfaceRequestHandler) {\n logger.warn(\"Current LensCore version doesn't support lens client interface requests\");\n return;\n }\n\n lensCore.setClientInterfaceRequestHandler(async ({ data, interfaceControl, interfaceAction }) => {\n if (\n interfaceControl === lensCore.InterfaceControl.ImagePicker &&\n interfaceAction === lensCore.InterfaceAction.Show\n ) {\n await pickClientImage(data, lensCore).catch((error) => {\n logger.error(lensImagePickerError(\"Failed to pick an image.\", error));\n });\n }\n });\n }\n);\n"]}
1
+ {"version":3,"file":"lensClientInterface.js","sourceRoot":"","sources":["../../src/lens-client-interface/lensClientInterface.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,UAAU,CACxD,oCAAoC,EACpC,CAAC,eAAe,CAAC,KAAK,CAAU,EAChC,CAAC,QAAwB,EAAE,EAAE;IACzB,8DAA8D;IAC9D,IAAI,CAAC,QAAQ,CAAC,gCAAgC,EAAE;QAC5C,MAAM,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;QACvF,OAAO;KACV;IAED,QAAQ,CAAC,gCAAgC,CAAC,CAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,EAAE,EAAE;QAC5F,IACI,gBAAgB,KAAK,QAAQ,CAAC,gBAAgB,CAAC,WAAW;YAC1D,eAAe,KAAK,QAAQ,CAAC,eAAe,CAAC,IAAI,EACnD;YACE,MAAM,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBAClD,MAAM,CAAC,KAAK,CACR,oBAAoB,CAChB,+EAA+E,EAC/E,KAAK,CACR,CACJ,CAAC;YACN,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { lensImagePickerError } from \"../namedErrors\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { lensCoreFactory } from \"../lens-core-module\";\nimport { LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { getLogger } from \"../logger/logger\";\nimport { pickClientImage } from \"./imagePicker\";\n\nconst logger = getLogger(\"lensClientInterface\");\n\n/**\n * Registers client interface handler in LensCore.\n *\n * @internal\n * @param lensCore LensCore instance to register in.\n * @param sessionErrors EventTarget to dispatch errors in.\n */\nexport const registerLensClientInterfaceHandler = Injectable(\n \"registerLensClientInterfaceHandler\",\n [lensCoreFactory.token] as const,\n (lensCore: LensCoreModule) => {\n // Make sure we are compatible with previous LensCore versions\n if (!lensCore.setClientInterfaceRequestHandler) {\n logger.warn(\"Current LensCore version doesn't support lens client interface requests\");\n return;\n }\n\n lensCore.setClientInterfaceRequestHandler(async ({ data, interfaceControl, interfaceAction }) => {\n if (\n interfaceControl === lensCore.InterfaceControl.ImagePicker &&\n interfaceAction === lensCore.InterfaceAction.Show\n ) {\n await pickClientImage(data, lensCore).catch((error) => {\n logger.error(\n lensImagePickerError(\n \"Error occurred while attempting to select an image file for the lens request.\",\n error\n )\n );\n });\n }\n });\n }\n);\n"]}
@@ -81,14 +81,14 @@ export const lensCoreFactory = Injectable("lensCore", [defaultFetchHandlerFactor
81
81
  lensCoreWASM = (_b = findMatch(/\.wasm/, assetURLs)) !== null && _b !== void 0 ? _b : "";
82
82
  if (!lensCoreJS || !lensCoreWASM) {
83
83
  throw new Error(`Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +
84
- `this list: ${assetURLs}`);
84
+ `this list: ${assetURLs}.`);
85
85
  }
86
86
  // Fetching here and creating an Object URL lets LensCore optimized loading itself in a WebWorker,
87
87
  // otherwise the glue script would need to be downloaded again.
88
88
  const glueScript = yield handler(lensCoreJS).then((r) => r.blob());
89
89
  lensCoreJS = URL.createObjectURL(glueScript);
90
90
  }
91
- yield loadScript(lensCoreJS);
91
+ const scriptElement = yield loadScript(lensCoreJS);
92
92
  const lensCore = yield new Promise((resolve, reject) => {
93
93
  let initialModule;
94
94
  // will trigger WASM initialization and data loading,
@@ -112,6 +112,8 @@ export const lensCoreFactory = Injectable("lensCore", [defaultFetchHandlerFactor
112
112
  },
113
113
  }));
114
114
  });
115
+ // now when we have LensCore WASM in memory we can release the script element
116
+ scriptElement.remove();
115
117
  // print warning if loaded version differs from hardcoded one
116
118
  if (lensCoreWasm.version != `${lensCore.getCoreVersion()}`) {
117
119
  logger.warn(`Loaded LensCore version (${lensCore.getCoreVersion()}) differs from expected one (${lensCoreWasm.version})`);
@@ -1 +1 @@
1
- {"version":3,"file":"lensCoreFactory.js","sourceRoot":"","sources":["../../../src/lens-core-module/loader/lensCoreFactory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,YAAY,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAA0B,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAgB,MAAM,oCAAoC,CAAC;AAE9F,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,MAAM,MAAM,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAE5C,MAAM,UAAU,GAAG,CAAC,wBAAwB,EAAE,0BAA0B,CAAC,CAAC;AAE1E,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,OAAiB,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3F,MAAM,gBAAgB,GAAG;IACrB,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,IAAI;IACV,UAAU,EAAE,IAAI;CACnB,CAAC;AAEF,MAAM,yBAAyB,GAAG;IAC9B,CAAC,gBAAgB,CAAC,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,EAAE,cAAc;IACrE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,cAAc;IACvC,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,SAAS;IACxC,CAAC,gBAAgB,CAAC,OA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CAAC,UAAU,CAAC,CAAC;IAE7B,MAAM,QAAQ,GAAG,MAAM,IAAI,OAAO,CAA2C,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7F,IAAI,aAA+C,CAAC;QACpD,qDAAqD;QACrD,mEAAmE;QACnE,wCAAwC;QACxC,mCAAmC;QACnC,mKAAmK;QACnK,MAAM,UAAU,GAAG,UAAU,CAAC,kBAAkB,CAC5C,CAAC,aAAa,GAAG;YACb,kEAAkE;YAClE,mBAAmB,EAAE,UAAU;YAC/B,4DAA4D;YAC5D,eAAe,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,EAAE;gBAC/C,WAAW,CAAC,oBAAoB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;qBAChE,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE;oBAChC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;oBAClC,2CAA2C;oBAC3C,aAAa,CAAC,cAAc,GAAG,MAAM,CAAC;oBACtC,OAAO,CAAC,UAAU,CAAC,CAAC;gBACxB,CAAC,CAAC;qBACD,KAAK,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;SACJ,CAAC,CACL,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,6DAA6D;IAC7D,IAAI,YAAY,CAAC,OAAO,IAAI,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,EAAE;QACxD,MAAM,CAAC,IAAI,CACP,4BAA4B,QAAQ,CAAC,cAAc,EAAE,gCACjD,YAAY,CAAC,OACjB,GAAG,CACN,CAAC;KACL;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAA,CACJ,CAAC","sourcesContent":["import { simd, exceptions } from \"wasm-feature-detect\";\nimport lensCoreWasm from \"../../lensCoreWasmVersions.json\";\nimport { loadScript } from \"../../common\";\nimport { CameraKitConfiguration, configurationToken } from \"../../configuration\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { InitialEmscriptenModule, LensCoreModule } from \"../generated-types\";\nimport { getLogger } from \"../../logger/logger\";\nimport { cameraKitUserAgent } from \"../../common/cameraKitUserAgent\";\n\nconst logger = getLogger(\"lensCoreFactory\");\n\nconst wasmAssets = [\"LensCoreWebAssembly.js\", \"LensCoreWebAssembly.wasm\"];\n\nconst findMatch = (regex: RegExp, strings: string[]) => strings.find((s) => regex.test(s));\n\nconst PlatformFeatures = {\n Default: 0,\n Simd: 0b01,\n Exceptions: 0b10,\n};\n\nconst platformFeaturesToFlavour = {\n [PlatformFeatures.Exceptions | PlatformFeatures.Simd]: \"rel-simd-neh\",\n [PlatformFeatures.Simd]: \"release-simd\",\n [PlatformFeatures.Exceptions]: \"rel-neh\",\n [PlatformFeatures.Default]: \"release\",\n};\n\n/**\n * Returns a list of URLs for resources which will be fetched during {@link bootstrapCameraKit}.\n *\n * When CameraKit is used on a website, these URLs much be reachable in order for CameraKit to be successfully\n * bootstrapped.\n *\n * @param endpointOverride Optional endpoint override to load the assets from.\n * @returns An array of asset URLs.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function getRequiredBootstrapURLs(endpointOverride?: string): Promise<string[]> {\n // If we have an endpoint override, remove trailing `/` so we can construct a valid URL.\n const endpoint = endpointOverride?.replace(/[\\/]+$/, \"\");\n\n let [simdFeature, exceptionsFeature] = await Promise.all([\n simd().then((supported) => (supported ? PlatformFeatures.Simd : PlatformFeatures.Default)),\n exceptions().then((supported) => (supported ? PlatformFeatures.Exceptions : PlatformFeatures.Default)),\n ]);\n\n // Although Safari 16.4 reports SIMD support, LensCore encounters rendering bugs when using SIMD in Safari 16.4.\n // Therefore, we have made the decision to disable SIMD for now until Safari stabilizes the feature.\n const { brand } = cameraKitUserAgent.browser;\n if (brand === \"Safari\") simdFeature = PlatformFeatures.Default;\n\n const flavor = platformFeaturesToFlavour[simdFeature | exceptionsFeature];\n\n const version = lensCoreWasm.version;\n const buildNumber = lensCoreWasm.buildNumber;\n return wasmAssets.map((asset) => {\n if (endpoint) return `${endpoint}/${asset}`;\n const { origin, pathname, search } = new URL(lensCoreWasm.baseUrl);\n return `${origin}${pathname}/${version}/${buildNumber}/${flavor}/${asset}${search}`;\n });\n}\n\n/**\n * This component is responsible for:\n * 1) Loading LensCore WebAssembly (WASM) assets\n * 2) Using the WASM assets to initialize the LensCore WASM module\n *\n * By default, WASM assets will be loaded from the Bolt CDN – but if `endpoint` is provided, assets will be loaded\n * using it as a base URL.\n *\n * @internal\n */\nexport const lensCoreFactory = Injectable(\n \"lensCore\",\n [defaultFetchHandlerFactory.token, configurationToken] as const,\n async (handler: FetchHandler, { lensCoreOverrideUrls, wasmEndpointOverride }: CameraKitConfiguration) => {\n let lensCoreJS: string;\n let lensCoreWASM: string;\n\n if (lensCoreOverrideUrls) {\n lensCoreJS = lensCoreOverrideUrls.js;\n lensCoreWASM = lensCoreOverrideUrls.wasm;\n } else {\n const endpointOverride = wasmEndpointOverride ?? undefined;\n const assetURLs = await getRequiredBootstrapURLs(endpointOverride);\n\n lensCoreJS = findMatch(/\\.js/, assetURLs) ?? \"\";\n lensCoreWASM = findMatch(/\\.wasm/, assetURLs) ?? \"\";\n\n if (!lensCoreJS || !lensCoreWASM) {\n throw new Error(\n `Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +\n `this list: ${assetURLs}`\n );\n }\n\n // Fetching here and creating an Object URL lets LensCore optimized loading itself in a WebWorker,\n // otherwise the glue script would need to be downloaded again.\n const glueScript = await handler(lensCoreJS).then((r) => r.blob());\n lensCoreJS = URL.createObjectURL(glueScript);\n }\n\n await loadScript(lensCoreJS);\n\n const lensCore = await new Promise<InitialEmscriptenModule & LensCoreModule>((resolve, reject) => {\n let initialModule: Partial<InitialEmscriptenModule>;\n // will trigger WASM initialization and data loading,\n // after completion it will be safe to call imported WASM functions\n // More about emscripten initialization:\n // eslint-disable-next-line max-len\n // https://emscripten.org/docs/getting_started/FAQ.html?highlight=modularize#how-can-i-tell-when-the-page-is-fully-loaded-and-it-is-safe-to-call-compiled-functions\n const moduleInit = globalThis.createLensesModule(\n (initialModule = {\n // url will be used for loading glue JS during Worker inialization\n mainScriptUrlOrBlob: lensCoreJS,\n // will be triggered by Emscripten during the initialization\n instantiateWasm: (importObject, receiveInstance) => {\n WebAssembly.instantiateStreaming(handler(lensCoreWASM), importObject)\n .then(function ({ instance, module }) {\n receiveInstance(instance, module);\n // compiled module will be reused in Worker\n initialModule.compiledModule = module;\n resolve(moduleInit);\n })\n .catch(reject);\n },\n })\n );\n });\n\n // print warning if loaded version differs from hardcoded one\n if (lensCoreWasm.version != `${lensCore.getCoreVersion()}`) {\n logger.warn(\n `Loaded LensCore version (${lensCore.getCoreVersion()}) differs from expected one (${\n lensCoreWasm.version\n })`\n );\n }\n\n return lensCore;\n }\n);\n"]}
1
+ {"version":3,"file":"lensCoreFactory.js","sourceRoot":"","sources":["../../../src/lens-core-module/loader/lensCoreFactory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,YAAY,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAA0B,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAgB,MAAM,oCAAoC,CAAC;AAE9F,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,MAAM,MAAM,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAE5C,MAAM,UAAU,GAAG,CAAC,wBAAwB,EAAE,0BAA0B,CAAC,CAAC;AAE1E,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,OAAiB,EAAE,EAAE,CAAC,OAA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C,CAAC,CAAC;IAEH,6EAA6E;IAC7E,aAAa,CAAC,MAAM,EAAE,CAAC;IAEvB,6DAA6D;IAC7D,IAAI,YAAY,CAAC,OAAO,IAAI,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,EAAE;QACxD,MAAM,CAAC,IAAI,CACP,4BAA4B,QAAQ,CAAC,cAAc,EAAE,gCACjD,YAAY,CAAC,OACjB,GAAG,CACN,CAAC;KACL;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAA,CACJ,CAAC","sourcesContent":["import { simd, exceptions } from \"wasm-feature-detect\";\nimport lensCoreWasm from \"../../lensCoreWasmVersions.json\";\nimport { loadScript } from \"../../common\";\nimport { CameraKitConfiguration, configurationToken } from \"../../configuration\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { InitialEmscriptenModule, LensCoreModule } from \"../generated-types\";\nimport { getLogger } from \"../../logger/logger\";\nimport { cameraKitUserAgent } from \"../../common/cameraKitUserAgent\";\n\nconst logger = getLogger(\"lensCoreFactory\");\n\nconst wasmAssets = [\"LensCoreWebAssembly.js\", \"LensCoreWebAssembly.wasm\"];\n\nconst findMatch = (regex: RegExp, strings: string[]) => strings.find((s) => regex.test(s));\n\nconst PlatformFeatures = {\n Default: 0,\n Simd: 0b01,\n Exceptions: 0b10,\n};\n\nconst platformFeaturesToFlavour = {\n [PlatformFeatures.Exceptions | PlatformFeatures.Simd]: \"rel-simd-neh\",\n [PlatformFeatures.Simd]: \"release-simd\",\n [PlatformFeatures.Exceptions]: \"rel-neh\",\n [PlatformFeatures.Default]: \"release\",\n};\n\n/**\n * Returns a list of URLs for resources which will be fetched during {@link bootstrapCameraKit}.\n *\n * When CameraKit is used on a website, these URLs much be reachable in order for CameraKit to be successfully\n * bootstrapped.\n *\n * @param endpointOverride Optional endpoint override to load the assets from.\n * @returns An array of asset URLs.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function getRequiredBootstrapURLs(endpointOverride?: string): Promise<string[]> {\n // If we have an endpoint override, remove trailing `/` so we can construct a valid URL.\n const endpoint = endpointOverride?.replace(/[\\/]+$/, \"\");\n\n let [simdFeature, exceptionsFeature] = await Promise.all([\n simd().then((supported) => (supported ? PlatformFeatures.Simd : PlatformFeatures.Default)),\n exceptions().then((supported) => (supported ? PlatformFeatures.Exceptions : PlatformFeatures.Default)),\n ]);\n\n // Although Safari 16.4 reports SIMD support, LensCore encounters rendering bugs when using SIMD in Safari 16.4.\n // Therefore, we have made the decision to disable SIMD for now until Safari stabilizes the feature.\n const { brand } = cameraKitUserAgent.browser;\n if (brand === \"Safari\") simdFeature = PlatformFeatures.Default;\n\n const flavor = platformFeaturesToFlavour[simdFeature | exceptionsFeature];\n\n const version = lensCoreWasm.version;\n const buildNumber = lensCoreWasm.buildNumber;\n return wasmAssets.map((asset) => {\n if (endpoint) return `${endpoint}/${asset}`;\n const { origin, pathname, search } = new URL(lensCoreWasm.baseUrl);\n return `${origin}${pathname}/${version}/${buildNumber}/${flavor}/${asset}${search}`;\n });\n}\n\n/**\n * This component is responsible for:\n * 1) Loading LensCore WebAssembly (WASM) assets\n * 2) Using the WASM assets to initialize the LensCore WASM module\n *\n * By default, WASM assets will be loaded from the Bolt CDN – but if `endpoint` is provided, assets will be loaded\n * using it as a base URL.\n *\n * @internal\n */\nexport const lensCoreFactory = Injectable(\n \"lensCore\",\n [defaultFetchHandlerFactory.token, configurationToken] as const,\n async (handler: FetchHandler, { lensCoreOverrideUrls, wasmEndpointOverride }: CameraKitConfiguration) => {\n let lensCoreJS: string;\n let lensCoreWASM: string;\n\n if (lensCoreOverrideUrls) {\n lensCoreJS = lensCoreOverrideUrls.js;\n lensCoreWASM = lensCoreOverrideUrls.wasm;\n } else {\n const endpointOverride = wasmEndpointOverride ?? undefined;\n const assetURLs = await getRequiredBootstrapURLs(endpointOverride);\n\n lensCoreJS = findMatch(/\\.js/, assetURLs) ?? \"\";\n lensCoreWASM = findMatch(/\\.wasm/, assetURLs) ?? \"\";\n\n if (!lensCoreJS || !lensCoreWASM) {\n throw new Error(\n `Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +\n `this list: ${assetURLs}.`\n );\n }\n\n // Fetching here and creating an Object URL lets LensCore optimized loading itself in a WebWorker,\n // otherwise the glue script would need to be downloaded again.\n const glueScript = await handler(lensCoreJS).then((r) => r.blob());\n lensCoreJS = URL.createObjectURL(glueScript);\n }\n\n const scriptElement = await loadScript(lensCoreJS);\n\n const lensCore = await new Promise<InitialEmscriptenModule & LensCoreModule>((resolve, reject) => {\n let initialModule: Partial<InitialEmscriptenModule>;\n // will trigger WASM initialization and data loading,\n // after completion it will be safe to call imported WASM functions\n // More about emscripten initialization:\n // eslint-disable-next-line max-len\n // https://emscripten.org/docs/getting_started/FAQ.html?highlight=modularize#how-can-i-tell-when-the-page-is-fully-loaded-and-it-is-safe-to-call-compiled-functions\n const moduleInit = globalThis.createLensesModule(\n (initialModule = {\n // url will be used for loading glue JS during Worker inialization\n mainScriptUrlOrBlob: lensCoreJS,\n // will be triggered by Emscripten during the initialization\n instantiateWasm: (importObject, receiveInstance) => {\n WebAssembly.instantiateStreaming(handler(lensCoreWASM), importObject)\n .then(function ({ instance, module }) {\n receiveInstance(instance, module);\n // compiled module will be reused in Worker\n initialModule.compiledModule = module;\n resolve(moduleInit);\n })\n .catch(reject);\n },\n })\n );\n });\n\n // now when we have LensCore WASM in memory we can release the script element\n scriptElement.remove();\n\n // print warning if loaded version differs from hardcoded one\n if (lensCoreWasm.version != `${lensCore.getCoreVersion()}`) {\n logger.warn(\n `Loaded LensCore version (${lensCore.getCoreVersion()}) differs from expected one (${\n lensCoreWasm.version\n })`\n );\n }\n\n return lensCore;\n }\n);\n"]}
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "209",
3
- "buildNumber": "8",
4
- "baseUrl": "https://cf-st.sc-cdn.net/d/MkroAjRWoH1TVgTCn9VZV?go=IgsKCTIBBEgBUFxgAQ%3D%3D&uc=92"
2
+ "version": "221",
3
+ "buildNumber": "55",
4
+ "baseUrl": "https://cf-st.sc-cdn.net/d/vA3O0DqarC4cIl0WyVKNH?go=IgsKCTIBBEgBUFxgAQ%3D%3D&uc=92"
5
5
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The factory creates new logEntries subject.
3
3
  *
4
- * NOTE: The factory calls `initLogger()`, which overrides the global `logEntrySubject`.
4
+ * NOTE: The factory calls `resetLogger()`, which overrides the global `logEntrySubject`.
5
5
  * This is currently necessary to avoid sharing the same subject between multiple `CameraKit` instances.
6
6
  * In the future, we may throw an error when bootstrapping more than a single `CameraKit`,
7
7
  * that will allow us to have a single log entry subject.
@@ -1,14 +1,14 @@
1
1
  import { Injectable } from "../dependency-injection/Injectable";
2
- import { initLogger } from "./logger";
2
+ import { resetLogger } from "./logger";
3
3
  /**
4
4
  * The factory creates new logEntries subject.
5
5
  *
6
- * NOTE: The factory calls `initLogger()`, which overrides the global `logEntrySubject`.
6
+ * NOTE: The factory calls `resetLogger()`, which overrides the global `logEntrySubject`.
7
7
  * This is currently necessary to avoid sharing the same subject between multiple `CameraKit` instances.
8
8
  * In the future, we may throw an error when bootstrapping more than a single `CameraKit`,
9
9
  * that will allow us to have a single log entry subject.
10
10
  *
11
11
  * @internal
12
12
  */
13
- export const logEntriesFactory = Injectable("logEntries", () => initLogger().asObservable());
13
+ export const logEntriesFactory = Injectable("logEntries", () => resetLogger().asObservable());
14
14
  //# sourceMappingURL=logEntries.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logEntries.js","sourceRoot":"","sources":["../../src/logger/logEntries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { initLogger } from \"./logger\";\n\n/**\n * The factory creates new logEntries subject.\n *\n * NOTE: The factory calls `initLogger()`, which overrides the global `logEntrySubject`.\n * This is currently necessary to avoid sharing the same subject between multiple `CameraKit` instances.\n * In the future, we may throw an error when bootstrapping more than a single `CameraKit`,\n * that will allow us to have a single log entry subject.\n *\n * @internal\n */\nexport const logEntriesFactory = Injectable(\"logEntries\", () => initLogger().asObservable());\n"]}
1
+ {"version":3,"file":"logEntries.js","sourceRoot":"","sources":["../../src/logger/logEntries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { resetLogger } from \"./logger\";\n\n/**\n * The factory creates new logEntries subject.\n *\n * NOTE: The factory calls `resetLogger()`, which overrides the global `logEntrySubject`.\n * This is currently necessary to avoid sharing the same subject between multiple `CameraKit` instances.\n * In the future, we may throw an error when bootstrapping more than a single `CameraKit`,\n * that will allow us to have a single log entry subject.\n *\n * @internal\n */\nexport const logEntriesFactory = Injectable(\"logEntries\", () => resetLogger().asObservable());\n"]}
@@ -12,10 +12,15 @@ export declare const logLevelMap: {
12
12
  debug: number;
13
13
  };
14
14
  /**
15
- * Initializes new logger subject.
15
+ * Initializes a new logger subject.
16
+ *
17
+ * Note: currently only one `CameraKit` instance is allowed to listen to log messages at a time, therefore that is
18
+ * necessary to avoid sharing the same subject between multiple `CameraKit` instances by calling`resetLogger()`.
19
+ * Also, `resetLogger()` should be called when there is no interest in logged messages.
20
+ * This allows the previous logEntriesSubject to be GCec.
16
21
  * @internal
17
22
  */
18
- export declare function initLogger(): Subject<LogEntry>;
23
+ export declare function resetLogger(): Subject<LogEntry>;
19
24
  export interface LogEntry {
20
25
  time: Date;
21
26
  module: string;
@@ -1,8 +1,8 @@
1
1
  import { Subject } from "rxjs";
2
2
  import { entries } from "../common/entries";
3
3
  /**
4
- * The subsject is created and overrdien in initLogger().
5
- * The function has to be called each time new instance of CameraKit is bootstrapped.
4
+ * A reference to the recently created log messages subject.
5
+ * The subject is overridden in resetLogger() method, which is called during CameraKit bootstrapping.
6
6
  */
7
7
  let logEntriesSubject = new Subject();
8
8
  /**
@@ -18,10 +18,15 @@ export const logLevelMap = {
18
18
  debug: 0,
19
19
  };
20
20
  /**
21
- * Initializes new logger subject.
21
+ * Initializes a new logger subject.
22
+ *
23
+ * Note: currently only one `CameraKit` instance is allowed to listen to log messages at a time, therefore that is
24
+ * necessary to avoid sharing the same subject between multiple `CameraKit` instances by calling`resetLogger()`.
25
+ * Also, `resetLogger()` should be called when there is no interest in logged messages.
26
+ * This allows the previous logEntriesSubject to be GCec.
22
27
  * @internal
23
28
  */
24
- export function initLogger() {
29
+ export function resetLogger() {
25
30
  return (logEntriesSubject = new Subject());
26
31
  }
27
32
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;;GAGG;AACH,IAAI,iBAAiB,GAAG,IAAI,OAAO,EAAY,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACX,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,UAAU;IACtB,OAAO,CAAC,iBAAiB,GAAG,IAAI,OAAO,EAAY,CAAC,CAAC;AACzD,CAAC;AAYD;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc;IACpC,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE;QACnD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,QAAe,EAAE,EAAE;YACnC,iBAAiB,CAAC,IAAI,CAAC;gBACnB,IAAI,EAAE,IAAI,IAAI,EAAE;gBAChB,MAAM;gBACN,KAAK;gBACL,QAAQ;aACX,CAAC,CAAC;QACP,CAAC,CAAC;QACF,OAAO,MAAM,CAAC;IAClB,CAAC,EAAE,EAAY,CAAC,CAAC;AACrB,CAAC","sourcesContent":["import { Subject } from \"rxjs\";\nimport { entries } from \"../common/entries\";\n\n/**\n * The subsject is created and overrdien in initLogger().\n * The function has to be called each time new instance of CameraKit is bootstrapped.\n */\nlet logEntriesSubject = new Subject<LogEntry>();\n\n/**\n * This map associates log level names with their corresponding level value.\n * This means that a configured log level will match all log entries with a level value greater than\n * or equal to the configured value.\n */\nexport const logLevelMap = {\n error: 3,\n warn: 2,\n log: 1,\n info: 1,\n debug: 0,\n};\n\n/**\n * Initializes new logger subject.\n * @internal\n */\nexport function initLogger() {\n return (logEntriesSubject = new Subject<LogEntry>());\n}\n\nexport interface LogEntry {\n time: Date;\n module: string;\n level: keyof Logger;\n messages: any[];\n}\n\nexport type LogLevelName = keyof typeof logLevelMap;\nexport type Logger = Record<LogLevelName, (message?: any, ...optionalParams: any[]) => void>;\n\n/**\n * Gets logger for a given module.\n *\n * @internal\n *\n * @param module Module name.\n * @returns Logger instance.\n */\nexport function getLogger(module: string): Logger {\n return entries(logLevelMap).reduce((logger, [level]) => {\n logger[level] = (...messages: any[]) => {\n logEntriesSubject.next({\n time: new Date(),\n module,\n level,\n messages,\n });\n };\n return logger;\n }, {} as Logger);\n}\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;;GAGG;AACH,IAAI,iBAAiB,GAAG,IAAI,OAAO,EAAY,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACX,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW;IACvB,OAAO,CAAC,iBAAiB,GAAG,IAAI,OAAO,EAAY,CAAC,CAAC;AACzD,CAAC;AAYD;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc;IACpC,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE;QACnD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,QAAe,EAAE,EAAE;YACnC,iBAAiB,CAAC,IAAI,CAAC;gBACnB,IAAI,EAAE,IAAI,IAAI,EAAE;gBAChB,MAAM;gBACN,KAAK;gBACL,QAAQ;aACX,CAAC,CAAC;QACP,CAAC,CAAC;QACF,OAAO,MAAM,CAAC;IAClB,CAAC,EAAE,EAAY,CAAC,CAAC;AACrB,CAAC","sourcesContent":["import { Subject } from \"rxjs\";\nimport { entries } from \"../common/entries\";\n\n/**\n * A reference to the recently created log messages subject.\n * The subject is overridden in resetLogger() method, which is called during CameraKit bootstrapping.\n */\nlet logEntriesSubject = new Subject<LogEntry>();\n\n/**\n * This map associates log level names with their corresponding level value.\n * This means that a configured log level will match all log entries with a level value greater than\n * or equal to the configured value.\n */\nexport const logLevelMap = {\n error: 3,\n warn: 2,\n log: 1,\n info: 1,\n debug: 0,\n};\n\n/**\n * Initializes a new logger subject.\n *\n * Note: currently only one `CameraKit` instance is allowed to listen to log messages at a time, therefore that is\n * necessary to avoid sharing the same subject between multiple `CameraKit` instances by calling`resetLogger()`.\n * Also, `resetLogger()` should be called when there is no interest in logged messages.\n * This allows the previous logEntriesSubject to be GCec.\n * @internal\n */\nexport function resetLogger() {\n return (logEntriesSubject = new Subject<LogEntry>());\n}\n\nexport interface LogEntry {\n time: Date;\n module: string;\n level: keyof Logger;\n messages: any[];\n}\n\nexport type LogLevelName = keyof typeof logLevelMap;\nexport type Logger = Record<LogLevelName, (message?: any, ...optionalParams: any[]) => void>;\n\n/**\n * Gets logger for a given module.\n *\n * @internal\n *\n * @param module Module name.\n * @returns Logger instance.\n */\nexport function getLogger(module: string): Logger {\n return entries(logLevelMap).reduce((logger, [level]) => {\n logger[level] = (...messages: any[]) => {\n logEntriesSubject.next({\n time: new Date(),\n module,\n level,\n messages,\n });\n };\n return logger;\n }, {} as Logger);\n}\n"]}
@@ -21,7 +21,7 @@ const getImageBitmap = (imageData, format) => __awaiter(void 0, void 0, void 0,
21
21
  case "nv12":
22
22
  case "yuv":
23
23
  if (!window.VideoFrame)
24
- return Promise.reject(new Error(`Cannot process frame. ImageData in ${format} ` + `is not supported by this browser.`));
24
+ return Promise.reject(new Error(`Cannot process frame. ImageData in ${format} is not supported by this browser.`));
25
25
  const frame = new VideoFrame(imageData.data.buffer, {
26
26
  format: "NV12",
27
27
  codedWidth: imageData.width,
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionSource.js","sourceRoot":"","sources":["../../src/media-sources/FunctionSource.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAqD,MAAM,mBAAmB,CAAC;AAEvG,MAAM,eAAe,GAAG,CAAO,MAAyB,EAAE,QAAwB,EAAsB,EAAE;IACtG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACjC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ameraKitSource, CameraKitSourceOptions, CameraKitSourceSubscriber } from \"./CameraKitSource\";\n\nconst getYUVImageData = async (canvas: HTMLCanvasElement, lensCore: LensCoreModule): Promise<ImageData> => {\n const { width, height } = canvas;\n // A YUV buffer has lower-res UV channels, so the total number of bytes works out like so:\n const outputBuffer = new ArrayBuffer((width * height * 3) / 2);\n await new Promise((onSuccess, onFailure) => {\n lensCore.imageToYuvBuffer({ image: canvas, width, height, outputBuffer, onSuccess, onFailure });\n });\n const pixels = new Uint8ClampedArray(outputBuffer);\n return new ImageData(pixels, width, height);\n};\n\nconst getRGBImageData = (output: HTMLCanvasElement, imageReader2D: CanvasRenderingContext2D | null): ImageData => {\n if (imageReader2D === null) return new ImageData(0, 0);\n imageReader2D.drawImage(output, 0, 0);\n return imageReader2D.getImageData(0, 0, output.width, output.height);\n};\n\nconst getImageBitmap = async (imageData: ImageData, format: FrameFormat): Promise<ImageBitmap> => {\n switch (format) {\n case \"nv12\":\n case \"yuv\":\n if (!window.VideoFrame)\n return Promise.reject(\n new Error(`Cannot process frame. ImageData in ${format} ` + `is not supported by this browser.`)\n );\n const frame = new VideoFrame(imageData.data.buffer, {\n format: \"NV12\",\n codedWidth: imageData.width,\n codedHeight: imageData.height,\n timestamp: 0,\n });\n return createImageBitmap(frame);\n case \"rgb\":\n return createImageBitmap(imageData);\n }\n};\n\n/** @internal */\nexport type FrameFormat = \"rgb\" | \"yuv\" | \"nv12\";\n\n/** @internal */\nexport interface FrameInput {\n format?: FrameFormat;\n imageData: ImageData;\n timestampMillis: number;\n}\n\n/** @internal */\nexport interface FrameOutput {\n live: ImageData;\n capture: ImageData;\n}\n\n/** @internal */\nexport interface MediaSourceFunction {\n (render: (frame: FrameInput) => Promise<FrameOutput>): Promise<void>;\n}\n\n/**\n * Creates a {@link CameraKitSource} from a function which provides per-frame pixel data to CameraKit.\n *\n * @param sourceFunction This function will be called in a requestAnimationFrame loop. Each time it is called, it is\n * passed a `render` function. It may call `render` and CameraKit will process the pixel data passed to `render` and\n * return a Promise of the processed pixels (along with rendering them to the normal output canvases).\n * @param options\n * @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.\n *\n * @internal\n */\nexport const createFunctionSource = (\n sourceFunction: MediaSourceFunction,\n options: Omit<CameraKitSourceOptions, \"fpsLimit\"> = {}\n): CameraKitSource => {\n let width = 0;\n let height = 0;\n let shouldProcessFrame = true;\n\n // We require an auxiliary canvas that we can use to read back pixel data (unless we're in YUV mode, in which case\n // we use LensCore to convert between formats and we don't need this canvas).\n const imageReaderCanvas = document.createElement(\"canvas\");\n const imageReader2D = imageReaderCanvas.getContext(\"2d\");\n\n const subscriber: CameraKitSourceSubscriber = {\n onAttach: (source, lensCore, reportError) => {\n const outputs = lensCore.getOutputCanvases();\n const output = {\n live: outputs[lensCore.CanvasType.Preview.value],\n capture: outputs[lensCore.CanvasType.Capture.value],\n };\n\n const processFrame = (\n source: CameraKitSource,\n lensCore: LensCoreModule,\n reportError: (error: Error) => void\n ) =>\n requestAnimationFrame(async () => {\n if (!shouldProcessFrame) return;\n try {\n await sourceFunction(({ format, imageData, timestampMillis }) => {\n const frameOutput = new Promise<FrameOutput>(async (resolve, reject) => {\n const inputFrame = await getImageBitmap(imageData, format ?? \"rgb\");\n if (inputFrame.width !== width || inputFrame.height !== height) {\n width = imageReaderCanvas.width = inputFrame.width;\n height = imageReaderCanvas.height = inputFrame.height;\n // We don't await this promise, because we want to continue to process frames and\n // let LensCore manage the concurrency between setting resolution and processing a\n // frame.\n source.setRenderSize(width, height);\n }\n lensCore.processFrame({\n inputFrame,\n timestampMillis,\n onSuccess: async () => {\n // Closing releases graphics resources associated with the frame, now that is\n // has been processed.\n inputFrame.close();\n\n switch (format ?? \"rgb\") {\n case \"nv12\":\n case \"yuv\":\n const [live, capture] = await Promise.all([\n getYUVImageData(output.live, lensCore),\n getYUVImageData(output.capture, lensCore),\n ]).catch((error) => {\n reject(error);\n return [undefined, undefined] as const;\n });\n // if either of these is undefined, we'll have already rejected\n // the promise, so we can return.\n if (!live || !capture) return;\n return resolve({ live, capture });\n case \"rgb\":\n return resolve({\n live: getRGBImageData(output.live, imageReader2D),\n capture: getRGBImageData(output.capture, imageReader2D),\n });\n }\n },\n onFailure: (error) => {\n inputFrame.close();\n reject(error);\n },\n });\n });\n // Even if there's an error processing the frame, we do want to attempt to process the next\n // frame. We expect `sourceFunction` to handle a rejected `frameOutput` Promise.\n frameOutput.finally(() => processFrame(source, lensCore, reportError));\n return frameOutput;\n });\n } catch (error) {\n reportError(\n new Error(\n \"Failure to process frame, which was not handled by the provided \" +\n `MediaSourceFunction ${sourceFunction.name ?? \"anonymous\"}.`,\n { cause: error }\n )\n );\n }\n });\n processFrame(source, lensCore, reportError);\n },\n onDetach: () => {\n shouldProcessFrame = false;\n },\n };\n\n return new CameraKitSource({ useManualFrameProcessing: true }, subscriber, options);\n};\n"]}
1
+ {"version":3,"file":"FunctionSource.js","sourceRoot":"","sources":["../../src/media-sources/FunctionSource.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAqD,MAAM,mBAAmB,CAAC;AAEvG,MAAM,eAAe,GAAG,CAAO,MAAyB,EAAE,QAAwB,EAAsB,EAAE;IACtG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACjC,0FAA0F;IAC1F,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,MAAM,IAAI,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE;QACvC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACpG,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACnD,OAAO,IAAI,SAAS,CA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J,CAAC,CAAC;wBACP,CAAC,CAAA,CAAC,CAAC;wBACH,2FAA2F;wBAC3F,gFAAgF;wBAChF,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;wBACvE,OAAO,WAAW,CAAC;oBACvB,CAAC,CAAC,CAAC;iBACN;gBAAC,OAAO,KAAK,EAAE;oBACZ,WAAW,CACP,IAAI,KAAK,CACL,kEAAkE;wBAC9D,uBAAuB,MAAA,cAAc,CAAC,IAAI,mCAAI,WAAW,GAAG,EAChE,EAAE,KAAK,EAAE,KAAK,EAAE,CACnB,CACJ,CAAC;iBACL;YACL,CAAC,CAAA,CAAC,CAAC;YACP,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;QAChD,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE;YACX,kBAAkB,GAAG,KAAK,CAAC;QAC/B,CAAC;KACJ,CAAC;IAEF,OAAO,IAAI,eAAe,CAAC,EAAE,wBAAwB,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACxF,CAAC,CAAC","sourcesContent":["import { LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { CameraKitSource, CameraKitSourceOptions, CameraKitSourceSubscriber } from \"./CameraKitSource\";\n\nconst getYUVImageData = async (canvas: HTMLCanvasElement, lensCore: LensCoreModule): Promise<ImageData> => {\n const { width, height } = canvas;\n // A YUV buffer has lower-res UV channels, so the total number of bytes works out like so:\n const outputBuffer = new ArrayBuffer((width * height * 3) / 2);\n await new Promise((onSuccess, onFailure) => {\n lensCore.imageToYuvBuffer({ image: canvas, width, height, outputBuffer, onSuccess, onFailure });\n });\n const pixels = new Uint8ClampedArray(outputBuffer);\n return new ImageData(pixels, width, height);\n};\n\nconst getRGBImageData = (output: HTMLCanvasElement, imageReader2D: CanvasRenderingContext2D | null): ImageData => {\n if (imageReader2D === null) return new ImageData(0, 0);\n imageReader2D.drawImage(output, 0, 0);\n return imageReader2D.getImageData(0, 0, output.width, output.height);\n};\n\nconst getImageBitmap = async (imageData: ImageData, format: FrameFormat): Promise<ImageBitmap> => {\n switch (format) {\n case \"nv12\":\n case \"yuv\":\n if (!window.VideoFrame)\n return Promise.reject(\n new Error(`Cannot process frame. ImageData in ${format} is not supported by this browser.`)\n );\n const frame = new VideoFrame(imageData.data.buffer, {\n format: \"NV12\",\n codedWidth: imageData.width,\n codedHeight: imageData.height,\n timestamp: 0,\n });\n return createImageBitmap(frame);\n case \"rgb\":\n return createImageBitmap(imageData);\n }\n};\n\n/** @internal */\nexport type FrameFormat = \"rgb\" | \"yuv\" | \"nv12\";\n\n/** @internal */\nexport interface FrameInput {\n format?: FrameFormat;\n imageData: ImageData;\n timestampMillis: number;\n}\n\n/** @internal */\nexport interface FrameOutput {\n live: ImageData;\n capture: ImageData;\n}\n\n/** @internal */\nexport interface MediaSourceFunction {\n (render: (frame: FrameInput) => Promise<FrameOutput>): Promise<void>;\n}\n\n/**\n * Creates a {@link CameraKitSource} from a function which provides per-frame pixel data to CameraKit.\n *\n * @param sourceFunction This function will be called in a requestAnimationFrame loop. Each time it is called, it is\n * passed a `render` function. It may call `render` and CameraKit will process the pixel data passed to `render` and\n * return a Promise of the processed pixels (along with rendering them to the normal output canvases).\n * @param options\n * @param options.cameraType By default we set this to 'front', which is the camera type most Lenses expect.\n *\n * @internal\n */\nexport const createFunctionSource = (\n sourceFunction: MediaSourceFunction,\n options: Omit<CameraKitSourceOptions, \"fpsLimit\"> = {}\n): CameraKitSource => {\n let width = 0;\n let height = 0;\n let shouldProcessFrame = true;\n\n // We require an auxiliary canvas that we can use to read back pixel data (unless we're in YUV mode, in which case\n // we use LensCore to convert between formats and we don't need this canvas).\n const imageReaderCanvas = document.createElement(\"canvas\");\n const imageReader2D = imageReaderCanvas.getContext(\"2d\");\n\n const subscriber: CameraKitSourceSubscriber = {\n onAttach: (source, lensCore, reportError) => {\n const outputs = lensCore.getOutputCanvases();\n const output = {\n live: outputs[lensCore.CanvasType.Preview.value],\n capture: outputs[lensCore.CanvasType.Capture.value],\n };\n\n const processFrame = (\n source: CameraKitSource,\n lensCore: LensCoreModule,\n reportError: (error: Error) => void\n ) =>\n requestAnimationFrame(async () => {\n if (!shouldProcessFrame) return;\n try {\n await sourceFunction(({ format, imageData, timestampMillis }) => {\n const frameOutput = new Promise<FrameOutput>(async (resolve, reject) => {\n const inputFrame = await getImageBitmap(imageData, format ?? \"rgb\");\n if (inputFrame.width !== width || inputFrame.height !== height) {\n width = imageReaderCanvas.width = inputFrame.width;\n height = imageReaderCanvas.height = inputFrame.height;\n // We don't await this promise, because we want to continue to process frames and\n // let LensCore manage the concurrency between setting resolution and processing a\n // frame.\n source.setRenderSize(width, height);\n }\n lensCore.processFrame({\n inputFrame,\n timestampMillis,\n onSuccess: async () => {\n // Closing releases graphics resources associated with the frame, now that is\n // has been processed.\n inputFrame.close();\n\n switch (format ?? \"rgb\") {\n case \"nv12\":\n case \"yuv\":\n const [live, capture] = await Promise.all([\n getYUVImageData(output.live, lensCore),\n getYUVImageData(output.capture, lensCore),\n ]).catch((error) => {\n reject(error);\n return [undefined, undefined] as const;\n });\n // if either of these is undefined, we'll have already rejected\n // the promise, so we can return.\n if (!live || !capture) return;\n return resolve({ live, capture });\n case \"rgb\":\n return resolve({\n live: getRGBImageData(output.live, imageReader2D),\n capture: getRGBImageData(output.capture, imageReader2D),\n });\n }\n },\n onFailure: (error) => {\n inputFrame.close();\n reject(error);\n },\n });\n });\n // Even if there's an error processing the frame, we do want to attempt to process the next\n // frame. We expect `sourceFunction` to handle a rejected `frameOutput` Promise.\n frameOutput.finally(() => processFrame(source, lensCore, reportError));\n return frameOutput;\n });\n } catch (error) {\n reportError(\n new Error(\n \"Failure to process frame, which was not handled by the provided \" +\n `MediaSourceFunction ${sourceFunction.name ?? \"anonymous\"}.`,\n { cause: error }\n )\n );\n }\n });\n processFrame(source, lensCore, reportError);\n },\n onDetach: () => {\n shouldProcessFrame = false;\n },\n };\n\n return new CameraKitSource({ useManualFrameProcessing: true }, subscriber, options);\n};\n"]}
@@ -21,13 +21,17 @@ export interface MediaStreamSourceOptions {
21
21
  * @returns A Promise, resolving to {@link CameraKitSource}
22
22
  *
23
23
  * @category Rendering
24
+ *
25
+ * @deprecated The helper will be removed in one of the future releases.
26
+ * Consumer apps are responsible for acquiring a media stream,
27
+ * which can then be supplied to {@link createMediaStreamSource}.
24
28
  */
25
29
  export declare function createUserMediaSource(constraints?: MediaStreamConstraints, options?: CameraKitSourceOptions<MediaStreamSourceOptions>): Promise<CameraKitSource>;
26
30
  /**
27
31
  * Create a {@link CameraKitSource} from any
28
32
  * [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).
29
33
  *
30
- * @param stream Any MediaStream, such as obtained via `canvas.captureStream()`
34
+ * @param stream Any MediaStream, such as obtained via `canvas.captureStream()` or `mediaDevices.getUserMedia()`.
31
35
  * @param options
32
36
  * @param options.transform We apply no transformation by default.
33
37
  * @param options.disableSourceAudio By default we pass audio to lens. Settings this to true will disable sending audio
@@ -12,6 +12,13 @@ function closeWorklet(worklet) {
12
12
  worklet.port.onmessage = null;
13
13
  worklet.disconnect();
14
14
  }
15
+ function closeAudioContext(audioContext) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ if (!audioContext || audioContext.state === "closed")
18
+ return;
19
+ return audioContext.close();
20
+ });
21
+ }
15
22
  /**
16
23
  * Create a {@link CameraKitSource} from a user's media device -- this calls
17
24
  * [MediaDevices.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) to get a
@@ -28,6 +35,10 @@ function closeWorklet(worklet) {
28
35
  * @returns A Promise, resolving to {@link CameraKitSource}
29
36
  *
30
37
  * @category Rendering
38
+ *
39
+ * @deprecated The helper will be removed in one of the future releases.
40
+ * Consumer apps are responsible for acquiring a media stream,
41
+ * which can then be supplied to {@link createMediaStreamSource}.
31
42
  */
32
43
  export function createUserMediaSource(constraints = { video: true }, options = {}) {
33
44
  return __awaiter(this, void 0, void 0, function* () {
@@ -39,7 +50,7 @@ export function createUserMediaSource(constraints = { video: true }, options = {
39
50
  * Create a {@link CameraKitSource} from any
40
51
  * [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).
41
52
  *
42
- * @param stream Any MediaStream, such as obtained via `canvas.captureStream()`
53
+ * @param stream Any MediaStream, such as obtained via `canvas.captureStream()` or `mediaDevices.getUserMedia()`.
43
54
  * @param options
44
55
  * @param options.transform We apply no transformation by default.
45
56
  * @param options.disableSourceAudio By default we pass audio to lens. Settings this to true will disable sending audio
@@ -99,7 +110,7 @@ export function createMediaStreamSource(stream, options = {}) {
99
110
  // To ensure there are not leaks, it is better to close any existing connections.
100
111
  closeWorklet(worklet);
101
112
  audioSource === null || audioSource === void 0 ? void 0 : audioSource.disconnect();
102
- yield (audioContext === null || audioContext === void 0 ? void 0 : audioContext.close());
113
+ yield closeAudioContext(audioContext);
103
114
  }
104
115
  catch (error) {
105
116
  // We still want to continue if anything above failed
@@ -155,9 +166,7 @@ export function createMediaStreamSource(stream, options = {}) {
155
166
  audioSource = undefined;
156
167
  }
157
168
  if (audioContext) {
158
- yield audioContext.close().catch((error) => {
159
- reportError(error);
160
- });
169
+ yield closeAudioContext(audioContext).catch(reportError);
161
170
  audioContext = undefined;
162
171
  }
163
172
  }),
@@ -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,Y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,CAAC,KAAY,EAAE,EAAE;wCACxB,WAAW,CAAC,KAAK,CAAC,CAAC;oCACvB,CAAC;iCACJ,CAAC,CAAC;6BACN;wBACL,CAAC,CAAC;qBACL;gBACL,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;oBACpB,WAAW,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC,CAAC,CAAC;aACV;QACL,CAAC,CAAA;QACD,QAAQ,EAAE,CAAO,WAAW,EAAE,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,YAAY,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;oBAC9C,WAAW,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC,CAAC,CAAC;gBACH,YAAY,GAAG,SAAS,CAAC;aAC5B;QACL,CAAC,CAAA;KACJ,EACD,OAAO,CACV,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.onmessage = null;\n worklet.disconnect();\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 */\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()`\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 'front', 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 optionsNotNull = {\n ...defaultOptions,\n ...options,\n };\n\n const { width, height } =\n stream.getVideoTracks().length > 0 ? stream.getVideoTracks()[0].getSettings() : { width: 0, height: 0 };\n const enableSourceAudio: boolean = stream.getAudioTracks().length > 0 && !optionsNotNull.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(optionsNotNull.transform);\n\n if (enableSourceAudio) {\n // Audio paramters set has to be called before lens is applied\n lensCore.setAudioParameters({\n parameters: {\n numChannels: simulateStereoAudio ? 2 : 1,\n sampleRate,\n },\n onFailure: (error: Error) => {\n reportError(error);\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 audioContext?.close();\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 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({\n input: inputBuffers,\n onFailure: (error: Error) => {\n reportError(error);\n },\n });\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 audioContext.close().catch((error: Error) => {\n reportError(error);\n });\n audioContext = undefined;\n }\n },\n },\n options\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,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,CA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AY,EAAE,EAAE;oBACpB,WAAW,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC,CAAC,CAAC;aACV;QACL,CAAC,CAAA;QACD,QAAQ,EAAE,CAAO,WAAW,EAAE,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,OAAO,CACV,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.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 'front', 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 optionsNotNull = {\n ...defaultOptions,\n ...options,\n };\n\n const { width, height } =\n stream.getVideoTracks().length > 0 ? stream.getVideoTracks()[0].getSettings() : { width: 0, height: 0 };\n const enableSourceAudio: boolean = stream.getAudioTracks().length > 0 && !optionsNotNull.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(optionsNotNull.transform);\n\n if (enableSourceAudio) {\n // Audio paramters set has to be called before lens is applied\n lensCore.setAudioParameters({\n parameters: {\n numChannels: simulateStereoAudio ? 2 : 1,\n sampleRate,\n },\n onFailure: (error: Error) => {\n reportError(error);\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 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({\n input: inputBuffers,\n onFailure: (error: Error) => {\n reportError(error);\n },\n });\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 options\n );\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { FetchHandler } from "../handlers/defaultFetchHandler";
2
2
  import * as blizzard from "../generated-proto/blizzard/cameraKitEvents";
3
+ import { PageVisibility } from "../common/pageVisibility";
3
4
  import { MetricsEventTarget } from "./metricsEventTarget";
4
5
  /**
5
6
  * Translate between an external metric name, which is exposed to SDK users, and an internal Blizzard event name,
@@ -30,8 +31,8 @@ export type MakeTaggedBusinessEvent<K extends keyof CameraKitBusinessEventMap> =
30
31
  name: K;
31
32
  } & CameraKitBusinessEventMap[K];
32
33
  export declare const businessEventsReporterFactory: {
33
- (args_0: MetricsEventTarget, args_1: FetchHandler): void;
34
+ (args_0: MetricsEventTarget, args_1: FetchHandler, args_2: PageVisibility): void;
34
35
  token: "businessEventsReporter";
35
- dependencies: readonly ["metricsEventTarget", "metricsHandler"];
36
+ dependencies: readonly ["metricsEventTarget", "metricsHandler", "pageVisibility"];
36
37
  };
37
38
  export {};