@snap/camera-kit 0.11.0 → 0.12.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 (226) hide show
  1. package/README.md +242 -67
  2. package/docs/html/assets/search.js +1 -1
  3. package/docs/html/classes/CameraKit.html +3 -3
  4. package/docs/html/classes/CameraKitSession.html +3 -3
  5. package/docs/html/classes/CameraKitSource.html +3 -3
  6. package/docs/html/classes/LensPerformanceMeasurement.html +3 -3
  7. package/docs/html/classes/LensPerformanceMetrics.html +3 -3
  8. package/docs/html/classes/LensRepository.html +3 -3
  9. package/docs/html/classes/LensSources.html +3 -3
  10. package/docs/html/classes/Transform2D.html +3 -3
  11. package/docs/html/classes/TypedCustomEvent.html +3 -3
  12. package/docs/html/classes/TypedEventTarget.html +3 -3
  13. package/docs/html/functions/Injectable.html +3 -3
  14. package/docs/html/functions/bootstrapCameraKit.html +3 -3
  15. package/docs/html/functions/createExtension.html +3 -3
  16. package/docs/html/functions/createImageSource.html +3 -3
  17. package/docs/html/functions/createMediaStreamSource.html +3 -3
  18. package/docs/html/functions/createUserMediaSource.html +3 -3
  19. package/docs/html/functions/createVideoSource.html +3 -3
  20. package/docs/html/functions/estimateLensPerformance.html +3 -3
  21. package/docs/html/functions/getRequiredBootstrapURLs.html +3 -3
  22. package/docs/html/functions/lensSourcesFactory.html +3 -3
  23. package/docs/html/functions/uriHandlersFactory.html +3 -3
  24. package/docs/html/index.html +162 -46
  25. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +3 -3
  26. package/docs/html/interfaces/CameraKitSourceSubscriber.html +3 -3
  27. package/docs/html/interfaces/ComputedFrameMetrics.html +3 -3
  28. package/docs/html/interfaces/CreateSessionOptions.html +3 -3
  29. package/docs/html/interfaces/EstimatedLensPerformance.html +3 -3
  30. package/docs/html/interfaces/Lens.html +3 -3
  31. package/docs/html/interfaces/LensSource.html +3 -3
  32. package/docs/html/interfaces/MediaStreamSourceOptions.html +3 -3
  33. package/docs/html/interfaces/Preview.html +3 -3
  34. package/docs/html/interfaces/Snapcode.html +3 -3
  35. package/docs/html/interfaces/UriCancelRequest.html +3 -3
  36. package/docs/html/interfaces/UriHandler.html +3 -3
  37. package/docs/html/interfaces/UriRequest.html +10 -5
  38. package/docs/html/interfaces/UriResponse.html +3 -3
  39. package/docs/html/interfaces/VideoSourceOptions.html +3 -3
  40. package/docs/html/modules.html +4 -4
  41. package/docs/html/types/AssetLoader.html +3 -3
  42. package/docs/html/types/AssetTiming.html +3 -3
  43. package/docs/html/types/BenchmarkError.html +3 -3
  44. package/docs/html/types/BootstrapError.html +3 -3
  45. package/docs/html/types/CacheKeyNotFoundError.html +3 -3
  46. package/docs/html/types/CameraKitDeviceInfo.html +3 -3
  47. package/docs/html/types/CameraKitSessionEventListener.html +3 -3
  48. package/docs/html/types/CameraKitSessionEvents.html +3 -3
  49. package/docs/html/types/CameraKitSourceError.html +3 -3
  50. package/docs/html/types/CameraKitSourceInfo.html +3 -3
  51. package/docs/html/types/CameraKitSourceOptions.html +3 -3
  52. package/docs/html/types/ConfigurationError.html +3 -3
  53. package/docs/html/types/Keyboard.html +3 -3
  54. package/docs/html/types/KeyboardEvents.html +3 -3
  55. package/docs/html/types/LegalError.html +3 -3
  56. package/docs/html/types/LensAssetError.html +3 -3
  57. package/docs/html/types/LensContentValidationError.html +3 -3
  58. package/docs/html/types/LensError.html +3 -3
  59. package/docs/html/types/LensExecutionError.html +3 -3
  60. package/docs/html/types/LensImagePickerError.html +3 -3
  61. package/docs/html/types/LensLaunchParams.html +3 -3
  62. package/docs/html/types/LensMetricsEvents.html +3 -3
  63. package/docs/html/types/LensPerformanceCluster.html +3 -3
  64. package/docs/html/types/LensView.html +3 -3
  65. package/docs/html/types/LensWait.html +3 -3
  66. package/docs/html/types/PersistentStoreError.html +3 -3
  67. package/docs/html/types/PlatformNotSupportedError.html +3 -3
  68. package/docs/html/types/PublicContainer.html +3 -3
  69. package/docs/html/types/RenderTarget.html +3 -3
  70. package/docs/html/types/Uri.html +3 -3
  71. package/docs/html/types/UriHandlers.html +3 -3
  72. package/docs/html/types/WebGLError.html +3 -3
  73. package/docs/html/variables/extensionRequestContext.html +3 -3
  74. package/docs/md/README.md +242 -67
  75. package/docs/md/classes/CameraKit.md +1 -1
  76. package/docs/md/classes/CameraKitSession.md +1 -1
  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 +1 -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 +1 -1
  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 +1 -1
  94. package/docs/md/interfaces/Snapcode.md +1 -1
  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 +8 -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 +2 -2
  101. package/lib/CameraKit.d.ts +16 -6
  102. package/lib/assertPlatformSupported.d.ts +3 -1
  103. package/lib/assertPlatformSupported.js +13 -2
  104. package/lib/assertPlatformSupported.js.map +1 -1
  105. package/lib/bootstrapCameraKit.js +2 -0
  106. package/lib/bootstrapCameraKit.js.map +1 -1
  107. package/lib/common/cameraKitUserAgent.js +17 -2
  108. package/lib/common/cameraKitUserAgent.js.map +1 -1
  109. package/lib/common/dialog.d.ts +43 -0
  110. package/lib/common/dialog.js +26 -12
  111. package/lib/common/dialog.js.map +1 -1
  112. package/lib/configuration.d.ts +2 -0
  113. package/lib/configuration.js +1 -0
  114. package/lib/configuration.js.map +1 -1
  115. package/lib/dependency-injection/RootServices.d.ts +2 -0
  116. package/lib/dependency-injection/RootServices.js.map +1 -1
  117. package/lib/environment.json +1 -1
  118. package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -1
  119. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +0 -26
  120. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +0 -15
  121. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -1
  122. package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +0 -59
  123. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +0 -10
  124. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -1
  125. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +0 -13
  126. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +0 -7
  127. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -1
  128. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +0 -55
  129. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +0 -12
  130. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -1
  131. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +0 -5
  132. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +0 -7
  133. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -1
  134. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +0 -23
  135. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +0 -15
  136. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -1
  137. package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +0 -62
  138. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +0 -1
  139. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
  140. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +0 -8
  141. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js +0 -1
  142. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js.map +1 -1
  143. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.d.ts +0 -45
  144. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js +0 -46
  145. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js.map +1 -1
  146. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +0 -104
  147. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +0 -1
  148. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -1
  149. package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +0 -129
  150. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js +0 -24
  151. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -1
  152. package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +0 -22
  153. package/lib/generated-proto/pb_schema/cdp/cof/config_response.js +0 -1
  154. package/lib/generated-proto/pb_schema/cdp/cof/config_response.js.map +1 -1
  155. package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +0 -510
  156. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +0 -415
  157. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
  158. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.d.ts +0 -9
  159. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js +0 -3
  160. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js.map +1 -1
  161. package/lib/generated-proto/pb_schema/cdp/cof/namespace.d.ts +0 -1
  162. package/lib/generated-proto/pb_schema/cdp/cof/namespace.js +0 -2
  163. package/lib/generated-proto/pb_schema/cdp/cof/namespace.js.map +1 -1
  164. package/lib/generated-proto/pb_schema/common/ruid.d.ts +0 -27
  165. package/lib/generated-proto/pb_schema/common/ruid.js +0 -20
  166. package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -1
  167. package/lib/generated-proto/pb_schema/common/value.d.ts +0 -9
  168. package/lib/generated-proto/pb_schema/common/value.js +0 -1
  169. package/lib/generated-proto/pb_schema/common/value.js.map +1 -1
  170. package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +0 -105
  171. package/lib/generated-proto/pb_schema/google/protobuf/any.js +0 -1
  172. package/lib/generated-proto/pb_schema/google/protobuf/any.js.map +1 -1
  173. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +0 -64
  174. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js +0 -1
  175. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js.map +1 -1
  176. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +0 -54
  177. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js +0 -1
  178. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js.map +1 -1
  179. package/lib/generated-proto/pb_schema/lenses/geocircle.js +0 -1
  180. package/lib/generated-proto/pb_schema/lenses/geocircle.js.map +1 -1
  181. package/lib/generated-proto/pb_schema/lenses/geopoint.js +0 -1
  182. package/lib/generated-proto/pb_schema/lenses/geopoint.js.map +1 -1
  183. package/lib/generated-proto/pb_schema/lenses/launch_params.js +0 -1
  184. package/lib/generated-proto/pb_schema/lenses/launch_params.js.map +1 -1
  185. package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +0 -2
  186. package/lib/generated-proto/pb_schema/lenses/launchdata.js +0 -3
  187. package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -1
  188. package/lib/generated-proto/pb_schema/lenses/lures.d.ts +0 -2
  189. package/lib/generated-proto/pb_schema/lenses/lures.js +0 -1
  190. package/lib/generated-proto/pb_schema/lenses/lures.js.map +1 -1
  191. package/lib/generated-proto/pb_schema/lenses/persistent_store.js +0 -1
  192. package/lib/generated-proto/pb_schema/lenses/persistent_store.js.map +1 -1
  193. package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +0 -19
  194. package/lib/generated-proto/pb_schema/lenses/snappable.js +0 -2
  195. package/lib/generated-proto/pb_schema/lenses/snappable.js.map +1 -1
  196. package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +0 -18
  197. package/lib/generated-proto/pb_schema/lenses/user_data.js +0 -1
  198. package/lib/generated-proto/pb_schema/lenses/user_data.js.map +1 -1
  199. package/lib/legal/legalPrompt.js +29 -27
  200. package/lib/legal/legalPrompt.js.map +1 -1
  201. package/lib/lens/LensRepository.d.ts +5 -3
  202. package/lib/lens/LensRepository.js +8 -5
  203. package/lib/lens/LensRepository.js.map +1 -1
  204. package/lib/lens/assets/LensAssetsProvider.js +18 -3
  205. package/lib/lens/assets/LensAssetsProvider.js.map +1 -1
  206. package/lib/lens/lensHttpUtil.d.ts +3 -2
  207. package/lib/lens/lensHttpUtil.js +5 -5
  208. package/lib/lens/lensHttpUtil.js.map +1 -1
  209. package/lib/lens-core-module/generated-types.d.ts +21 -0
  210. package/lib/lens-core-module/generated-types.js.map +1 -1
  211. package/lib/lensCoreWasmVersions.json +3 -3
  212. package/lib/media-sources/MediaStreamSource.js +4 -0
  213. package/lib/media-sources/MediaStreamSource.js.map +1 -1
  214. package/lib/metrics/businessEventsReporter.d.ts +3 -2
  215. package/lib/metrics/businessEventsReporter.js +13 -7
  216. package/lib/metrics/businessEventsReporter.js.map +1 -1
  217. package/lib/metrics/operational/operationalMetricsReporter.d.ts +3 -2
  218. package/lib/metrics/operational/operationalMetricsReporter.js +8 -6
  219. package/lib/metrics/operational/operationalMetricsReporter.js.map +1 -1
  220. package/lib/remote-configuration/cofHandler.d.ts +10 -6
  221. package/lib/remote-configuration/cofHandler.js +77 -67
  222. package/lib/remote-configuration/cofHandler.js.map +1 -1
  223. package/lib/remote-configuration/remoteConfiguration.d.ts +9 -6
  224. package/lib/remote-configuration/remoteConfiguration.js +5 -13
  225. package/lib/remote-configuration/remoteConfiguration.js.map +1 -1
  226. package/package.json +1 -1
package/README.md CHANGED
@@ -2,31 +2,60 @@
2
2
 
3
3
  The Camera Kit Web SDK allows web developers to build Snap's core AR Lens technology into their applications.
4
4
 
5
- ## Getting started
5
+ ## Minimum browser requirements
6
6
 
7
- First, familiarize yourself with the [Camera Kit docs](https://docs.snap.com/camera-kit/home). This covers access to the Camera Kit Portal, where to find your API Token, how to manage lenses and lens groups, etc.
7
+ - **Chrome 73+**
8
+ - **Safari 15+**
9
+ - MacOS 12+, iOS 15+, iPadOS 15+
10
+ - SIMD: Unsupported
11
+ - Web Worker Mode\*: Unsupported
12
+ - **Edge 79+**
13
+ - Edge is still currently under evaluation. However, since New Edge is Chromium based, the expectations are similar to that of Chrome.
14
+ - **Firefox** - Under Evaluation
15
+ - Web Worker Mode\*: Firefox 105+
8
16
 
9
- Most of the content found here can also be found on the [Camera Kit docs](https://docs.snap.com/camera-kit/quick-start/integrate-sdk/integrate-sdk-web/web-configuration) site.
17
+ \*Web Worker Mode requires `OffscreenCanvas` support.
10
18
 
11
- ### Installing the SDK
19
+ ## Prerequisites
20
+
21
+ ### Snap Developer set up
22
+ You'll need a Snap Developer account, and you'll need to apply for access to Camera Kit Web SDK. You can find more info on that [here](camera-kit/quick-start/setting-up-accounts).
23
+
24
+ You may also want to familiarize yourself with how to access and manage AR content (i.e. Lenses). You read about that [here](/camera-kit/quick-start/build-manage-ar-content/camera-kit-portal).
25
+
26
+ ### Development environment
27
+ This guide assumes you've already set up an [NPM](https://www.npmjs.com/) package, you're using [TypeScript](https://www.typescriptlang.org/), and have some way to build and host your project during development (e.g. using [Webpack](https://webpack.js.org/)).
28
+
29
+ #### Using the SDK in a JavaScript project
30
+
31
+ The SDK is authored in TypeScript, and distributes type definitions. All the examples here are presented in TypeScript. We encourage the use of TypeScript in projects that consume the SDK – but it's also fully compatible with JavaScript projects as well.
32
+
33
+ ### Content Security Policy
34
+
35
+ If your project already has a [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) in place, you'll likely need to make some changes in order for Camera Kit Web SDK to work.
36
+
37
+ When it bootstraps, Camera Kit Web SDK downloads an executable WebAssembly file containing the Lens rendering engine. This file is served from an optimized CDN managed by Snap. You'll need to make sure your Content Security Policy allows this file to be executed.
38
+
39
+ - `connect-src` must include `https://*.snapar.com`, otherwise Camera Kit Web will fail to initialize.
40
+ - `script-src` must include `https://cf-st.sc-cdn.net/ blob: 'wasm-unsafe-eval'`.
41
+
42
+ _Note: Some older browser versions may not support the `'wasm-unsafe-eval'` source value, and it may be necessary to use `'unsafe-eval'` to allow Camera Kit's downloaded WebAssembly to run._
43
+
44
+ ## Installing the SDK
12
45
 
13
46
  ```
14
47
  npm install @snap/camera-kit
15
48
  ```
16
49
 
17
- ### Using the SDK in a Javascript project
18
-
19
- The SDK is authored in TypeScript, and distributes type definitions. All the examples here are presented in TypeScript. We encourage the use of TypeScript in projects that consume the SDK – but it's also fully compatible with Javascript projects as well.
50
+ You can find the Camera Kit Web SDK package on npmjs.com [here](https://www.npmjs.com/package/@snap/camera-kit).
20
51
 
21
- ### Importing the SDK
52
+ ### Importing Camera Kit
22
53
 
23
- Currently, the SDK distributes [Javascript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). We may support other module formats in the future (e.g. CommonJS), but for now you'll need to use `import` syntax to use the Camera Kit Web SDK.
54
+ Currently, the SDK distributes [JavaScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). We may support other module formats in the future (e.g. CommonJS), but for now you'll need to use `import` syntax to use the Camera Kit Web SDK.
24
55
 
25
- If you're working in a project that uses a bundler (e.g. Webpack or Rollup), or builds using the TypeScript compiler, this shouldn't be an issue. If you're not using a bundler, many browsers now support `import` syntax natively – if you don't need support for older browsers (or IE), no bundler is necessary.
56
+ ## Bootstrapping the SDK
26
57
 
27
- ### Bootstrapping the SDK
28
-
29
- With the SDK installed and capable of being imported, the first thing to do is bootstrap the SDK. This tells the SDK to download the LensCore WebAssembly runtime, which will be used to render Lenses. It also allows you to configure the SDK according to your needs.
58
+ With the SDK installed and imported, the first thing to do is bootstrap the SDK. When bootstrapping, the SDK will download the WebAssembly runtime which is used to render Lenses. This is also where you'll configure the SDK according to your needs.
30
59
 
31
60
  To call {@link bootstrapCameraKit}, you'll need to provide a `apiToken`. Once you've completed the [Getting set up in our portals](https://docs.snap.com/camera-kit/guides/quick-start/integrate-sdk/setting-up-accounts) section of the Getting Started guide, you'll be able to find this in the [Snap Kit Portal](https://devportal.snap.com/manage).
32
61
 
@@ -34,14 +63,14 @@ To call {@link bootstrapCameraKit}, you'll need to provide a `apiToken`. Once yo
34
63
  import { boostrapCameraKit } from "@snap/camera-kit";
35
64
 
36
65
  (async function main() {
37
- const apiToken = "API Token value copied from the Camera Kit Portal";
66
+ const apiToken = "Your API Token value copied from the Camera Kit Portal";
38
67
  const cameraKit = await bootstrapCameraKit({ apiToken });
39
68
  })();
40
69
  ```
41
70
 
42
- ### Creating a CameraKitSession
71
+ ## Creating a `CameraKitSession`
43
72
 
44
- In order to render Lenses, you must first create a {@link CameraKitSession}. Each session represents a rendering pipeline - it connects an input media source (e.g. a webcam) to the LensCore AR engine, applies a Lens, and renders the output to a `<canvas>` element.
73
+ In order to render Lenses, you must first create a {@link CameraKitSession}. Each session represents a rendering pipeline - it connects an input media source (e.g. a webcam) to Camera Kit's AR engine, applies a Lens, and renders the output to a `<canvas>` element.
45
74
 
46
75
  There are two ways to create a session. If you already have a `<canvas>` element on your page that you'd like for the {@link CameraKitSession} to render into, you can pass it to Camera Kit when creating the session. Otherwise, the session will create a new `<canvas>` element which you can add to the DOM.
47
76
 
@@ -56,63 +85,71 @@ const session = await cameraKit.createSession();
56
85
  canvasContainer.appendChild(session.output.live);
57
86
  ```
58
87
 
59
- _There are actually two different output canvases: `live` and `capture`. These correspond to the two different RenderTargets to which a Lens may render. The `live` output renders a view suitable for presentation to the current user. Some Lenses may also render to the `capture` output, which renders content suitable for viewing by other users._
88
+ There are actually two different output canvases:
89
+
90
+ - `live`: This canvas renders content intended for the Lens user. Depending on the Lens being used, this canvas may include UI elements, prompts, or other content that is only meant to be seen by the user of the Lens.
91
+ - `capture`: This canvas renders content intended for presenting to other users.
92
+
93
+ These two output canvases correspond to the two different [RenderTargets](https://docs.snap.com/lens-studio/references/guides/lens-features/scene-set-up/camera#render-target) a Lens may use to render its content. Not all Lenses will render different content to `live` vs. `capture`, so it's important to understand how the Lenses you'll be using use these two different outputs.
94
+
95
+ > No rendering will happen yet, and the output canvas associated with this new `CameraKitSession` will be blank. Frames are not processed until you start [playback](#playback) by calling the `CameraKitSession`'s `play()` method. This will be discussed below.
96
+
97
+ ## Creating a `CameraKitSource`
98
+
99
+ In order for Camera Kit Web SDK to render anything, it must have a source of imagery to be processed by the AR engine. The Lens content will be rendered on top of this source media.
100
+
101
+ The most common source of input media is the user's webcam. Camera Kit Web SDK provides a helper method to create a `CameraKitSource` object from a [`MediaStream`](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream). You can use [`getUserMedia`](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) to obtain a `MediaStream` with video from the user's webcam.
60
102
 
61
- ### Obtaining a media source
103
+ > Note that calling `getUserMedia` will prompt the user to grant the webpage access to their camera.
62
104
 
63
- The most common source will be the user's webcam. Camera Kit Web SDK provides helper methods to create a {@link CameraKitSource} object from
64
- a [`MediaStream`](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/MediaStream), or directly from a user's webcam via [`getUserMedia`](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia).
105
+ Once we have a `CameraKitSource`, we can tell the `CameraKitSession` to use this source for rendering.
65
106
 
66
107
  ```ts
67
- import { createMediaStreamSource } from "@snap/camera-kit";
108
+ import { createMediaStreamSource, Transform2D } from "@snap/camera-kit"
68
109
 
69
- // ...
70
110
  const stream = await navigator.mediaDevices.getUserMedia({ video: true });
71
- const source = createMediaStreamSource(stream, {
72
- transform: Transform2D.MirrorX,
73
- cameraType: "front",
74
- });
75
- session.setSource(source);
111
+ const source = createMediaStreamSource(stream, { transform: Transform2D.MirrorX, cameraType: 'front' });
112
+ await session.setSource(source);
76
113
  ```
77
114
 
78
- _Note that calling `getUserMedia` will prompt the user to grant the webpage access to the webcam._
115
+ In this example, we also mirror the source stream (which feels more natural in most cases), and we indicate this source comes from a front-facing camera. To read more about these options, see [below](#customizing-camerakitsource).
116
+
117
+ Camera Kit Web SDK has helper methods to create a `CameraKitSource` from:
118
+
119
+ - A `MediaStream` object, which could come from the user's camera, a WebRTC connection, a `<canvas>` via the [`captureStream()` method](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream), or elsewhere.
120
+ - A `<video>` element (i.e. `HTMLVideoElement`)
121
+ - An `<img>`element (i.e. `HTMLImageElement`)
79
122
 
80
- ### Applying a Lens
123
+ ## Loading, applying, and removing Lenses
81
124
 
82
- In order to apply a lens to our session, we first have to fetch metadata for the lens we wish to apply. We can configure a group of lenses and get all the lenses in that group – this could be useful if we want to allow the user to select a lens from the group. Or if we know the specific lens we want to apply, we can provide its unique ID (along with the ID of a group that contains that lens) and get back just the single lens.
125
+ In Camera Kit Web SDK -- just like in the Snapchat app itself -- each individual AR experience is called a Lens. Lenses are created using [Lens Studio](https://ar.snap.com/en-US/lens-studio). You can find more information about acquiring Lenses [here](https://docs.snap.com/camera-kit/quick-start/build-manage-ar-content/ar-overview).
83
126
 
84
- In the [Camera Kit Portal](https://camera-kit.snapchat.com/), you can find available lenses and add them to lens groups. Once you've chosen a lens or lens group to load, you can use the Lens repository to fetch the lens metadata. Then you can apply the lens to the session.
127
+ You can find Lens and Lens Groups in the [Camera Kit Portal](https://camera-kit.snapchat.com/). This is where you can manage your Lenses and Lens Groups and where you can find Lens IDs and Lens Group IDs. You can read more about managing Lenses in the Camera Kit Portal [here](https://docs.snap.com/camera-kit/quick-start/build-manage-ar-content/camera-kit-portal).
85
128
 
86
- _The [Camera Kit docs](https://docs.snap.com/camera-kit/guides/quick-start/build-manage-ar-content/camera-kit-portal) include info on how to set up Lenses and Lens Groups._
129
+ Before applying a Lens to our session, we have to load metadata about that Lens. Lenses can be loaded either one at a time, or entire Lens Groups can be loaded at once. You'll need a Lens ID and its Lens Group ID to complete this step.
87
130
 
88
131
  ```ts
89
- // A single lens
90
- const lens = await cameraKit.lensRepository.loadLens("A lens ID found in the Camera Kit Portal", "A lens group ID");
91
- session.applyLens(lens);
132
+ // Loading a single lens
133
+ const lens = await cameraKit.lensRepository.loadLens("<Lens ID>", "<Lens Group ID>");
134
+ await session.applyLens(lens);
92
135
 
93
- // One or more lens groupslenses from all groups are returned as a single array of lenses.
136
+ // Loading one or more Lens GroupsLenses from all groups are returned as a single array of lenses.
94
137
  const { lenses } = await cameraKit.lensRepository.loadLensGroups([
95
- "A lens group ID",
96
- "These can be found in the Camera Kit Portal",
138
+ "<Lens Group ID 1>",
139
+ "<Lens Group ID 2>",
97
140
  ]);
98
- session.applyLens(lenses[0]);
141
+ await session.applyLens(lenses[0]);
99
142
  ```
100
143
 
101
- ### Setting the render size
102
-
103
- By default, Camera Kit will render its output at the same resolution as the video input you provided. But you can also tell Camera Kit to render at a different resolution.
104
-
105
- Keep in mind that this controls LensCore's render resolution, and not (necessarily) the size at which the output canvas is displayed to the user. The output canvas may be sized using HTML and CSS, and may apply its own scaling to the rendered output.
106
-
107
- Most of the time you'll not need to set the render size – but it could be useful if your video source is, say, very high resolution. In that case, you may observe better performance by telling Camera Kit to render at a lower resolution.
144
+ ### Removing the Lens
108
145
 
146
+ You can also remove the currently-applied Lens:
109
147
  ```ts
110
- session.setRenderSize(width, height);
148
+ await session.removeLens();
111
149
  ```
150
+ After removing the Lens, when the session renders it will simply render the input media directly to the output canvas.
112
151
 
113
- _Note that when calling [`getUserMedia`](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia), best performance can be achieved by requesting the resolution you want to display. This can be done using [constraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#parameters)_
114
-
115
- ### Session playback
152
+ ## Playback
116
153
 
117
154
  The {@link CameraKitSession} will only process input video frames and render them to the output when you tell it to do so – this way, you can control when Camera Kit is using a client's resources (e.g. CPU and GPU compute cycles). You can tell the session to `play` or `pause`.
118
155
 
@@ -123,9 +160,45 @@ session.play();
123
160
  session.pause();
124
161
  ```
125
162
 
126
- _You can also tell the session which output – `live` or `capture` - to play / pause. By default, `play` will start rendering the `live` output and `pause` will pause rendering all outputs._
163
+ ### Playing and pausing the different RenderTargets
164
+
165
+ By default, `play()` will only begin rendering the `live` output canvas. You can specify which canvas to render by passing an argument:
166
+
167
+ ```ts
168
+ session.play('live');
169
+ session.play('capture');
170
+ ```
171
+
172
+ Calling `pause()` with no arguments will pause both outputs. But just like with `play()`, you can pass an argument to select which canvas to pause.
173
+
174
+ ```ts
175
+ session.pause('live');
176
+ session.pause('capture');
177
+ ```
178
+
179
+ > - _`live`: This canvas renders content intended for the Lens user. Depending on the Lens being used, this canvas may include UI elements, prompts, or other content that is only meant to be seen by the user of the Lens._
180
+ > - _`capture`: This canvas renders content intended for presenting to other users._
181
+
182
+ ## Error Handling
127
183
 
128
- ### Putting it all together
184
+ Camera Kit Web SDK methods may throw errors, or return rejected Promises -- these are documented in the [API docs](https://kit.snapchat.com/reference/CameraKit/web/0.12.0/index.html). It is good practice to handle such cases, to provide a good experience to your users.
185
+
186
+ Errors may also occur during Lens rendering. For example, Lenses contain their own scripting, which could throw an error. A rendering error could also occur if a Lens attempts to use a feature that is not supported by Camera Kit Web SDK.
187
+
188
+ When a `LensExecutionError` such as these occurs, the Lens is **automatically removed** from the `CameraKitSession`. An error event is emitted so that your application can respond appropriately. You can listen to these error events like so:
189
+
190
+ ```ts
191
+ session.events.addEventListener('error', (event) => {
192
+ console.error(event.detail.error);
193
+
194
+ if (event.detail.error.name === 'LensExecutionError') {
195
+ // The currently-applied Lens encountered a problem that is most likely unrecoverable and the Lens has been removed.
196
+ // Your application may want to prevent this Lens from being applied again.
197
+ }
198
+ });
199
+ ```
200
+
201
+ ## Putting it all together
129
202
 
130
203
  Using the examples above, here's a complete example of the minimal Camera Kit Web SDK integration:
131
204
 
@@ -133,37 +206,139 @@ Using the examples above, here's a complete example of the minimal Camera Kit We
133
206
  import { boostrapCameraKit, createMediaStreamSource } from "@snap/camera-kit";
134
207
 
135
208
  (async function main() {
136
- const apiToken = "API Token value copied from the SnapKit developer portal";
209
+ const apiToken = "Your API Token value copied from the SnapKit developer portal";
137
210
  const cameraKit = await bootstrapCameraKit({ apiToken });
138
211
 
139
212
  const canvas = document.getElementById("my-canvas");
140
- const session = await cameraKit.createSession(canvas);
213
+ const session = await cameraKit.createSession({ liveRenderTarget: canvas });
214
+ session.events.addEventListener('error', (event) => {
215
+ if (event.detail.error.name === 'LensExecutionError') {
216
+ console.log('The current Lens encountered an error and was removed.', event.detail.error);
217
+ }
218
+ });
141
219
 
142
220
  const stream = await navigator.mediaDevices.getUserMedia({ video: true });
143
- const source = createMediaStreamSource(stream, {
144
- transform: Transform2D.MirrorX,
145
- cameraType: "front",
146
- });
147
- session.setSource(source);
221
+ const source = createMediaStreamSource(stream, { transform: Transform2D.MirrorX, cameraType: 'front' });
222
+ await session.setSource(source);
148
223
 
149
- const lens = await cameraKit.lensRepository.loadLens("A lens ID found in the Camera Kit Portal", "A lens group ID");
224
+ const lens = await cameraKit.lensRepository.loadLens("<Lens ID>", "<Lens Group ID>");
150
225
  await session.applyLens(lens);
151
226
 
152
227
  await session.play();
153
228
  console.log("Lens rendering has started!");
154
229
  })();
230
+
231
+ main();
155
232
  ```
156
233
 
157
- ### Content Security Policy
234
+ ## Advanced use cases
235
+
236
+ ### Logging
158
237
 
159
- Camera Kit Web SDK downloads an executable WebAssembly file containing the Lens rendering engine. This file is served from an optimized CDN. If you have a [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) in place on your page, you'll likely need to make some changes in order for Camera Kit to work.
238
+ By default, Camera Kit Web SDK does very minimal logging. Specifying `'console'` as logger will cause more log statements to be printed to the browser's console, which may be useful during development.
160
239
 
161
- #### `connect-src`
240
+ ```ts
241
+ const cameraKit = await bootstrapCameraKit({
242
+ apiToken: '<apiToken>',
243
+ logger: 'console',
244
+ });
245
+ ```
162
246
 
163
- Must include `https://*.snapchat.com`, otherwise Camera Kit Web will fail to initialize.
247
+ ### Keyboard support for Lenses
164
248
 
165
- #### `script-src`
249
+ Some Lenses allow for keyboard input. The SDK provides a `<textarea>` (`HTMLTextAreaElement`) element that can be added to your page, and will send its text to the active Lens whenever the user presses the `Enter` key.
166
250
 
167
- Must include `https://cf-st.sc-cdn.net/ blob: 'wasm-unsafe-eval'`.
251
+ ```ts
252
+ const textAreaContainer = document.getElementById('text-area-container');
253
+ const textArea = session.keyboard.getElement();
254
+ textAreaContainer.appendChild(textArea);
255
+ ```
168
256
 
169
- _Note: Some older browser versions may not support the `'wasm-unsafe-eval'` source value, and it may be necessary to use `'unsafe-eval'` to allow Camera Kit's downloaded WebAssembly to run._
257
+ Alternatively, an event is emitted when a Lens is expecting text input. You can then implement your own UI and logic for obtaining text input from your users, and then send it back to the Lens. For example, something like:
258
+
259
+ ```ts
260
+ const input = document.getElementById('my-text-area');
261
+ session.keyboard.addEventListener('active', () => {
262
+ input.classList.remove('hidden');
263
+ });
264
+
265
+ input.addEventListener('keyup', () => {
266
+ session.keyboard.sendInputToLens(input.value);
267
+ })
268
+ ```
269
+
270
+ See an example of this [here](https://camera-kit.snapchat.com/websdk/sample/keyboard).
271
+
272
+ ### Customizing `CameraKitSource`
273
+
274
+ #### Setting the render size
275
+
276
+ By default, Camera Kit will render its output at the same resolution as the video input you provided. But you can also tell Camera Kit to render at a different resolution.
277
+
278
+ Keep in mind that this controls Camera Kit's render resolution, and not (necessarily) the size at which the output canvas is displayed to the user. The output canvas may be sized using HTML and CSS, and may apply its own scaling to the rendered output.
279
+
280
+ Most of the time you'll not need to set the render size – but it could be useful if your video source is, say, very high resolution. In that case, you may observe better performance by telling Camera Kit to render at a lower resolution.
281
+
282
+ ```ts
283
+ await session.setSource(source)
284
+ // This must be done *after* calling `setSource()`
285
+ await source.setRenderSize(width, height);
286
+ ```
287
+
288
+ > When calling [`getUserMedia`](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia), best performance can be achieved by requesting the resolution at which you want to render. This can be done using [constraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#parameters). Then you won't have to use `setRenderSize` at all.
289
+
290
+ #### Camera type
291
+
292
+ When setting up a `CameraKitSource`, you can specify whether or not it is a front facing camera or a back facing camera. By default, the media source will be treated as a front facing camera. If it is a back facing camera be sure to specify it as such when you create your source; this ensures that Lenses created for back facing camera's (e.g. World AR) render properly.
293
+
294
+ ```ts
295
+ const stream = await navigator.mediaDevices.getUserMedia(constraints);
296
+ const source = createMediaStreamSource(stream, { cameraType: 'back' });
297
+ await session.setSource(source);
298
+ ```
299
+
300
+ #### FPS limit
301
+
302
+ In some cases, it may be desirable to set a limit on the FPS at which Camera Kit renders. By default, Camera Kit will attempt to render frames at the same rate as the source media. But, for example, if your input media source has a very high framerate you may want to limit Camera Kit's rendering framerate to achieve better performance.
303
+
304
+ This can be done at the `CameraKitSession` level:
305
+
306
+ ```ts
307
+ await session.setFPSLimit(60);
308
+ ```
309
+
310
+ Or at the `CameraKitSource` level:
311
+
312
+ ```ts
313
+ const stream = await navigator.mediaDevices.getUserMedia(constraints);
314
+ const source = createMediaStreamSource(stream, { fpsLimit: 60 });
315
+ ```
316
+
317
+ These options can also be used with any of the [create source helpers](#creating-a-camerakitsource).
318
+
319
+ #### 2D transforms
320
+
321
+ Any `CameraKitSource` can be transformed using a matrix, to rotate, scale, or mirror the source media. This is most often used to mirror a front-facing camera stream so that it appears more natural to the user.
322
+
323
+ ```ts
324
+ import { Transform2D } from "@snap/camera-kit";
325
+
326
+ await session.setSource(source)
327
+ // This must be done *after* calling `setSource()`
328
+ source.setTransform(Transform2D.MirrorX);
329
+ ```
330
+
331
+ ### Metrics reporting
332
+
333
+ Camera Kit Web SDK reports certain important events which may be of interest to the application.
334
+
335
+ > This is an unstable portion of the Camera Kit Web SDK's public API -- the specific events and their properties may change between versions of the SDK, without warning. We currently offer these events as a convenient way to gather more information from the SDK, but if you need to report accurate metrics (e.g. number of lens views), that is currently something you will have to implement in your application.
336
+
337
+ Currently, the only event that may be of interest is the `lensView` event. It is emitted whenever a lens is _removed_ from the `CameraKitSession`, indicating a complete lens view. It contains information about the lens' performance (e.g. fps, frame processing times, etc.) and how long the lens was applied.
338
+
339
+ You may listen to these events like so:
340
+ ```ts
341
+ cameraKit.metrics.addEventListener('lensView', (event) => {
342
+ console.debug(event.detail);
343
+ });
344
+ ```