@snap/camera-kit
Version:
Camera Kit Web
186 lines (119 loc) • 5.53 kB
Markdown
[**CameraKit Web SDK v1.13.0**](../README.md)
***
[CameraKit Web SDK](../globals.md) / CameraKitBootstrapConfiguration
# Interface: CameraKitBootstrapConfiguration
Configuration which must be provided when calling [bootstrapCameraKit](../functions/bootstrapCameraKit.md). These values are used to create various
CameraKit components.
## Properties
### apiToken
> **apiToken**: `string`
Long-lived token granting your application access to CameraKit APIs. This is found in the SnapKit Dev Portal,
where it's called the API Token.
***
### logger?
> `optional` **logger**: [`Logger`](../type-aliases/Logger.md) \| `"noop"` \| `"console"`
Determine where to print CameraKit log messages. By default no logs will be printed.
CameraKit emits log messages to help diagnose and root cause issues that may occur during the development of a
host application. The printing of these can be controlled via the following options:
- `"noop"`: log messages are ignored.
- `"console"`: log messages are printed to console.
- A custom [Logger](../type-aliases/Logger.md) instance can be provided to integrate with an existing logging system.
***
### logLevel?
> `optional` **logLevel**: [`LogLevel`](../type-aliases/LogLevel.md)
Log only if a logged entry level is greater than or equal to this level. Here is the order of levels:
error > warn > log = info > debug. Default value is "info".
***
### lensPerformance?
> `optional` **lensPerformance**: [`EstimatedLensPerformance`](EstimatedLensPerformance.md) \| `Promise`\<[`EstimatedLensPerformance`](EstimatedLensPerformance.md)\>
Some lenses may decide to modify their behavior based on the performance of the current environment. If you are
using such lenses, providing an estimation of lens performance may lead to better user experience (especially on
low-performance devices).
Running the [estimateLensPerformance](../functions/estimateLensPerformance.md) function will run benchmarks and estimate an appropriate lens
performance cluster (i.e. a performance rating) based on the current environment.
Lower cluster = worse expected performance capability.
#### Example
```ts
import { bootstrapCameraKit, estimateLensPerformance } from '@snap/camera-kit`
const cameraKit = await bootstrapCameraKit({
apiToken: '...',
lensPerformance: estimateLensPerformance(),
})
```
***
### lensCoreOverrideUrls?
> `optional` **lensCoreOverrideUrls**: `object`
In recommended production deployments, the WebAssembly assets required by CameraKit will be downloaded from an
optimized CDN. But sometimes (e.g. during development or within a CI pipeline), it may be necessary to download
these assets from somewhere else.
This configuration option allows the application to specify URLs to be used for both the WebAssembly and JS glue
file that are used to run and interact with CameraKit's rendering engine.
#### wasm
> **wasm**: `string`
#### js
> **js**: `string`
***
### wasmEndpointOverride?
> `optional` **wasmEndpointOverride**: `string`
In recommended production deployments, the WebAssembly assets required by CameraKit will be downloaded from an
optimized CDN. But sometimes during development or within a CI pipeline, it may be necessary to download these
assets from somewhere else. With a provided `wasmEndpointOverride`, asset URLs will be automatically generated
based on this root endpoint.
***
### analyticsId?
> `optional` **analyticsId**: `string`
Applications may optionally provide a unique identifier called analyticsId. This ID would enable Camera Kit to
improve data reporting and accuracy and to better support potential needs related to an application's lens and
user analytics.
***
### fonts?
> `optional` **fonts**: [`Font`](Font.md)[]
An array of fonts to be used by Camera Kit for text rendering.
Lenses usually have their own font assets, but emojis are often not embedded.
As a result, you may need to provide additional fonts (e.g., an emoji font) to ensure all glyphs render
correctly.
#### Example
```ts
fonts: [
{
name: 'EmojiFont',
data: emojiFontArrayBuffer, // Your emoji font data goes here
},
]
```
***
### lensHttpHandler?
> `optional` **lensHttpHandler**: [`LensHttpHandler`](../type-aliases/LensHttpHandler.md)
An optional custom HTTP handler for requests made by a Lens.
This handler allows you to intercept and customize the behavior of HTTP requests,
such as adding authentication headers, logging request details, or replacing the default
HTTP library used by the Lens system.
If not specified, the Lens system will use a default HTTP implementation.
#### Example
Here is an example of how to configure a custom `LensHttpHandler` to add an authentication token:
```typescript
const customLensHttpHandler: LensHttpHandler = async (url, init, lensRequest) => {
// Add an authentication token to the headers
const sessionToken = await getAuthToken();
const updatedInit = {
...init,
headers: {
...init.headers,
'Authorization': `Bearer ${sessionToken}`,
},
};
// Log the request details for debugging
console.log(`Requesting ${lensRequest.url} from lens: ${lensRequest.lens.name}`);
// Use fetch to perform the HTTP request
return fetch(url, updatedInit);
};
const cameraKit = bootstrapCameraKit({
apiToken,
lensHttpHandler: customLensHttpHandler,
});
```
***
### trustedTypesPolicyName?
> `optional` **trustedTypesPolicyName**: `string`
The name of the Trusted Types policy to use when loading scripts.
Defaults to "snap-camera-kit".