@snap/camera-kit 0.7.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 (554) hide show
  1. package/LICENSE.md +6247 -0
  2. package/README.md +166 -0
  3. package/docs/html/.nojekyll +1 -0
  4. package/docs/html/assets/highlight.css +106 -0
  5. package/docs/html/assets/main.js +54 -0
  6. package/docs/html/assets/search.js +1 -0
  7. package/docs/html/assets/style.css +1225 -0
  8. package/docs/html/assets/widgets.png +0 -0
  9. package/docs/html/assets/widgets@2x.png +0 -0
  10. package/docs/html/classes/CameraKit.html +121 -0
  11. package/docs/html/classes/CameraKitSession.html +347 -0
  12. package/docs/html/classes/CameraKitSource.html +152 -0
  13. package/docs/html/classes/LensPerformanceMeasurement.html +115 -0
  14. package/docs/html/classes/LensPerformanceMetrics.html +76 -0
  15. package/docs/html/classes/LensRepository.html +171 -0
  16. package/docs/html/classes/LensSources.html +82 -0
  17. package/docs/html/classes/Transform2D.html +99 -0
  18. package/docs/html/classes/TypedCustomEvent.html +109 -0
  19. package/docs/html/classes/TypedEventTarget.html +146 -0
  20. package/docs/html/functions/Injectable.html +193 -0
  21. package/docs/html/functions/bootstrapCameraKit.html +158 -0
  22. package/docs/html/functions/createExtension.html +127 -0
  23. package/docs/html/functions/createImageSource.html +123 -0
  24. package/docs/html/functions/createMediaStreamSource.html +123 -0
  25. package/docs/html/functions/createUserMediaSource.html +127 -0
  26. package/docs/html/functions/createVideoSource.html +124 -0
  27. package/docs/html/functions/estimateLensPerformance.html +116 -0
  28. package/docs/html/functions/getRequiredBootstrapURLs.html +124 -0
  29. package/docs/html/functions/lensSourcesFactory.html +116 -0
  30. package/docs/html/functions/uriHandlersFactory.html +118 -0
  31. package/docs/html/index.html +208 -0
  32. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +132 -0
  33. package/docs/html/interfaces/CameraKitSourceSubscriber.html +121 -0
  34. package/docs/html/interfaces/ComputedFrameMetrics.html +70 -0
  35. package/docs/html/interfaces/CreateSessionOptions.html +77 -0
  36. package/docs/html/interfaces/EstimatedLensPerformance.html +78 -0
  37. package/docs/html/interfaces/Lens.html +115 -0
  38. package/docs/html/interfaces/LensSource.html +113 -0
  39. package/docs/html/interfaces/MediaStreamSourceOptions.html +65 -0
  40. package/docs/html/interfaces/UriCancelRequest.html +65 -0
  41. package/docs/html/interfaces/UriHandler.html +128 -0
  42. package/docs/html/interfaces/UriRequest.html +80 -0
  43. package/docs/html/interfaces/UriResponse.html +80 -0
  44. package/docs/html/interfaces/VideoSourceOptions.html +60 -0
  45. package/docs/html/modules.html +198 -0
  46. package/docs/html/types/AssetLoader.html +126 -0
  47. package/docs/html/types/AssetTiming.html +116 -0
  48. package/docs/html/types/BenchmarkError.html +107 -0
  49. package/docs/html/types/BootstrapError.html +110 -0
  50. package/docs/html/types/CacheKeyNotFoundError.html +107 -0
  51. package/docs/html/types/CameraKitDeviceInfo.html +114 -0
  52. package/docs/html/types/CameraKitSessionEventListener.html +109 -0
  53. package/docs/html/types/CameraKitSessionEvents.html +118 -0
  54. package/docs/html/types/CameraKitSourceError.html +107 -0
  55. package/docs/html/types/CameraKitSourceInfo.html +107 -0
  56. package/docs/html/types/CameraKitSourceOptions.html +113 -0
  57. package/docs/html/types/ConfigurationError.html +109 -0
  58. package/docs/html/types/Keyboard.html +196 -0
  59. package/docs/html/types/KeyboardEvents.html +109 -0
  60. package/docs/html/types/LegalError.html +107 -0
  61. package/docs/html/types/LensAssetError.html +109 -0
  62. package/docs/html/types/LensContentValidationError.html +107 -0
  63. package/docs/html/types/LensError.html +107 -0
  64. package/docs/html/types/LensExecutionError.html +114 -0
  65. package/docs/html/types/LensImagePickerError.html +110 -0
  66. package/docs/html/types/LensLaunchParams.html +109 -0
  67. package/docs/html/types/LensMetricsEvents.html +110 -0
  68. package/docs/html/types/LensPerformanceCluster.html +107 -0
  69. package/docs/html/types/LensView.html +119 -0
  70. package/docs/html/types/LensWait.html +111 -0
  71. package/docs/html/types/PersistentStoreError.html +109 -0
  72. package/docs/html/types/PlatformNotSupportedError.html +110 -0
  73. package/docs/html/types/PublicContainer.html +110 -0
  74. package/docs/html/types/RenderTarget.html +111 -0
  75. package/docs/html/types/Uri.html +107 -0
  76. package/docs/html/types/UriHandlers.html +109 -0
  77. package/docs/html/types/WebGLError.html +107 -0
  78. package/docs/html/variables/extensionRequestContext.html +109 -0
  79. package/docs/md/.nojekyll +1 -0
  80. package/docs/md/README.md +168 -0
  81. package/docs/md/classes/CameraKit.md +94 -0
  82. package/docs/md/classes/CameraKitSession.md +359 -0
  83. package/docs/md/classes/CameraKitSource.md +110 -0
  84. package/docs/md/classes/LensPerformanceMeasurement.md +77 -0
  85. package/docs/md/classes/LensPerformanceMetrics.md +37 -0
  86. package/docs/md/classes/LensRepository.md +145 -0
  87. package/docs/md/classes/LensSources.md +29 -0
  88. package/docs/md/classes/Transform2D.md +55 -0
  89. package/docs/md/classes/TypedCustomEvent.md +65 -0
  90. package/docs/md/classes/TypedEventTarget.md +103 -0
  91. package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +106 -0
  92. package/docs/md/interfaces/CameraKitSourceSubscriber.md +55 -0
  93. package/docs/md/interfaces/ComputedFrameMetrics.md +29 -0
  94. package/docs/md/interfaces/CreateSessionOptions.md +35 -0
  95. package/docs/md/interfaces/EstimatedLensPerformance.md +38 -0
  96. package/docs/md/interfaces/Lens.md +84 -0
  97. package/docs/md/interfaces/LensSource.md +68 -0
  98. package/docs/md/interfaces/MediaStreamSourceOptions.md +22 -0
  99. package/docs/md/interfaces/UriCancelRequest.md +22 -0
  100. package/docs/md/interfaces/UriHandler.md +63 -0
  101. package/docs/md/interfaces/UriRequest.md +43 -0
  102. package/docs/md/interfaces/UriResponse.md +43 -0
  103. package/docs/md/interfaces/VideoSourceOptions.md +15 -0
  104. package/docs/md/modules.md +827 -0
  105. package/lib/CameraKit.d.ts +170 -0
  106. package/lib/CameraKit.js +145 -0
  107. package/lib/CameraKit.js.map +1 -0
  108. package/lib/__tests__/data.d.ts +9 -0
  109. package/lib/__tests__/data.js +50 -0
  110. package/lib/__tests__/data.js.map +1 -0
  111. package/lib/__tests__/deferred.d.ts +16 -0
  112. package/lib/__tests__/deferred.js +29 -0
  113. package/lib/__tests__/deferred.js.map +1 -0
  114. package/lib/__tests__/jest.matchers.d.ts +17 -0
  115. package/lib/__tests__/jest.matchers.js +67 -0
  116. package/lib/__tests__/jest.matchers.js.map +1 -0
  117. package/lib/assertPlatformSupported.d.ts +4 -0
  118. package/lib/assertPlatformSupported.js +10 -0
  119. package/lib/assertPlatformSupported.js.map +1 -0
  120. package/lib/benchmark/benchmarkGflops.d.ts +16 -0
  121. package/lib/benchmark/benchmarkGflops.js +129 -0
  122. package/lib/benchmark/benchmarkGflops.js.map +1 -0
  123. package/lib/benchmark/estimateLensPerformanceCluster.d.ts +33 -0
  124. package/lib/benchmark/estimateLensPerformanceCluster.js +48 -0
  125. package/lib/benchmark/estimateLensPerformanceCluster.js.map +1 -0
  126. package/lib/benchmark/webglUtils.d.ts +7 -0
  127. package/lib/benchmark/webglUtils.js +87 -0
  128. package/lib/benchmark/webglUtils.js.map +1 -0
  129. package/lib/bootstrapCameraKit.d.ts +96 -0
  130. package/lib/bootstrapCameraKit.js +204 -0
  131. package/lib/bootstrapCameraKit.js.map +1 -0
  132. package/lib/common/__mocks__/loadScript.d.ts +1 -0
  133. package/lib/common/__mocks__/loadScript.js +10 -0
  134. package/lib/common/__mocks__/loadScript.js.map +1 -0
  135. package/lib/common/assertions.d.ts +27 -0
  136. package/lib/common/assertions.js +39 -0
  137. package/lib/common/assertions.js.map +1 -0
  138. package/lib/common/cameraKitUserAgent.d.ts +34 -0
  139. package/lib/common/cameraKitUserAgent.js +216 -0
  140. package/lib/common/cameraKitUserAgent.js.map +1 -0
  141. package/lib/common/copyDefinedProperties.d.ts +13 -0
  142. package/lib/common/copyDefinedProperties.js +16 -0
  143. package/lib/common/copyDefinedProperties.js.map +1 -0
  144. package/lib/common/entries.d.ts +3 -0
  145. package/lib/common/entries.js +3 -0
  146. package/lib/common/entries.js.map +1 -0
  147. package/lib/common/errorHelpers.d.ts +10 -0
  148. package/lib/common/errorHelpers.js +24 -0
  149. package/lib/common/errorHelpers.js.map +1 -0
  150. package/lib/common/getFilename.d.ts +1 -0
  151. package/lib/common/getFilename.js +4 -0
  152. package/lib/common/getFilename.js.map +1 -0
  153. package/lib/common/index.d.ts +2 -0
  154. package/lib/common/index.js +3 -0
  155. package/lib/common/index.js.map +1 -0
  156. package/lib/common/loadScript.d.ts +1 -0
  157. package/lib/common/loadScript.js +11 -0
  158. package/lib/common/loadScript.js.map +1 -0
  159. package/lib/common/locale.d.ts +2 -0
  160. package/lib/common/locale.js +11 -0
  161. package/lib/common/locale.js.map +1 -0
  162. package/lib/common/localization.d.ts +43 -0
  163. package/lib/common/localization.js +43 -0
  164. package/lib/common/localization.js.map +1 -0
  165. package/lib/common/memoize.d.ts +8 -0
  166. package/lib/common/memoize.js +15 -0
  167. package/lib/common/memoize.js.map +1 -0
  168. package/lib/common/pageVisibility.d.ts +20 -0
  169. package/lib/common/pageVisibility.js +62 -0
  170. package/lib/common/pageVisibility.js.map +1 -0
  171. package/lib/common/time.d.ts +1 -0
  172. package/lib/common/time.js +2 -0
  173. package/lib/common/time.js.map +1 -0
  174. package/lib/common/typeguards.d.ts +53 -0
  175. package/lib/common/typeguards.js +92 -0
  176. package/lib/common/typeguards.js.map +1 -0
  177. package/lib/common/types.d.ts +10 -0
  178. package/lib/common/types.js +2 -0
  179. package/lib/common/types.js.map +1 -0
  180. package/lib/common/validate.d.ts +14 -0
  181. package/lib/common/validate.js +104 -0
  182. package/lib/common/validate.js.map +1 -0
  183. package/lib/configuration.d.ts +92 -0
  184. package/lib/configuration.js +36 -0
  185. package/lib/configuration.js.map +1 -0
  186. package/lib/configurationOverrides.d.ts +12 -0
  187. package/lib/configurationOverrides.js +41 -0
  188. package/lib/configurationOverrides.js.map +1 -0
  189. package/lib/dependency-injection/Container.d.ts +177 -0
  190. package/lib/dependency-injection/Container.js +160 -0
  191. package/lib/dependency-injection/Container.js.map +1 -0
  192. package/lib/dependency-injection/Injectable.d.ts +39 -0
  193. package/lib/dependency-injection/Injectable.js +18 -0
  194. package/lib/dependency-injection/Injectable.js.map +1 -0
  195. package/lib/dependency-injection/PartialContainer.d.ts +81 -0
  196. package/lib/dependency-injection/PartialContainer.js +85 -0
  197. package/lib/dependency-injection/PartialContainer.js.map +1 -0
  198. package/lib/dependency-injection/RootServices.d.ts +62 -0
  199. package/lib/dependency-injection/RootServices.js +2 -0
  200. package/lib/dependency-injection/RootServices.js.map +1 -0
  201. package/lib/dependency-injection/types.d.ts +56 -0
  202. package/lib/dependency-injection/types.js +2 -0
  203. package/lib/dependency-injection/types.js.map +1 -0
  204. package/lib/environment.json +1 -0
  205. package/lib/events/TypedCustomEvent.d.ts +10 -0
  206. package/lib/events/TypedCustomEvent.js +11 -0
  207. package/lib/events/TypedCustomEvent.js.map +1 -0
  208. package/lib/events/TypedEventTarget.d.ts +25 -0
  209. package/lib/events/TypedEventTarget.js +57 -0
  210. package/lib/events/TypedEventTarget.js.map +1 -0
  211. package/lib/events/scan.d.ts +15 -0
  212. package/lib/events/scan.js +46 -0
  213. package/lib/events/scan.js.map +1 -0
  214. package/lib/extensions/LensSources.d.ts +58 -0
  215. package/lib/extensions/LensSources.js +50 -0
  216. package/lib/extensions/LensSources.js.map +1 -0
  217. package/lib/extensions/UriHandlers.d.ts +54 -0
  218. package/lib/extensions/UriHandlers.js +93 -0
  219. package/lib/extensions/UriHandlers.js.map +1 -0
  220. package/lib/extensions/extensionRequestContext.d.ts +4 -0
  221. package/lib/extensions/extensionRequestContext.js +14 -0
  222. package/lib/extensions/extensionRequestContext.js.map +1 -0
  223. package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +5603 -0
  224. package/lib/generated-proto/blizzard/cameraKitEvents.js +522 -0
  225. package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -0
  226. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +98 -0
  227. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +260 -0
  228. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -0
  229. package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +543 -0
  230. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +429 -0
  231. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -0
  232. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +100 -0
  233. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +164 -0
  234. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -0
  235. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +395 -0
  236. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +644 -0
  237. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -0
  238. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +185 -0
  239. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +172 -0
  240. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -0
  241. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +86 -0
  242. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +234 -0
  243. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -0
  244. package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +854 -0
  245. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +629 -0
  246. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -0
  247. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +86 -0
  248. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js +185 -0
  249. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js.map +1 -0
  250. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.d.ts +95 -0
  251. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js +104 -0
  252. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js.map +1 -0
  253. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +10212 -0
  254. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +1300 -0
  255. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -0
  256. package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +401 -0
  257. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js +525 -0
  258. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -0
  259. package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +1287 -0
  260. package/lib/generated-proto/pb_schema/cdp/cof/config_response.js +135 -0
  261. package/lib/generated-proto/pb_schema/cdp/cof/config_response.js.map +1 -0
  262. package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4208 -0
  263. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +1053 -0
  264. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -0
  265. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.d.ts +102 -0
  266. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js +165 -0
  267. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js.map +1 -0
  268. package/lib/generated-proto/pb_schema/cdp/cof/namespace.d.ts +8 -0
  269. package/lib/generated-proto/pb_schema/cdp/cof/namespace.js +17 -0
  270. package/lib/generated-proto/pb_schema/cdp/cof/namespace.js.map +1 -0
  271. package/lib/generated-proto/pb_schema/common/ruid.d.ts +75 -0
  272. package/lib/generated-proto/pb_schema/common/ruid.js +96 -0
  273. package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -0
  274. package/lib/generated-proto/pb_schema/common/value.d.ts +131 -0
  275. package/lib/generated-proto/pb_schema/common/value.js +204 -0
  276. package/lib/generated-proto/pb_schema/common/value.js.map +1 -0
  277. package/lib/generated-proto/pb_schema/google/api/annotations.d.ts +1 -0
  278. package/lib/generated-proto/pb_schema/google/api/annotations.js +9 -0
  279. package/lib/generated-proto/pb_schema/google/api/annotations.js.map +1 -0
  280. package/lib/generated-proto/pb_schema/google/api/http.d.ts +3636 -0
  281. package/lib/generated-proto/pb_schema/google/api/http.js +271 -0
  282. package/lib/generated-proto/pb_schema/google/api/http.js.map +1 -0
  283. package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +139 -0
  284. package/lib/generated-proto/pb_schema/google/protobuf/any.js +94 -0
  285. package/lib/generated-proto/pb_schema/google/protobuf/any.js.map +1 -0
  286. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +50968 -0
  287. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +2962 -0
  288. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -0
  289. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +98 -0
  290. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js +82 -0
  291. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js.map +1 -0
  292. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +173 -0
  293. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js +332 -0
  294. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js.map +1 -0
  295. package/lib/generated-proto/pb_schema/lenses/geocircle.d.ts +42 -0
  296. package/lib/generated-proto/pb_schema/lenses/geocircle.js +52 -0
  297. package/lib/generated-proto/pb_schema/lenses/geocircle.js.map +1 -0
  298. package/lib/generated-proto/pb_schema/lenses/geopoint.d.ts +32 -0
  299. package/lib/generated-proto/pb_schema/lenses/geopoint.js +50 -0
  300. package/lib/generated-proto/pb_schema/lenses/geopoint.js.map +1 -0
  301. package/lib/generated-proto/pb_schema/lenses/launch_params.d.ts +29 -0
  302. package/lib/generated-proto/pb_schema/lenses/launch_params.js +43 -0
  303. package/lib/generated-proto/pb_schema/lenses/launch_params.js.map +1 -0
  304. package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +365 -0
  305. package/lib/generated-proto/pb_schema/lenses/launchdata.js +216 -0
  306. package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -0
  307. package/lib/generated-proto/pb_schema/lenses/lures.d.ts +113 -0
  308. package/lib/generated-proto/pb_schema/lenses/lures.js +64 -0
  309. package/lib/generated-proto/pb_schema/lenses/lures.js.map +1 -0
  310. package/lib/generated-proto/pb_schema/lenses/persistent_store.d.ts +29 -0
  311. package/lib/generated-proto/pb_schema/lenses/persistent_store.js +43 -0
  312. package/lib/generated-proto/pb_schema/lenses/persistent_store.js.map +1 -0
  313. package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +921 -0
  314. package/lib/generated-proto/pb_schema/lenses/snappable.js +954 -0
  315. package/lib/generated-proto/pb_schema/lenses/snappable.js.map +1 -0
  316. package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +247 -0
  317. package/lib/generated-proto/pb_schema/lenses/user_data.js +362 -0
  318. package/lib/generated-proto/pb_schema/lenses/user_data.js.map +1 -0
  319. package/lib/handlers/HandlerChainBuilder.d.ts +95 -0
  320. package/lib/handlers/HandlerChainBuilder.js +187 -0
  321. package/lib/handlers/HandlerChainBuilder.js.map +1 -0
  322. package/lib/handlers/arrayBufferParsingHandler.d.ts +10 -0
  323. package/lib/handlers/arrayBufferParsingHandler.js +18 -0
  324. package/lib/handlers/arrayBufferParsingHandler.js.map +1 -0
  325. package/lib/handlers/batchingHandler.d.ts +25 -0
  326. package/lib/handlers/batchingHandler.js +79 -0
  327. package/lib/handlers/batchingHandler.js.map +1 -0
  328. package/lib/handlers/cameraKitServiceFetchHandlerFactory.d.ts +12 -0
  329. package/lib/handlers/cameraKitServiceFetchHandlerFactory.js +19 -0
  330. package/lib/handlers/cameraKitServiceFetchHandlerFactory.js.map +1 -0
  331. package/lib/handlers/debugHandler.d.ts +8 -0
  332. package/lib/handlers/debugHandler.js +27 -0
  333. package/lib/handlers/debugHandler.js.map +1 -0
  334. package/lib/handlers/defaultFetchHandler.d.ts +15 -0
  335. package/lib/handlers/defaultFetchHandler.js +29 -0
  336. package/lib/handlers/defaultFetchHandler.js.map +1 -0
  337. package/lib/handlers/headersModifyingFetchHandler.d.ts +8 -0
  338. package/lib/handlers/headersModifyingFetchHandler.js +13 -0
  339. package/lib/handlers/headersModifyingFetchHandler.js.map +1 -0
  340. package/lib/handlers/index.d.ts +2 -0
  341. package/lib/handlers/index.js +3 -0
  342. package/lib/handlers/index.js.map +1 -0
  343. package/lib/handlers/mappingHandler.d.ts +15 -0
  344. package/lib/handlers/mappingHandler.js +65 -0
  345. package/lib/handlers/mappingHandler.js.map +1 -0
  346. package/lib/handlers/noCorsRetryingFetchHandler.d.ts +48 -0
  347. package/lib/handlers/noCorsRetryingFetchHandler.js +94 -0
  348. package/lib/handlers/noCorsRetryingFetchHandler.js.map +1 -0
  349. package/lib/handlers/persistingHandler.d.ts +14 -0
  350. package/lib/handlers/persistingHandler.js +71 -0
  351. package/lib/handlers/persistingHandler.js.map +1 -0
  352. package/lib/handlers/rateLimitingHandler.d.ts +20 -0
  353. package/lib/handlers/rateLimitingHandler.js +43 -0
  354. package/lib/handlers/rateLimitingHandler.js.map +1 -0
  355. package/lib/handlers/requestStateEmittingHandler.d.ts +29 -0
  356. package/lib/handlers/requestStateEmittingHandler.js +43 -0
  357. package/lib/handlers/requestStateEmittingHandler.js.map +1 -0
  358. package/lib/handlers/responseCachingHandler.d.ts +27 -0
  359. package/lib/handlers/responseCachingHandler.js +94 -0
  360. package/lib/handlers/responseCachingHandler.js.map +1 -0
  361. package/lib/handlers/retryingHandler.d.ts +37 -0
  362. package/lib/handlers/retryingHandler.js +73 -0
  363. package/lib/handlers/retryingHandler.js.map +1 -0
  364. package/lib/handlers/timeoutHandler.d.ts +18 -0
  365. package/lib/handlers/timeoutHandler.js +30 -0
  366. package/lib/handlers/timeoutHandler.js.map +1 -0
  367. package/lib/index.d.ts +33 -0
  368. package/lib/index.js +32 -0
  369. package/lib/index.js.map +1 -0
  370. package/lib/legal/legalPrompt.d.ts +17 -0
  371. package/lib/legal/legalPrompt.js +144 -0
  372. package/lib/legal/legalPrompt.js.map +1 -0
  373. package/lib/legal/legalState.d.ts +50 -0
  374. package/lib/legal/legalState.js +149 -0
  375. package/lib/legal/legalState.js.map +1 -0
  376. package/lib/lens/Lens.d.ts +71 -0
  377. package/lib/lens/Lens.js +63 -0
  378. package/lib/lens/Lens.js.map +1 -0
  379. package/lib/lens/LensLaunchParams.d.ts +19 -0
  380. package/lib/lens/LensLaunchParams.js +38 -0
  381. package/lib/lens/LensLaunchParams.js.map +1 -0
  382. package/lib/lens/LensPersistenceStore.d.ts +7 -0
  383. package/lib/lens/LensPersistenceStore.js +20 -0
  384. package/lib/lens/LensPersistenceStore.js.map +1 -0
  385. package/lib/lens/LensRepository.d.ts +134 -0
  386. package/lib/lens/LensRepository.js +239 -0
  387. package/lib/lens/LensRepository.js.map +1 -0
  388. package/lib/lens/assets/LensAssetRepository.d.ts +66 -0
  389. package/lib/lens/assets/LensAssetRepository.js +179 -0
  390. package/lib/lens/assets/LensAssetRepository.js.map +1 -0
  391. package/lib/lens/assets/LensAssetsProvider.d.ts +21 -0
  392. package/lib/lens/assets/LensAssetsProvider.js +41 -0
  393. package/lib/lens/assets/LensAssetsProvider.js.map +1 -0
  394. package/lib/lens/assets/deviceDependentAssetLoader.d.ts +11 -0
  395. package/lib/lens/assets/deviceDependentAssetLoader.js +58 -0
  396. package/lib/lens/assets/deviceDependentAssetLoader.js.map +1 -0
  397. package/lib/lens/assets/remoteMediaAssetLoaderFactory.d.ts +10 -0
  398. package/lib/lens/assets/remoteMediaAssetLoaderFactory.js +26 -0
  399. package/lib/lens/assets/remoteMediaAssetLoaderFactory.js.map +1 -0
  400. package/lib/lens/assets/staticAssetLoader.d.ts +10 -0
  401. package/lib/lens/assets/staticAssetLoader.js +24 -0
  402. package/lib/lens/assets/staticAssetLoader.js.map +1 -0
  403. package/lib/lens/index.d.ts +7 -0
  404. package/lib/lens/index.js +7 -0
  405. package/lib/lens/index.js.map +1 -0
  406. package/lib/lens/lensEnvelopeUtil.d.ts +5 -0
  407. package/lib/lens/lensEnvelopeUtil.js +19 -0
  408. package/lib/lens/lensEnvelopeUtil.js.map +1 -0
  409. package/lib/lens/lensHttpUtil.d.ts +4 -0
  410. package/lib/lens/lensHttpUtil.js +30 -0
  411. package/lib/lens/lensHttpUtil.js.map +1 -0
  412. package/lib/lens-client-interface/exif.d.ts +20 -0
  413. package/lib/lens-client-interface/exif.js +61 -0
  414. package/lib/lens-client-interface/exif.js.map +1 -0
  415. package/lib/lens-client-interface/imagePicker.d.ts +7 -0
  416. package/lib/lens-client-interface/imagePicker.js +128 -0
  417. package/lib/lens-client-interface/imagePicker.js.map +1 -0
  418. package/lib/lens-client-interface/lensClientInterface.d.ts +13 -0
  419. package/lib/lens-client-interface/lensClientInterface.js +30 -0
  420. package/lib/lens-client-interface/lensClientInterface.js.map +1 -0
  421. package/lib/lens-core-module/generated-types.d.ts +426 -0
  422. package/lib/lens-core-module/generated-types.js +2 -0
  423. package/lib/lens-core-module/generated-types.js.map +1 -0
  424. package/lib/lens-core-module/index.d.ts +2 -0
  425. package/lib/lens-core-module/index.js +3 -0
  426. package/lib/lens-core-module/index.js.map +1 -0
  427. package/lib/lens-core-module/loader/index.d.ts +1 -0
  428. package/lib/lens-core-module/loader/index.js +2 -0
  429. package/lib/lens-core-module/loader/index.js.map +1 -0
  430. package/lib/lens-core-module/loader/lensCoreFactory.d.ts +30 -0
  431. package/lib/lens-core-module/loader/lensCoreFactory.js +121 -0
  432. package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -0
  433. package/lib/lensCoreWasmVersions.json +5 -0
  434. package/lib/logger/errorLoggingDecorator.d.ts +9 -0
  435. package/lib/logger/errorLoggingDecorator.js +32 -0
  436. package/lib/logger/errorLoggingDecorator.js.map +1 -0
  437. package/lib/logger/logEntries.d.ts +15 -0
  438. package/lib/logger/logEntries.js +14 -0
  439. package/lib/logger/logEntries.js.map +1 -0
  440. package/lib/logger/logger.d.ts +35 -0
  441. package/lib/logger/logger.js +48 -0
  442. package/lib/logger/logger.js.map +1 -0
  443. package/lib/logger/registerLogEntriesSubscriber.d.ts +14 -0
  444. package/lib/logger/registerLogEntriesSubscriber.js +23 -0
  445. package/lib/logger/registerLogEntriesSubscriber.js.map +1 -0
  446. package/lib/media-sources/CameraKitSource.d.ts +88 -0
  447. package/lib/media-sources/CameraKitSource.js +140 -0
  448. package/lib/media-sources/CameraKitSource.js.map +1 -0
  449. package/lib/media-sources/FunctionSource.d.ts +30 -0
  450. package/lib/media-sources/FunctionSource.js +132 -0
  451. package/lib/media-sources/FunctionSource.js.map +1 -0
  452. package/lib/media-sources/ImageSource.d.ts +13 -0
  453. package/lib/media-sources/ImageSource.js +28 -0
  454. package/lib/media-sources/ImageSource.js.map +1 -0
  455. package/lib/media-sources/MediaStreamSource.d.ts +41 -0
  456. package/lib/media-sources/MediaStreamSource.js +146 -0
  457. package/lib/media-sources/MediaStreamSource.js.map +1 -0
  458. package/lib/media-sources/VideoSource.d.ts +21 -0
  459. package/lib/media-sources/VideoSource.js +38 -0
  460. package/lib/media-sources/VideoSource.js.map +1 -0
  461. package/lib/metrics/businessEventsReporter.d.ts +37 -0
  462. package/lib/metrics/businessEventsReporter.js +160 -0
  463. package/lib/metrics/businessEventsReporter.js.map +1 -0
  464. package/lib/metrics/metricsEventTarget.d.ts +41 -0
  465. package/lib/metrics/metricsEventTarget.js +11 -0
  466. package/lib/metrics/metricsEventTarget.js.map +1 -0
  467. package/lib/metrics/metricsHandler.d.ts +9 -0
  468. package/lib/metrics/metricsHandler.js +13 -0
  469. package/lib/metrics/metricsHandler.js.map +1 -0
  470. package/lib/metrics/operationalMetricsReporter.d.ts +52 -0
  471. package/lib/metrics/operationalMetricsReporter.js +108 -0
  472. package/lib/metrics/operationalMetricsReporter.js.map +1 -0
  473. package/lib/metrics/reporters/reportBenchmarks.d.ts +10 -0
  474. package/lib/metrics/reporters/reportBenchmarks.js +29 -0
  475. package/lib/metrics/reporters/reportBenchmarks.js.map +1 -0
  476. package/lib/metrics/reporters/reportGlobalException.d.ts +19 -0
  477. package/lib/metrics/reporters/reportGlobalException.js +68 -0
  478. package/lib/metrics/reporters/reportGlobalException.js.map +1 -0
  479. package/lib/metrics/reporters/reportHttpMetrics.d.ts +17 -0
  480. package/lib/metrics/reporters/reportHttpMetrics.js +92 -0
  481. package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -0
  482. package/lib/metrics/reporters/reportLegalState.d.ts +15 -0
  483. package/lib/metrics/reporters/reportLegalState.js +34 -0
  484. package/lib/metrics/reporters/reportLegalState.js.map +1 -0
  485. package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +38 -0
  486. package/lib/metrics/reporters/reportLensAndAssetDownload.js +88 -0
  487. package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -0
  488. package/lib/metrics/reporters/reportLensValidationFailed.d.ts +20 -0
  489. package/lib/metrics/reporters/reportLensValidationFailed.js +24 -0
  490. package/lib/metrics/reporters/reportLensValidationFailed.js.map +1 -0
  491. package/lib/metrics/reporters/reportLensView.d.ts +36 -0
  492. package/lib/metrics/reporters/reportLensView.js +101 -0
  493. package/lib/metrics/reporters/reportLensView.js.map +1 -0
  494. package/lib/metrics/reporters/reportLensWait.d.ts +33 -0
  495. package/lib/metrics/reporters/reportLensWait.js +56 -0
  496. package/lib/metrics/reporters/reportLensWait.js.map +1 -0
  497. package/lib/metrics/reporters/reportSessionException.d.ts +17 -0
  498. package/lib/metrics/reporters/reportSessionException.js +12 -0
  499. package/lib/metrics/reporters/reportSessionException.js.map +1 -0
  500. package/lib/metrics/reporters/reportUserSession.d.ts +14 -0
  501. package/lib/metrics/reporters/reportUserSession.js +67 -0
  502. package/lib/metrics/reporters/reportUserSession.js.map +1 -0
  503. package/lib/metrics/reporters/reporters.d.ts +44 -0
  504. package/lib/metrics/reporters/reporters.js +33 -0
  505. package/lib/metrics/reporters/reporters.js.map +1 -0
  506. package/lib/namedErrors.d.ts +107 -0
  507. package/lib/namedErrors.js +56 -0
  508. package/lib/namedErrors.js.map +1 -0
  509. package/lib/persistence/ExpiringPersistence.d.ts +20 -0
  510. package/lib/persistence/ExpiringPersistence.js +58 -0
  511. package/lib/persistence/ExpiringPersistence.js.map +1 -0
  512. package/lib/persistence/IndexedDBPersistence.d.ts +47 -0
  513. package/lib/persistence/IndexedDBPersistence.js +180 -0
  514. package/lib/persistence/IndexedDBPersistence.js.map +1 -0
  515. package/lib/persistence/Persistence.d.ts +25 -0
  516. package/lib/persistence/Persistence.js +10 -0
  517. package/lib/persistence/Persistence.js.map +1 -0
  518. package/lib/remote-configuration/cofHandler.d.ts +21 -0
  519. package/lib/remote-configuration/cofHandler.js +75 -0
  520. package/lib/remote-configuration/cofHandler.js.map +1 -0
  521. package/lib/remote-configuration/remoteConfiguration.d.ts +13 -0
  522. package/lib/remote-configuration/remoteConfiguration.js +43 -0
  523. package/lib/remote-configuration/remoteConfiguration.js.map +1 -0
  524. package/lib/session/CameraKitSession.d.ts +252 -0
  525. package/lib/session/CameraKitSession.js +439 -0
  526. package/lib/session/CameraKitSession.js.map +1 -0
  527. package/lib/session/CameraKitSessionEvents.d.ts +33 -0
  528. package/lib/session/CameraKitSessionEvents.js +21 -0
  529. package/lib/session/CameraKitSessionEvents.js.map +1 -0
  530. package/lib/session/LensKeyboard.d.ts +89 -0
  531. package/lib/session/LensKeyboard.js +95 -0
  532. package/lib/session/LensKeyboard.js.map +1 -0
  533. package/lib/session/LensPerformanceMeasurement.d.ts +55 -0
  534. package/lib/session/LensPerformanceMeasurement.js +91 -0
  535. package/lib/session/LensPerformanceMeasurement.js.map +1 -0
  536. package/lib/session/LensPerformanceMetrics.d.ts +31 -0
  537. package/lib/session/LensPerformanceMetrics.js +58 -0
  538. package/lib/session/LensPerformanceMetrics.js.map +1 -0
  539. package/lib/session/index.d.ts +1 -0
  540. package/lib/session/index.js +2 -0
  541. package/lib/session/index.js.map +1 -0
  542. package/lib/session/lensState.d.ts +29 -0
  543. package/lib/session/lensState.js +160 -0
  544. package/lib/session/lensState.js.map +1 -0
  545. package/lib/session/sessionState.d.ts +10 -0
  546. package/lib/session/sessionState.js +12 -0
  547. package/lib/session/sessionState.js.map +1 -0
  548. package/lib/transforms/Transform2D.d.ts +17 -0
  549. package/lib/transforms/Transform2D.js +18 -0
  550. package/lib/transforms/Transform2D.js.map +1 -0
  551. package/lib/transforms/index.d.ts +1 -0
  552. package/lib/transforms/index.js +2 -0
  553. package/lib/transforms/index.js.map +1 -0
  554. package/package.json +62 -0
@@ -0,0 +1,439 @@
1
+ import { __awaiter, __decorate, __metadata, __param } from "tslib";
2
+ /* eslint-disable @typescript-eslint/member-ordering */
3
+ import { filter, firstValueFrom, map, of, takeUntil, tap } from "rxjs";
4
+ import { dispatch, forActions, inStates, isAction, isState } from "@snap/state-management";
5
+ import { isLens } from "../lens";
6
+ import { Injectable } from "../dependency-injection/Injectable";
7
+ import { lensCoreFactory } from "../lens-core-module/loader/lensCoreFactory";
8
+ import { onPageHidden, onPageVisible } from "../common/pageVisibility";
9
+ import { guard, validate } from "../common/validate";
10
+ import { TypedEventTarget } from "../events/TypedEventTarget";
11
+ import { TypedCustomEvent } from "../events/TypedCustomEvent";
12
+ import { cameraKitSourceError } from "../namedErrors";
13
+ import { createMediaStreamSource } from "../media-sources/MediaStreamSource";
14
+ import { createVideoSource } from "../media-sources/VideoSource";
15
+ import { getLogger } from "../logger/logger";
16
+ import { errorLoggingDecorator } from "../logger/errorLoggingDecorator";
17
+ import { logEntriesFactory } from "../logger/logEntries";
18
+ import { LensPerformanceMetrics } from "./LensPerformanceMetrics";
19
+ import { lensStateFactory } from "./lensState";
20
+ import { sessionStateFactory } from "./sessionState";
21
+ import { lensKeyboardFactory } from "./LensKeyboard";
22
+ import { isSessionError } from "./CameraKitSessionEvents";
23
+ const logger = getLogger("CameraKitSession");
24
+ const log = errorLoggingDecorator(logger);
25
+ function isOptionalRenderTarget(value) {
26
+ return value === "live" || value === "capture" || value === undefined;
27
+ }
28
+ /**
29
+ * A CameraKitSession represents a single rendering pipeline connecting an input media source to output `<canvas>`
30
+ * elements. When a Lens is applied to the session, CameraKit uses the Lens to transform the input media into rendered
31
+ * output.
32
+ *
33
+ * CameraKitSession is the primary object that applications interact with when integrating the CameraKit SDK.
34
+ *
35
+ * A CameraKitSession instance is obtained by calling {@link CameraKit.createSession}.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const cameraKit = await bootstrapCameraKit(config)
40
+ * const session = await cameraKit.createSession()
41
+ * ```
42
+ *
43
+ * @category Rendering
44
+ * @category Lenses
45
+ */
46
+ export class CameraKitSession {
47
+ /**
48
+ * @internal
49
+ */
50
+ constructor(
51
+ /**
52
+ * Use this to interact with lenses which require text input.
53
+ */
54
+ keyboard, lensCore, sessionState, lensState, logEntries) {
55
+ this.keyboard = keyboard;
56
+ this.lensCore = lensCore;
57
+ this.sessionState = sessionState;
58
+ this.lensState = lensState;
59
+ /**
60
+ * Add event listeners here to handle events which occur during the CameraKitSession.
61
+ *
62
+ * **Note:** Applications may want to handle the `error` event, and check the contained error type -- if the type
63
+ * is {@link LensExecutionError}, this means the current lens was unable to render and CameraKit will automatically
64
+ * remove the lens.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * cameraKitSession.events.addEventListener('error', ({ detail }) => {
69
+ * if (detail.error.name === 'LensExecutionError') {
70
+ * console.log(`Lens ${detail.lens.name} encountered an error and was removed. Please pick a different lens.`)
71
+ * }
72
+ * })
73
+ * ```
74
+ */
75
+ this.events = new TypedEventTarget();
76
+ const outputs = this.lensCore.getOutputCanvases();
77
+ this.output = {
78
+ live: outputs[this.lensCore.CanvasType.Preview.value],
79
+ capture: outputs[this.lensCore.CanvasType.Capture.value],
80
+ };
81
+ this.playing = false;
82
+ this.metrics = new LensPerformanceMetrics(this.lensCore);
83
+ const removeOnHidden = onPageHidden(() => this.sessionState.dispatch("suspend", this));
84
+ const removeOnVisible = onPageVisible(() => this.sessionState.dispatch("resume", this));
85
+ this.removePageVisibilityHandlers = () => {
86
+ removeOnHidden();
87
+ removeOnVisible();
88
+ };
89
+ const sessionErrors = logEntries.pipe(filter((entry) => entry.level === "error"), map((entry) => entry.messages.find((e) => e instanceof Error)), filter(isSessionError));
90
+ this.subscriptions = [
91
+ // In case of LensCore lens execution error, we must remove the lens from rendering
92
+ // NOTE: LensCore doesn't differentiate recoverable vs non-recoverable errors and
93
+ // it is recommened to always remove the lens.
94
+ sessionErrors
95
+ .pipe(filter((error) => error.name === "LensExecutionError"))
96
+ .subscribe(() => this.removeLens()),
97
+ // Report LensExecutionError and LensImagePickerError errors to apps
98
+ sessionErrors.subscribe((error) => {
99
+ if (error.name !== "LensExecutionError" && error.name !== "LensImagePickerError")
100
+ return;
101
+ const state = lensState.getState();
102
+ if (!isState(state, "noLensApplied")) {
103
+ this.events.dispatchEvent(new TypedCustomEvent("error", { error, lens: state.data }));
104
+ }
105
+ else {
106
+ // NOTE: at this point the error is already reported, so we can just log a warning
107
+ logger.warn(new Error("Lens error occurred even though there is no active lens.", {
108
+ cause: error,
109
+ }));
110
+ }
111
+ }),
112
+ ];
113
+ }
114
+ /**
115
+ * Apply a Lens to this session.
116
+ *
117
+ * This method will download (and cache) the Lens executable, and then use that Lens for rendering. If the session
118
+ * is currently playing, this will immediately update the rendered output. Otherwise, the new Lens will be used
119
+ * when session playback in resumed.
120
+ *
121
+ * Calling `applyLens` replaces any prior Lens – only one Lens is allowed at a time (per session).
122
+ *
123
+ * **NOTE**: Errors may occur after the Lens is applied. If the Lens encounters errors while rendering,
124
+ * Camera Kit will automatically remove the Lens from the session and emit a {@link LensExecutionError} event.
125
+ * Applications may want to listen for this error and, for example,
126
+ * prevent the Lens from being selected again by the user.
127
+ *
128
+ * ```ts
129
+ * session.events.addEventListener("error", ({ detail }) => {
130
+ * if (detail.error.name === "LensExecutionError") {
131
+ * preventFutureLensSelection(detail.lens);
132
+ * showMessage("We're sorry, but the Lens you selected encountered an error. Please choose a different Lens.");
133
+ * }
134
+ * });
135
+ * ```
136
+ *
137
+ * @param lens The Lens to apply to this session.
138
+ * @param launchParams: This can optionally be provided to pass some initial data to the lens – only certain lenses
139
+ * expect launch data.
140
+ * @returns A promise which can have the following results:
141
+ * 1. Resolved with `true`: the lens has been applied.
142
+ * 2. Resolved with `false`: the lens has not been applied, but no error occurred – this can happen if a
143
+ * subsequent call to `applyLens` interrupted the lens application.
144
+ * 3. Rejected: the lens has not been applied because an error occurred. This can happen if:
145
+ * - The lens ID cannot be found in the LensRepository (use LensRepository to load the lens before calling this
146
+ * method)
147
+ * - Lens content download fails, or the download of any required lens assets fails.
148
+ * - An internal failure occurs in the Lens rendering engine when attempting to apply the lens.
149
+ */
150
+ applyLens(lens, launchParams) {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ const action = this.lensState.actions.applyLens({ lens, launchParams });
153
+ return firstValueFrom(of(action).pipe(dispatch(this.lensState),
154
+ // If another applyLens occurs while we're waiting, resolve this applyLens promise early – we're no
155
+ // longer waiting for the requested lens to be applied.
156
+ takeUntil(this.lensState.events.pipe(forActions("applyLens"), filter(([a]) => a !== action))),
157
+ // If lens application failed, convert this into a rejected promise by throwing the error.
158
+ tap(([a]) => {
159
+ if (isAction(a, "applyLensFailed") && a.data.lens.id === lens.id)
160
+ throw a.data.error;
161
+ }), inStates("lensApplied"), map(() => true)),
162
+ // The default value is used if `takeUntil` completes the Observable early – i.e. the lens was not
163
+ // applied (application was interrupted by a new call to `applyLens`), so we'll resolve with `false`.
164
+ { defaultValue: false });
165
+ });
166
+ }
167
+ /**
168
+ * Remove a Lens from this session.
169
+ *
170
+ * When a Lens is removed, rendering continues if the session is playing. It will just render the session input
171
+ * directly to the outputs without any image processing.
172
+ *
173
+ * @returns A promise which can have the following results:
174
+ * 1. Resolved with `true`: the session's rendered output has no lens applied.
175
+ * 2. Resolved with `false`: the current lens has been removed, but a subsequent call to `applyLens` means that the
176
+ * session's rendered output will still have a (new) lens applied.
177
+ * 3. Rejected: the lens has failed to be removed. This can happen if an internal failure occurs in the Lens
178
+ * rendering engine when attempting to remove the lens.
179
+ */
180
+ removeLens() {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ if (isState(this.lensState.getState(), "noLensApplied"))
183
+ return true;
184
+ return firstValueFrom(of(this.lensState.actions.removeLens()).pipe(dispatch(this.lensState),
185
+ // If lens removal failed, convert this into a rejected promise by throwing the error.
186
+ tap(([a]) => {
187
+ if (isAction(a, "removeLensFailed"))
188
+ throw a.data;
189
+ }), inStates("noLensApplied"),
190
+ // If applyLens is called while we're waiting for removal, complete immediately – applying the next lens
191
+ // will replace the current one.
192
+ takeUntil(this.lensState.events.pipe(forActions("applyLens"))), map(() => true)),
193
+ // The default value is used if `takeUntil` completes the Observable early (otherwise firstValueFrom will
194
+ // return a rejected Promise).
195
+ { defaultValue: false });
196
+ });
197
+ }
198
+ /**
199
+ * Start/resume session playback – LensCore will begin rendering frames to the output.
200
+ *
201
+ * If no source has been set for the session, calling `play()` will update the playing state, but no actual image
202
+ * processing will occur until `setSource()` is called.
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const cameraKitSession = await cameraKit.createSession()
207
+ * await cameraKitSession.setSource(mySource)
208
+ * await cameraKitSession.play()
209
+ *
210
+ * // If you call `play` before `setSource`, the call to `play` will resolve but playback will only begin once a
211
+ * // media source has been set.
212
+ * ```
213
+ *
214
+ * @param target Specify the {@link RenderTarget} to render. Defaults to the `live` RenderTarget.
215
+ * @returns Promise resolves when playback state has been updated. If no source has been set, this means `play` will
216
+ * resolve before any frames are processed -- but once a source is set, frames will immediately begin processing.
217
+ */
218
+ play(target = "live") {
219
+ return __awaiter(this, void 0, void 0, function* () {
220
+ if (this.playing)
221
+ return;
222
+ this.playing = target;
223
+ const type = this.renderTargetToCanvasType(target);
224
+ return new Promise((resolve, reject) => {
225
+ this.lensCore.playCanvas({
226
+ type,
227
+ onSuccess: resolve,
228
+ onFailure: (error) => {
229
+ this.playing = false;
230
+ reject(error);
231
+ },
232
+ });
233
+ });
234
+ });
235
+ }
236
+ /**
237
+ * Pause session playback – LensCore will stop rendering frames to the output.
238
+ *
239
+ * @param target Specify the RenderTarget to pause playback. May be either `'live'` or `'capture'`.
240
+ * Default is `'live'`.
241
+ * @returns Promise resolves when playback has stopped.
242
+ */
243
+ pause(target = "live") {
244
+ return __awaiter(this, void 0, void 0, function* () {
245
+ if (!this.playing)
246
+ return;
247
+ const priorPlayingState = this.playing;
248
+ this.playing = false;
249
+ const type = this.renderTargetToCanvasType(target);
250
+ return new Promise((resolve, reject) => {
251
+ this.lensCore.pauseCanvas({
252
+ type,
253
+ onSuccess: resolve,
254
+ onFailure: (error) => {
255
+ this.playing = priorPlayingState;
256
+ reject(error);
257
+ },
258
+ });
259
+ });
260
+ });
261
+ }
262
+ /**
263
+ * Mute all sounds (default SDK state is unmuted).
264
+ *
265
+ * @param fade Do we want audio to fade out?
266
+ */
267
+ mute(fade = false) {
268
+ this.lensCore.setAllSoundsMuted({
269
+ muted: true,
270
+ fade,
271
+ });
272
+ }
273
+ /**
274
+ * Unmute all sounds.
275
+ *
276
+ * @param fade Do we want audio to fade in?
277
+ */
278
+ unmute(fade = false) {
279
+ this.lensCore.setAllSoundsMuted({
280
+ muted: false,
281
+ fade,
282
+ });
283
+ }
284
+ setSource(source, options = {}) {
285
+ return __awaiter(this, void 0, void 0, function* () {
286
+ yield this.safelyDetachSource();
287
+ // For convenience, we allow callers to pass in native objects (e.g. MediaStream) as well as CameraKitSource.
288
+ // Native objects are wrapped in corresponding CameraKitSource classes with default options.
289
+ const cameraKitSource = source instanceof MediaStream
290
+ ? createMediaStreamSource(source, options)
291
+ : source instanceof HTMLVideoElement
292
+ ? createVideoSource(source, options)
293
+ : source;
294
+ const priorPlayingState = this.playing;
295
+ this.playing = false;
296
+ // The source will provide its data to LensCore, and use other LensCore APIs (e.g. setRenderSize,
297
+ // setInputTransform) to render the source correctly.
298
+ yield cameraKitSource.attach(this.lensCore, (error) => {
299
+ logger.error(cameraKitSourceError("Error happened during source attachment.", error));
300
+ });
301
+ // If attachment is successful, we'll update our source so that we can detach it later.
302
+ this.source = cameraKitSource;
303
+ // Finally we'll resume playback, if appropriate.
304
+ if (priorPlayingState) {
305
+ yield this.play(priorPlayingState);
306
+ }
307
+ return cameraKitSource;
308
+ });
309
+ }
310
+ /**
311
+ * Set an FPS limit.
312
+ *
313
+ * This may be useful to reduce CPU/GPU resource usage by CameraKit if, for example, the input
314
+ * media source has a low FPS – CameraKit would then not try to render more frequently than the source produces
315
+ * new frames.
316
+ *
317
+ * This may also be useful to gracefully degrade performance in situations where lowering FPS is preferable over
318
+ * alternatives.
319
+ *
320
+ * @param fpsLimit A maximum FPS, rendering will not exceed this limit
321
+ * @returns Promise is resolved when the limit is successfully set.
322
+ */
323
+ setFPSLimit(fpsLimit) {
324
+ return __awaiter(this, void 0, void 0, function* () {
325
+ // LensCore uses 0 to remove the limit.
326
+ const fps = fpsLimit < Number.POSITIVE_INFINITY ? fpsLimit : 0;
327
+ return new Promise((onSuccess, onFailure) => {
328
+ this.lensCore.setFPSLimit({ fps, onSuccess, onFailure });
329
+ });
330
+ });
331
+ }
332
+ /**
333
+ * Destroy the session.
334
+ *
335
+ * The session will become inoperable. Frame processing stops, and any session-scoped graphical resources are freed.
336
+ */
337
+ destroy() {
338
+ return __awaiter(this, void 0, void 0, function* () {
339
+ this.subscriptions.forEach((sub) => sub.unsubscribe());
340
+ yield this.removeLens();
341
+ yield this.safelyDetachSource();
342
+ yield new Promise((resolve, reject) => {
343
+ this.lensCore.teardown({ onSuccess: resolve, onFailure: reject });
344
+ });
345
+ this.removePageVisibilityHandlers();
346
+ });
347
+ }
348
+ renderTargetToCanvasType(target) {
349
+ return target === "capture" ? this.lensCore.CanvasType.Capture : this.lensCore.CanvasType.Preview;
350
+ }
351
+ safelyDetachSource() {
352
+ return __awaiter(this, void 0, void 0, function* () {
353
+ if (this.source) {
354
+ try {
355
+ yield this.source.detach((error) => {
356
+ logger.error(cameraKitSourceError("Error happened during source detachment.", error));
357
+ });
358
+ // If there's a failure to detach, we will report the error and proceed. Failure to detach may lead to a
359
+ // memory leak, but it shouldn't prevent us from switching to the new source.
360
+ }
361
+ catch (error) {
362
+ logger.error(cameraKitSourceError(`Detaching prior source of type ${typeof this.source} failed.`, error));
363
+ }
364
+ }
365
+ });
366
+ }
367
+ }
368
+ __decorate([
369
+ validate,
370
+ log,
371
+ __param(0, guard(isLens)),
372
+ __metadata("design:type", Function),
373
+ __metadata("design:paramtypes", [Object, Object]),
374
+ __metadata("design:returntype", Promise)
375
+ ], CameraKitSession.prototype, "applyLens", null);
376
+ __decorate([
377
+ log,
378
+ __metadata("design:type", Function),
379
+ __metadata("design:paramtypes", []),
380
+ __metadata("design:returntype", Promise)
381
+ ], CameraKitSession.prototype, "removeLens", null);
382
+ __decorate([
383
+ validate,
384
+ log,
385
+ __param(0, guard(isOptionalRenderTarget)),
386
+ __metadata("design:type", Function),
387
+ __metadata("design:paramtypes", [String]),
388
+ __metadata("design:returntype", Promise)
389
+ ], CameraKitSession.prototype, "play", null);
390
+ __decorate([
391
+ validate,
392
+ log,
393
+ __param(0, guard(isOptionalRenderTarget)),
394
+ __metadata("design:type", Function),
395
+ __metadata("design:paramtypes", [String]),
396
+ __metadata("design:returntype", Promise)
397
+ ], CameraKitSession.prototype, "pause", null);
398
+ __decorate([
399
+ log,
400
+ __metadata("design:type", Function),
401
+ __metadata("design:paramtypes", [Boolean]),
402
+ __metadata("design:returntype", void 0)
403
+ ], CameraKitSession.prototype, "mute", null);
404
+ __decorate([
405
+ log,
406
+ __metadata("design:type", Function),
407
+ __metadata("design:paramtypes", [Boolean]),
408
+ __metadata("design:returntype", void 0)
409
+ ], CameraKitSession.prototype, "unmute", null);
410
+ __decorate([
411
+ validate,
412
+ log,
413
+ __metadata("design:type", Function),
414
+ __metadata("design:paramtypes", [Object, Object]),
415
+ __metadata("design:returntype", Promise)
416
+ ], CameraKitSession.prototype, "setSource", null);
417
+ __decorate([
418
+ log,
419
+ __metadata("design:type", Function),
420
+ __metadata("design:paramtypes", [Number]),
421
+ __metadata("design:returntype", Promise)
422
+ ], CameraKitSession.prototype, "setFPSLimit", null);
423
+ __decorate([
424
+ log,
425
+ __metadata("design:type", Function),
426
+ __metadata("design:paramtypes", []),
427
+ __metadata("design:returntype", Promise)
428
+ ], CameraKitSession.prototype, "destroy", null);
429
+ /**
430
+ * @internal
431
+ */
432
+ export const cameraKitSessionFactory = Injectable("CameraKitSession", [
433
+ lensCoreFactory.token,
434
+ logEntriesFactory.token,
435
+ lensKeyboardFactory.token,
436
+ sessionStateFactory.token,
437
+ lensStateFactory.token,
438
+ ], (lensCore, logEntries, keyboard, sessionState, lensState) => new CameraKitSession(keyboard, lensCore, sessionState, lensState, logEntries));
439
+ //# sourceMappingURL=CameraKitSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CameraKitSession.js","sourceRoot":"","sources":["../../src/session/CameraKitSession.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,EAAc,EAAE,EAAgB,SAAS,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACjG,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC3F,OAAO,EAAQ,MAAM,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,M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GAAwG;oBACxG,6EAA6E;iBAChF;gBAAC,OAAO,KAAK,EAAE;oBACZ,MAAM,CAAC,KAAK,CACR,oBAAoB,CAAC,kCAAkC,OAAO,IAAI,CAAC,MAAM,UAAU,EAAE,KAAK,CAAC,CAC9F,CAAC;iBACL;aACJ;QACL,CAAC;KAAA;CACJ;AAtRS;IAFL,QAAQ;IACR,GAAG;IACa,WAAA,KAAK,CAAC,MAAM,CAAC,CAAA;;;;iDA4B7B;AAgBK;IADL,GAAG;;;;kDAqBH;AAwBK;IAFL,QAAQ;IACR,GAAG;IACQ,WAAA,KAAK,CAAC,sBAAsB,CAAC,CAAA;;;;4CAexC;AAWK;IAFL,QAAQ;IACR,GAAG;IACS,WAAA,KAAK,CAAC,sBAAsB,CAAC,CAAA;;;;6CAgBzC;AAOD;IAAC,GAAG;;;;4CAMH;AAOD;IAAC,GAAG;;;;8CAMH;AA8BK;IAFL,QAAQ;IACR,GAAG;;;;iDAkCH;AAgBK;IADL,GAAG;;;;mDAOH;AAQK;IADL,GAAG;;;;+CASH;AAuBL;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAC7C,kBAAkB,EAClB;IACI,eAAe,CAAC,KAAK;IACrB,iBAAiB,CAAC,KAAK;IACvB,mBAAmB,CAAC,KAAK;IACzB,mBAAmB,CAAC,KAAK;IACzB,gBAAgB,CAAC,KAAK;CAChB,EACV,CACI,QAAwB,EACxB,UAAgC,EAChC,QAAsB,EACtB,YAA0B,EAC1B,SAAoB,EACtB,EAAE,CAAC,IAAI,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,CAAC,CACrF,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/member-ordering */\nimport { filter, firstValueFrom, map, Observable, of, Subscription, takeUntil, tap } from \"rxjs\";\nimport { dispatch, forActions, inStates, isAction, isState } from \"@snap/state-management\";\nimport { Lens, isLens } from \"../lens\";\nimport { CanvasType, LensCoreModule } from \"../lens-core-module\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { lensCoreFactory } from \"../lens-core-module/loader/lensCoreFactory\";\nimport { LensLaunchParams } from \"../lens/LensLaunchParams\";\nimport { onPageHidden, onPageVisible } from \"../common/pageVisibility\";\nimport { guard, validate } from \"../common/validate\";\nimport { TypedEventTarget } from \"../events/TypedEventTarget\";\nimport { TypedCustomEvent } from \"../events/TypedCustomEvent\";\nimport { CameraKitDeviceInfo, CameraKitSource } from \"../media-sources/CameraKitSource\";\nimport { cameraKitSourceError } from \"../namedErrors\";\nimport { createMediaStreamSource } from \"../media-sources/MediaStreamSource\";\nimport { createVideoSource } from \"../media-sources/VideoSource\";\nimport { getLogger, LogEntry } from \"../logger/logger\";\nimport { errorLoggingDecorator } from \"../logger/errorLoggingDecorator\";\nimport { logEntriesFactory } from \"../logger/logEntries\";\nimport { LensPerformanceMetrics } from \"./LensPerformanceMetrics\";\nimport { lensStateFactory, LensState } from \"./lensState\";\nimport { SessionState, sessionStateFactory } from \"./sessionState\";\nimport { Keyboard, lensKeyboardFactory, LensKeyboard } from \"./LensKeyboard\";\nimport { CameraKitSessionEvents, isSessionError } from \"./CameraKitSessionEvents\";\n\nconst logger = getLogger(\"CameraKitSession\");\nconst log = errorLoggingDecorator(logger);\n\nfunction isOptionalRenderTarget(value: unknown): value is RenderTarget | undefined {\n return value === \"live\" || value === \"capture\" || value === undefined;\n}\n\n/**\n * Enumerates the supported render targets.\n *\n * Lenses may render to different render targets, as designed by the lens creator. In CameraKit, it's possible to choose\n * which render target to render, and the result for each target is available as a separate `<canvas>` element.\n *\n * @category Rendering\n * @category Lenses\n */\nexport type RenderTarget = \"live\" | \"capture\";\n\n/**\n * A CameraKitSession represents a single rendering pipeline connecting an input media source to output `<canvas>`\n * elements. When a Lens is applied to the session, CameraKit uses the Lens to transform the input media into rendered\n * output.\n *\n * CameraKitSession is the primary object that applications interact with when integrating the CameraKit SDK.\n *\n * A CameraKitSession instance is obtained by calling {@link CameraKit.createSession}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * const session = await cameraKit.createSession()\n * ```\n *\n * @category Rendering\n * @category Lenses\n */\nexport class CameraKitSession {\n /**\n * CameraKitSession renders video output to a `<canvas>` element. In fact, each session contains two canvas outputs\n * corresponding to the RenderTargets used by Lens creators, when using LensStudio to create a Lens.\n *\n * The `live` output renders content suitable for the Lens user (e.g. it may contain additional UI elements\n * applicable only to the person applying the lens). The `capture` output renders content suitable for sharing with\n * other users (e.g. sent to the other members of a video call, or saved to disk for sharing later).\n *\n * For many lenses, these outputs are identical – but each lens is free to render differently, based on its own\n * use-case.\n */\n readonly output: {\n live: HTMLCanvasElement;\n capture: HTMLCanvasElement;\n };\n\n /**\n * Indicates whether or not the session is currently rendering. If `false`, rendering is stopped. Otherwise the\n * value indicates which output is being rendered.\n */\n playing: false | RenderTarget;\n\n /**\n * Add event listeners here to handle events which occur during the CameraKitSession.\n *\n * **Note:** Applications may want to handle the `error` event, and check the contained error type -- if the type\n * is {@link LensExecutionError}, this means the current lens was unable to render and CameraKit will automatically\n * remove the lens.\n *\n * @example\n * ```ts\n * cameraKitSession.events.addEventListener('error', ({ detail }) => {\n * if (detail.error.name === 'LensExecutionError') {\n * console.log(`Lens ${detail.lens.name} encountered an error and was removed. Please pick a different lens.`)\n * }\n * })\n * ```\n */\n readonly events = new TypedEventTarget<CameraKitSessionEvents>();\n\n /**\n * Use this to measure current lens performance.\n */\n readonly metrics: LensPerformanceMetrics;\n\n private readonly removePageVisibilityHandlers: () => void;\n private source?: CameraKitSource;\n private subscriptions: Subscription[];\n\n /**\n * @internal\n */\n constructor(\n /**\n * Use this to interact with lenses which require text input.\n */\n public readonly keyboard: Keyboard,\n\n private readonly lensCore: LensCoreModule,\n private readonly sessionState: SessionState,\n private readonly lensState: LensState,\n logEntries: Observable<LogEntry>\n ) {\n const outputs = this.lensCore.getOutputCanvases();\n this.output = {\n live: outputs[this.lensCore.CanvasType.Preview.value],\n capture: outputs[this.lensCore.CanvasType.Capture.value],\n };\n this.playing = false;\n\n this.metrics = new LensPerformanceMetrics(this.lensCore);\n\n const removeOnHidden = onPageHidden(() => this.sessionState.dispatch(\"suspend\", this));\n const removeOnVisible = onPageVisible(() => this.sessionState.dispatch(\"resume\", this));\n this.removePageVisibilityHandlers = () => {\n removeOnHidden();\n removeOnVisible();\n };\n\n const sessionErrors = logEntries.pipe(\n filter((entry) => entry.level === \"error\"),\n map((entry) => entry.messages.find((e) => e instanceof Error)),\n filter(isSessionError)\n );\n\n this.subscriptions = [\n // In case of LensCore lens execution error, we must remove the lens from rendering\n // NOTE: LensCore doesn't differentiate recoverable vs non-recoverable errors and\n // it is recommened to always remove the lens.\n sessionErrors\n .pipe(filter((error) => error.name === \"LensExecutionError\"))\n .subscribe(() => this.removeLens()),\n\n // Report LensExecutionError and LensImagePickerError errors to apps\n sessionErrors.subscribe((error) => {\n if (error.name !== \"LensExecutionError\" && error.name !== \"LensImagePickerError\") return;\n\n const state = lensState.getState();\n if (!isState(state, \"noLensApplied\")) {\n this.events.dispatchEvent(new TypedCustomEvent(\"error\", { error, lens: state.data }));\n } else {\n // NOTE: at this point the error is already reported, so we can just log a warning\n logger.warn(\n new Error(\"Lens error occurred even though there is no active lens.\", {\n cause: error,\n })\n );\n }\n }),\n ];\n }\n\n /**\n * Apply a Lens to this session.\n *\n * This method will download (and cache) the Lens executable, and then use that Lens for rendering. If the session\n * is currently playing, this will immediately update the rendered output. Otherwise, the new Lens will be used\n * when session playback in resumed.\n *\n * Calling `applyLens` replaces any prior Lens – only one Lens is allowed at a time (per session).\n *\n * **NOTE**: Errors may occur after the Lens is applied. If the Lens encounters errors while rendering,\n * Camera Kit will automatically remove the Lens from the session and emit a {@link LensExecutionError} event.\n * Applications may want to listen for this error and, for example,\n * prevent the Lens from being selected again by the user.\n *\n * ```ts\n * session.events.addEventListener(\"error\", ({ detail }) => {\n * if (detail.error.name === \"LensExecutionError\") {\n * preventFutureLensSelection(detail.lens);\n * showMessage(\"We're sorry, but the Lens you selected encountered an error. Please choose a different Lens.\");\n * }\n * });\n * ```\n *\n * @param lens The Lens to apply to this session.\n * @param launchParams: This can optionally be provided to pass some initial data to the lens – only certain lenses\n * expect launch data.\n * @returns A promise which can have the following results:\n * 1. Resolved with `true`: the lens has been applied.\n * 2. Resolved with `false`: the lens has not been applied, but no error occurred – this can happen if a\n * subsequent call to `applyLens` interrupted the lens application.\n * 3. Rejected: the lens has not been applied because an error occurred. This can happen if:\n * - The lens ID cannot be found in the LensRepository (use LensRepository to load the lens before calling this\n * method)\n * - Lens content download fails, or the download of any required lens assets fails.\n * - An internal failure occurs in the Lens rendering engine when attempting to apply the lens.\n */\n @validate\n @log\n async applyLens(@guard(isLens) lens: Lens, launchParams?: LensLaunchParams): Promise<boolean> {\n const action = this.lensState.actions.applyLens({ lens, launchParams });\n return firstValueFrom(\n of(action).pipe(\n dispatch(this.lensState),\n\n // If another applyLens occurs while we're waiting, resolve this applyLens promise early – we're no\n // longer waiting for the requested lens to be applied.\n takeUntil(\n this.lensState.events.pipe(\n forActions(\"applyLens\"),\n filter(([a]) => a !== action)\n )\n ),\n\n // If lens application failed, convert this into a rejected promise by throwing the error.\n tap(([a]) => {\n if (isAction(a, \"applyLensFailed\") && a.data.lens.id === lens.id) throw a.data.error;\n }),\n\n inStates(\"lensApplied\"),\n\n map(() => true)\n ),\n // The default value is used if `takeUntil` completes the Observable early – i.e. the lens was not\n // applied (application was interrupted by a new call to `applyLens`), so we'll resolve with `false`.\n { defaultValue: false }\n );\n }\n\n /**\n * Remove a Lens from this session.\n *\n * When a Lens is removed, rendering continues if the session is playing. It will just render the session input\n * directly to the outputs without any image processing.\n *\n * @returns A promise which can have the following results:\n * 1. Resolved with `true`: the session's rendered output has no lens applied.\n * 2. Resolved with `false`: the current lens has been removed, but a subsequent call to `applyLens` means that the\n * session's rendered output will still have a (new) lens applied.\n * 3. Rejected: the lens has failed to be removed. This can happen if an internal failure occurs in the Lens\n * rendering engine when attempting to remove the lens.\n */\n @log\n async removeLens(): Promise<boolean> {\n if (isState(this.lensState.getState(), \"noLensApplied\")) return true;\n return firstValueFrom(\n of(this.lensState.actions.removeLens()).pipe(\n dispatch(this.lensState),\n // If lens removal failed, convert this into a rejected promise by throwing the error.\n tap(([a]) => {\n if (isAction(a, \"removeLensFailed\")) throw a.data;\n }),\n inStates(\"noLensApplied\"),\n\n // If applyLens is called while we're waiting for removal, complete immediately – applying the next lens\n // will replace the current one.\n takeUntil(this.lensState.events.pipe(forActions(\"applyLens\"))),\n map(() => true)\n ),\n // The default value is used if `takeUntil` completes the Observable early (otherwise firstValueFrom will\n // return a rejected Promise).\n { defaultValue: false }\n );\n }\n\n /**\n * Start/resume session playback – LensCore will begin rendering frames to the output.\n *\n * If no source has been set for the session, calling `play()` will update the playing state, but no actual image\n * processing will occur until `setSource()` is called.\n *\n * @example\n * ```ts\n * const cameraKitSession = await cameraKit.createSession()\n * await cameraKitSession.setSource(mySource)\n * await cameraKitSession.play()\n *\n * // If you call `play` before `setSource`, the call to `play` will resolve but playback will only begin once a\n * // media source has been set.\n * ```\n *\n * @param target Specify the {@link RenderTarget} to render. Defaults to the `live` RenderTarget.\n * @returns Promise resolves when playback state has been updated. If no source has been set, this means `play` will\n * resolve before any frames are processed -- but once a source is set, frames will immediately begin processing.\n */\n @validate\n @log\n async play(@guard(isOptionalRenderTarget) target: RenderTarget = \"live\"): Promise<void> {\n if (this.playing) return;\n this.playing = target;\n\n const type = this.renderTargetToCanvasType(target);\n return new Promise((resolve, reject) => {\n this.lensCore.playCanvas({\n type,\n onSuccess: resolve,\n onFailure: (error: Error) => {\n this.playing = false;\n reject(error);\n },\n });\n });\n }\n\n /**\n * Pause session playback – LensCore will stop rendering frames to the output.\n *\n * @param target Specify the RenderTarget to pause playback. May be either `'live'` or `'capture'`.\n * Default is `'live'`.\n * @returns Promise resolves when playback has stopped.\n */\n @validate\n @log\n async pause(@guard(isOptionalRenderTarget) target: RenderTarget = \"live\"): Promise<void> {\n if (!this.playing) return;\n const priorPlayingState = this.playing;\n this.playing = false;\n\n const type = this.renderTargetToCanvasType(target);\n return new Promise((resolve, reject) => {\n this.lensCore.pauseCanvas({\n type,\n onSuccess: resolve,\n onFailure: (error: Error) => {\n this.playing = priorPlayingState;\n reject(error);\n },\n });\n });\n }\n\n /**\n * Mute all sounds (default SDK state is unmuted).\n *\n * @param fade Do we want audio to fade out?\n */\n @log\n mute(fade: boolean = false): void {\n this.lensCore.setAllSoundsMuted({\n muted: true,\n fade,\n });\n }\n\n /**\n * Unmute all sounds.\n *\n * @param fade Do we want audio to fade in?\n */\n @log\n unmute(fade: boolean = false): void {\n this.lensCore.setAllSoundsMuted({\n muted: false,\n fade,\n });\n }\n\n /**\n * Set the media source for this session.\n *\n * Sessions may only have one source at a time - if `setSource` is called multiple times, subsequent calls replace\n * the prior source. Setting the source does not trigger rendering (that’s done by `session.play()`). If the session\n * is already playing, setting the source will immediately begin rendering the new source.\n *\n * The CameraKit SDK provides implementations for various common sources, which applications can create using the\n * following functions:\n * - {@link createUserMediaSource}\n * - {@link createMediaStreamSource}\n * - {@link createVideoSource}\n * - {@link createImageSource}\n *\n * @param source A CameraKitSource object representing input media (e.g. a webcam stream, video, or some other\n * source of image data), which CameraKit will supply to Lenses in order for them to render effects on top of that\n * source.\n * @returns Promise is resolved when the source has successfully be set. If the session was already in the playing\n * state, the Promise resolves when the first frame from the new source has been rendered. The resolved value is\n * the {@link CameraKitSource} object attached to the session.\n */\n async setSource(source: CameraKitSource): Promise<CameraKitSource>;\n async setSource(\n source: MediaStream | HTMLVideoElement,\n options?: Partial<CameraKitDeviceInfo>\n ): Promise<CameraKitSource>;\n @validate\n @log\n async setSource(\n source: CameraKitSource | MediaStream | HTMLVideoElement,\n options: Partial<CameraKitDeviceInfo> = {}\n ): Promise<CameraKitSource> {\n await this.safelyDetachSource();\n\n // For convenience, we allow callers to pass in native objects (e.g. MediaStream) as well as CameraKitSource.\n // Native objects are wrapped in corresponding CameraKitSource classes with default options.\n const cameraKitSource =\n source instanceof MediaStream\n ? createMediaStreamSource(source, options)\n : source instanceof HTMLVideoElement\n ? createVideoSource(source, options)\n : source;\n\n const priorPlayingState = this.playing;\n this.playing = false;\n\n // The source will provide its data to LensCore, and use other LensCore APIs (e.g. setRenderSize,\n // setInputTransform) to render the source correctly.\n await cameraKitSource.attach(this.lensCore, (error) => {\n logger.error(cameraKitSourceError(\"Error happened during source attachment.\", error));\n });\n\n // If attachment is successful, we'll update our source so that we can detach it later.\n this.source = cameraKitSource;\n\n // Finally we'll resume playback, if appropriate.\n if (priorPlayingState) {\n await this.play(priorPlayingState);\n }\n\n return cameraKitSource;\n }\n\n /**\n * Set an FPS limit.\n *\n * This may be useful to reduce CPU/GPU resource usage by CameraKit if, for example, the input\n * media source has a low FPS – CameraKit would then not try to render more frequently than the source produces\n * new frames.\n *\n * This may also be useful to gracefully degrade performance in situations where lowering FPS is preferable over\n * alternatives.\n *\n * @param fpsLimit A maximum FPS, rendering will not exceed this limit\n * @returns Promise is resolved when the limit is successfully set.\n */\n @log\n async setFPSLimit(fpsLimit: number): Promise<void> {\n // LensCore uses 0 to remove the limit.\n const fps = fpsLimit < Number.POSITIVE_INFINITY ? fpsLimit : 0;\n return new Promise((onSuccess, onFailure) => {\n this.lensCore.setFPSLimit({ fps, onSuccess, onFailure });\n });\n }\n\n /**\n * Destroy the session.\n *\n * The session will become inoperable. Frame processing stops, and any session-scoped graphical resources are freed.\n */\n @log\n async destroy(): Promise<void> {\n this.subscriptions.forEach((sub) => sub.unsubscribe());\n await this.removeLens();\n await this.safelyDetachSource();\n await new Promise<void>((resolve, reject) => {\n this.lensCore.teardown({ onSuccess: resolve, onFailure: reject });\n });\n this.removePageVisibilityHandlers();\n }\n\n private renderTargetToCanvasType(target: RenderTarget): CanvasType {\n return target === \"capture\" ? this.lensCore.CanvasType.Capture : this.lensCore.CanvasType.Preview;\n }\n\n private async safelyDetachSource(): Promise<void> {\n if (this.source) {\n try {\n await this.source.detach((error) => {\n logger.error(cameraKitSourceError(\"Error happened during source detachment.\", error));\n });\n // If there's a failure to detach, we will report the error and proceed. Failure to detach may lead to a\n // memory leak, but it shouldn't prevent us from switching to the new source.\n } catch (error) {\n logger.error(\n cameraKitSourceError(`Detaching prior source of type ${typeof this.source} failed.`, error)\n );\n }\n }\n }\n}\n\n/**\n * @internal\n */\nexport const cameraKitSessionFactory = Injectable(\n \"CameraKitSession\",\n [\n lensCoreFactory.token,\n logEntriesFactory.token,\n lensKeyboardFactory.token,\n sessionStateFactory.token,\n lensStateFactory.token,\n ] as const,\n (\n lensCore: LensCoreModule,\n logEntries: Observable<LogEntry>,\n keyboard: LensKeyboard,\n sessionState: SessionState,\n lensState: LensState\n ) => new CameraKitSession(keyboard, lensCore, sessionState, lensState, logEntries)\n);\n"]}
@@ -0,0 +1,33 @@
1
+ import { CameraKitSourceError, LensExecutionError, LensImagePickerError } from "../namedErrors";
2
+ import { TypedCustomEvent } from "../events/TypedCustomEvent";
3
+ import { TypedEventListener } from "../events/TypedEventTarget";
4
+ import { Lens } from "../lens";
5
+ /**
6
+ * Returns true if given value is of {@link SessionErrors} type and false otherwise.
7
+ */
8
+ export declare function isSessionError(value: unknown): value is SessionErrors;
9
+ /**
10
+ * Misc errors that occur during CameraKit session.
11
+ * @internal
12
+ */
13
+ export declare type SessionErrors = LensExecutionError | LensImagePickerError | CameraKitSourceError;
14
+ /**
15
+ * Events emitted by {@link CameraKitSession.events | CameraKitSession.events}.
16
+ *
17
+ * The following events are emitted:
18
+ * - `error`: An error has been encountered during lens rendering. May contain an error of type:
19
+ * - {@link LensExecutionError} If an error of this type occurs, the rendering lens will be automatically removed
20
+ * from the associated CameraKitSession.
21
+ * - {@link LensImagePickerError}
22
+ *
23
+ * @category Rendering
24
+ * @category Lenses
25
+ */
26
+ export declare type CameraKitSessionEvents = TypedCustomEvent<"error", {
27
+ error: LensExecutionError | LensImagePickerError;
28
+ lens: Lens;
29
+ }>;
30
+ /**
31
+ * Listener of {@link CameraKitSessionEvents} events.
32
+ */
33
+ export declare type CameraKitSessionEventListener = TypedEventListener<CameraKitSessionEvents>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A type guard helper to detect unreachable code.
3
+ */
4
+ const isReachable = (_) => false;
5
+ /**
6
+ * Returns true if given value is of {@link SessionErrors} type and false otherwise.
7
+ */
8
+ export function isSessionError(value) {
9
+ if (!(value instanceof Error))
10
+ return false;
11
+ const maybeSessionErrorName = value.name;
12
+ switch (maybeSessionErrorName) {
13
+ case "CameraKitSourceError":
14
+ case "LensExecutionError":
15
+ case "LensImagePickerError":
16
+ return true;
17
+ default:
18
+ return isReachable(maybeSessionErrorName);
19
+ }
20
+ }
21
+ //# sourceMappingURL=CameraKitSessionEvents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CameraKitSessionEvents.js","sourceRoot":"","sources":["../../src/session/CameraKitSessionEvents.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,GAAG,CAAC,CAAQ,EAAE,EAAE,CAAC,KAAK,CAAC;AAExC;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IACzC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAE5C,MAAM,qBAAqB,GAAI,KAAuB,CAAC,IAAI,CAAC;IAC5D,QAAQ,qBAAqB,EAAE;QAC3B,KAAK,sBAAsB,CAAC;QAC5B,KAAK,oBAAoB,CAAC;QAC1B,KAAK,sBAAsB;YACvB,OAAO,IAAI,CAAC;QAChB;YACI,OAAO,WAAW,CAAC,qBAAqB,CAAC,CAAC;KACjD;AACL,CAAC","sourcesContent":["import { CameraKitSourceError, LensExecutionError, LensImagePickerError } from \"../namedErrors\";\nimport { TypedCustomEvent } from \"../events/TypedCustomEvent\";\nimport { TypedEventListener } from \"../events/TypedEventTarget\";\nimport { Lens } from \"../lens\";\n\n/**\n * A type guard helper to detect unreachable code.\n */\nconst isReachable = (_: never) => false;\n\n/**\n * Returns true if given value is of {@link SessionErrors} type and false otherwise.\n */\nexport function isSessionError(value: unknown): value is SessionErrors {\n if (!(value instanceof Error)) return false;\n\n const maybeSessionErrorName = (value as SessionErrors).name;\n switch (maybeSessionErrorName) {\n case \"CameraKitSourceError\":\n case \"LensExecutionError\":\n case \"LensImagePickerError\":\n return true;\n default:\n return isReachable(maybeSessionErrorName);\n }\n}\n\n/**\n * Misc errors that occur during CameraKit session.\n * @internal\n */\nexport type SessionErrors = LensExecutionError | LensImagePickerError | CameraKitSourceError;\n\n/**\n * Events emitted by {@link CameraKitSession.events | CameraKitSession.events}.\n *\n * The following events are emitted:\n * - `error`: An error has been encountered during lens rendering. May contain an error of type:\n * - {@link LensExecutionError} If an error of this type occurs, the rendering lens will be automatically removed\n * from the associated CameraKitSession.\n * - {@link LensImagePickerError}\n *\n * @category Rendering\n * @category Lenses\n */\nexport type CameraKitSessionEvents = TypedCustomEvent<\n \"error\",\n { error: LensExecutionError | LensImagePickerError; lens: Lens }\n>;\n\n/**\n * Listener of {@link CameraKitSessionEvents} events.\n */\nexport type CameraKitSessionEventListener = TypedEventListener<CameraKitSessionEvents>;\n"]}