Class AvaturnSDK

Main SDK class

Hierarchy

  • Messaging<SdkMessageResponseType, SdkIncomingMessages>
    • AvaturnSDK

Constructors

  • Constructor does not perform actual initialization. After creating object use AvaturnSDK.init to actually initialize SDK.

    Returns AvaturnSDK

Methods

  • Destructs the SDK, cleans up data, removes the listeners.

    Returns void

  • Initializes SDK, creates DOM elements for Avaturn. Returns a promise that resolves when Avaturn inside iframe is initialized.

    Parameters

    • container: null | Element | HTMLElement

      DOM element that will be parent for all DOM elements created by SDK.

    • config: InitParams

      Config for initialization.

    Returns Promise<AvaturnSDK>

    Example

    sdk.init(containerRef, {
    url: "<INSERT URL FROM /sessions/new request>"
    iframeClassName: 'sdk-iframe',
    disableUi: true,
    })

Animation

  • Gets information about the current animation.

    Returns Promise<{
        id: string;
    }>

  • Gets a list of available animations and their preview urls.

    Returns Promise<AnimationItem[]>

  • Changes the current active animation to the specified one.

    Parameters

    Returns Promise<null>

    Promise which resolves once the animation is changed.

Asset

  • Gets a list of active assets for Avaturn in a form of dictionary {category: assetId }. If some category does not have an active item, empty string instead of asset id is returned. It's best to Avaturn state as source of truth because Avaturn automatically fixes inconsistencies such as when a developer calls .setActiveAsset() with incorrect id or when activating one asset leads to deactivating another one.

    Returns Promise<{
        clothing: string;
        eyewear: string;
        footwear: string;
        hairAndHeadwear: string;
    }>

  • Gets a list of available assets.

    Returns Promise<AssetItem[]>

  • Сhanges the current active asset to the specified one.

    Parameters

    • id: string

    Returns Promise<null>

  • Sets a list of available assets.

    Parameters

    • assets: string[]

    Returns Promise<null>

    Example

    sdk.getAssetList().then((list) => {
    const filteredList = list.slice(0, 3).map((x) => x.id);
    return sdk.setAvailableAssets(filteredList);
    })

Body

  • Gets information about the current body.

    Returns Promise<{
        id: string;
    }>

  • Gets a list of available bodies and their preview urls.

    Returns Promise<BodyItem[]>

  • Changes the current active body to the specified one.

    Parameters

    Returns Promise<null>

    Promise which resolves once the body is changed.

Events

Export

Options

  • Gets information about the current eyewear color.

    Returns Promise<`#${string}` | "transparent">

  • Gets information about the current hair color.

    Returns Promise<`#${string}`>

  • Gets information about the current skin tone correction coefficient.

    Returns Promise<number>

  • Sets body proportions.

    Parameters

    Returns Promise<null>

  • Sets eyewear lens color.

    Parameters

    • value: `#${string}` | "transparent"

      hex string with leading # (e.g. '#ffffff', '#b32973'), or "transparent"

    Returns Promise<null>

  • Sets hair color.

    Parameters

    • value: `#${string}`

      hex string with leading # (e.g. '#ffffff', '#b32973')

    Returns Promise<null>

  • Sets skin tone correction coefficient.

    Parameters

    • value: number

      Number from -50 to 50. 0 = no correction.

    Returns Promise<null>