Config
of the SDK supports the following initialization parameters:
Parameter | Description | Type | Required |
---|---|---|---|
module | The module configuration. | type ModuleConfig = { beautify: boolean // The default is `true`. segmentation: boolean // The default is `false`. } |
No. Default value: {beautify: true, segmentation: false} . |
auth | The authentication information. | type AuthConfig = { licenseKey: string // View in Web Licenses of the console. appId: string // View in Account Information > Basic Information of the console. authFunc:() => Promise<{ signature:string, timestamp:string }> // See documentation about the configuration and use of licenses } |
Yes |
input | The input. | MediaStream|HTMLImageElement|String | No |
camera | The built-in camera configuration. | type CameraConfig = { width: number, // The video width. height: number, // The video height. mirror: boolean, // Whether to horizontally flip the video. frameRate: number // The capturing frame rate. } |
No |
beautify | The beautification effects. | type BeautifyOptions = { whiten?: number, // The brightening effect. Value range: 0-1. dermabrasion?: number // The smooth skin effect. Value range: 0-1. lift?: number // The slim face effect. Value range: 0-1. shave?: number // The face width. Value range: 0-1. eye?: number // The big eyes effect. Value range: 0-1. chin?: number // The chin effect. Value range: 0-1. } |
No |
background | The background configuration. | type BackgroundOptions = { type: 'image' | 'blur' | 'transparent', src?: string } |
No |
loading | The configuration of the built-in loading icon. | type loadingConfig = { enable: boolean, size?: number lineWidth?: number strokeColor?: number } |
No |
let effectList = [];
let filterList = [];
// Using the callbacks of the SDK
sdk.on('created', () => {
// Pull and display the filter and effect list in the `created` callback
sdk.getEffectList({
Type: 'Preset',
Label: 'Makeup',
}).then(res => {
effectList = res
});
sdk.getCommonFilter().then(res => {
filterList = res
})
})
sdk.on('cameraReady', async () => {
// By getting the output stream in the `cameraReady` callback, you can display a video image sooner, but the initialization parameters have not taken effect at this point.
// You can choose this method if you want to display a video image as soon as possible but do not need to apply effects to the video the moment it is displayed.
// You don’t need to update the stream after the effects start working.
const arStream = await ar.getOutput();
// Play the stream locally
// localVideo.srcObject = arStream
})
sdk.on('ready', () => {
// Get the output stream in the `ready` callback. The initialization parameters have taken effect at this point.
// You can get the output stream in `ready` if you want your video to show effects the moment it is displayed but do not expect it to be displayed as soon as possible.
// Between the two methods, choose the one that fits your needs.
const arStream = await ar.getOutput();
// Play the stream locally
// localVideo.srcObject = arStream
// Call `setBeautify`, `setEffect`, or `setFilter` in the `ready` callback
sdk.setBeautify({
whiten: 0.3
});
sdk.setEffect({
id: effectList[0].EffectId,
intensity: 0.7
});
sdk.setEffect({
id: effectList[0].EffectId,
intensity: 0.7,
filterIntensity: 0.5 // In v0.1.18 and later, you can use this parameter to set the filter strength of a special effect. If you do not pass this parameter, the strength specified for the effect will be used.
});
sdk.setFilter(filterList[0].EffectId, 0.5)
})
Callback | Description | Return Value |
---|---|---|
created | The SDK completed authentication and an instance was created. | - |
cameraReady | The SDK generated a video output (the video is not yet processed). | - |
ready | Detection has been initialized. Effects are now applied to the output video. You can change the effect settings. | - |
error | The SDK encountered an error. | The error object. |
API | Request Parameters | Response Parameters | Description |
---|---|---|---|
async getOutput(fps) | fps (optional): The output frame rate. | MediaStream|String | - |
setBeautify(options) | options: The beautification settings.
type BeautifyOptions = { whiten?: number, // The brightening effect. Value range: 0-1. dermabrasion?: number // The smooth skin effect. Value range: 0-1. lift?: number // The slim face effect. Value range: 0-1. shave?: number // The face width. Value range: 0-1. eye?: number // The big eyes effect. Value range: 0-1. chin?: number // The chin effect. Value range: 0-1. } |
- | To configure beautification effects, you need to enable the effect module (`beautify`). |
setEffect(effects, callback) |
|
- | To configure special effects, you need to enable the effect module (`beautify`). |
setAvatar(params) | { mode: 'AR' | 'VR', effectId?: string, // Pass through `effectId` to use a built-in model url?: string, // Pass through `url` to use a custom model backgroundUrl?: string, // The URL of the background image. This parameter is valid only in the VR mode. } |
- | Use an animoji or virtual avatar. |
setBackground(options) | { type: 'image|blur|transparent', src: string // This parameter is required only if `type` is `image`. } |
- | To configure the background, you need to enable the keying module (`segmentation`). |
setFilter(id, intensity, callback) |
|
- | Set the filter. |
getEffectList(params) | { PageNumber: number, PageSize: number, Name: '', Label: Array, Type: 'Custom|Preset' } |
A list of effects. | Get a list of effects. |
getAvatarList(type) | type = 'AR' | 'VR' |
A list of virtual avatars | Get a list of virtual avatars. |
getEffect(effectId) | effectId: The effect ID. | The information of the effect queried. | Get the information of a specific effect. |
getCommonFilter() | - | A list of the built-in filters. | Get the built-in filters. |
async updateInputStream(src:MediaStream) (supported since v0.1.19) |
src: The new input stream (`MediaStream`). | - | Update the input stream. |
disable() | - | Disable face detection, which can reduce CPU usage. After it’s disabled, the original stream will be returned. | |
enable() | - | Enable face detection. After it’s enabled, the stream returned will have been processed. | |
destroy() | - | - | Terminate the SDK instance and clear its texture resources. |
The error object returned by the error callback includes the error code and error message, which facilitate troubleshooting.
sdk.on('error', (error) => {
// Handle an error in the error callback
const {code, message} = error
...
})
Error Code | Description | Remarks |
---|---|---|
10000001 | Unsupported browser. | Chrome, Firefox, or Safari is recommended. |
10000002 | Missing render context. | - |
10000003 | Rendering taking too long. | Consider reducing the resolution or disabling some features. |
10000005 | Input parsing error. | - |
10001101 | Error configuring special effects. | - |
10001102 | Error configuring filters. | - |
10001103 | Invalid effect strength. | - |
10001201 | Failed to start the camera. | - |
10001202 | The camera stopped. | - |
20002001 | Missing authentication parameters. | - |
20001001 | Authentication failed. | Make sure you have created a license and the signature is correct. |
20001002 | API request failed. | The error callback will return the data returned by the API. For details, see API Error Codes. |
40000001 | Some effects cannot work because the SDK version is too old. Please update your SDK. | - |
On some computers, if the SDK is in the background for a long time, the contextlost
error may occur. In such cases, you can call ArSdk.prototype.resetCore(input: MediaStream)
to resume rendering.
sdk.on('error', async (error) => {
if (error.code === 10000002) {
const newInput = await navigator.mediaDevices.getUserMedia({...})
await sdk.resetCore(newInput)
}
})
Was this page helpful?