Skip to main content
AvatarKit UI is a shadcn-style React component package for embedding a SpatialReal avatar player into your app. It wraps AvatarKit RTC setup, LiveKit session wiring, loading and error states, and a small set of presentational primitives so you can ship an avatar surface with minimal glue code.

Usage

Use SpatialRealAvatarProvider to initialize AvatarKit and LiveKit, then compose the avatar surface with SpatialRealAvatarFrame, SpatialRealAvatarCanvas, SpatialRealAvatarLoading, SpatialRealAvatarError, and SpatialRealAvatarStatus.
This is the same composition pattern used in the working Vite demo: an avatar frame for rendering, built-in overlays for loading and failure states, and context-driven controls for microphone and session UI.

Adding microphone controls with context

Use useSpatialRealAvatarContext() inside the provider tree when you want to drive UI from connection state or publish the local microphone into the avatar session.
SpatialRealAvatarCanvas must render inside a container with non-zero width and height. The provider waits for the canvas container to be measurable before it starts loading the avatar.

Features

  • Render a SpatialReal avatar surface with a small set of composable shadcn-style primitives.
  • Connect AvatarKit and LiveKit through SpatialRealAvatarProvider without writing your own player wiring.
  • Show built-in loading, error, and connection status UI out of the box.
  • Access the active LiveKit room and avatar session state through useSpatialRealAvatarContext().
  • Start, stop, reconnect, disconnect, and publish microphone audio with hook-based controls.

Installation

AvatarKit UI is built on:
  • shadcn/ui conventions (local component files + Tailwind styles)
  • LiveKit Agent UI ecosystem (@livekit/components-react, @livekit/components-styles)
Before adding this AvatarKit UI component to your project, you can use this guide to setup shadcn

API Reference

Exports

SpatialRealAvatarProvider

Initializes AvatarKit, connects the LiveKit-backed avatar stream, provides avatar state through React context, and renders remote room audio.

SpatialRealAvatarFrame

Visual wrapper for the avatar canvas and overlays.

SpatialRealAvatarCanvas

Mount target for AvatarView. The rendered avatar appears inside this div.

SpatialRealAvatarLoading

Loading overlay shown while the avatar is initializing or connecting.

SpatialRealAvatarError

Error overlay shown when avatar setup or streaming fails.

SpatialRealAvatarStatus

Small status badge for the current avatar connection state. Supported status labels:
  • idle
  • initializing
  • connecting
  • connected
  • disconnecting
  • error

useSpatialRealAvatar(options)

Low-level hook that powers the provider. Use it when you want to wire AvatarKit into your own context or compose a custom provider.

Options

useSpatialRealAvatar() accepts the same connection and SDK props as SpatialRealAvatarProvider, except for children, muted, volume, and onDisconnect.

Return value

useSpatialRealAvatarContext()

Returns the current avatar state from SpatialRealAvatarProvider.
Use this hook inside provider children to:
  • show or hide UI based on avatar.status
  • read the connected avatar.room for LiveKit chat and transcript components
  • call avatar.startPublishingMicrophone() and avatar.stopPublishingMicrophone()
  • invoke avatar.disconnect() or avatar.reconnect() from your own controls
useSpatialRealAvatarContext() throws an error if it is used outside SpatialRealAvatarProvider.