@snap/camera-kit
Version:
Camera Kit Web
51 lines (36 loc) • 2.03 kB
Markdown
[**CameraKit Web SDK v1.4.0**](../README.md)
***
[CameraKit Web SDK](../globals.md) / createExtension
# Function: createExtension()
> **createExtension**(): `PartialContainer`
Extensions offer a way to provide custom implementations of certain parts of the CameraKit SDK.
This enables more advanced use-cases, in which the default behavior of the SDK is substantially altered. For example,
replacing the default implementation that loads remote lens assets with a custom implementation that returns
different assets based on some business logic within the application.
An extension is implemented as a PartialContainer – a collection of factory functions, each with its own
dependencies, which each provide some "Service". A Service can be of any type, and the CameraKit SDK defines its
own Services, some of which can be overridden by providing a custom implementation of the type via an extension.
Here's an example of how extensions might be used:
```ts
import { bootstrapCameraKit, createExtension, remoteMediaAssetLoaderFactory } from '@snap/camera-kit'
const myCustomRemoteAssetLoader = Injectable(
remoteMediaAssetLoaderFactory.token,
[remoteMediaAssetLoaderFactory.token] as const,
(defaultLoader: AssetLoader): AssetLoader => {
return async (asset, lens) => {
if (lens?.id === MY_SPECIAL_LENS) {
return (await fetch('my/asset.glb')).arrayBuffer()
}
return defaultLoader(asset, lens)
}
},
)
const myExtension = createExtension().provides(myCustomRemoteAssetLoader);
const cameraKit = bootstrapCameraKit(config, container => container.provides(myExtension));
```
This also enables greater modularity – the person/team creating the extension can do so in their own package, which
could be shared by many applications that all require the same functionality.
## Returns
`PartialContainer`
A PartialContainer which can be used to create a collection of Services, and can later be provided
to CameraKit's DI container during [bootstrapCameraKit](bootstrapCameraKit.md).