This file provides guidance to AI coding agents (e.g. Claude Code) when working with code in this repository. CLAUDE.md includes it via @AGENTS.md.
LiveKit Unity SDK — a C# wrapper around LiveKit's Rust SDK using FFI (Foreign Function Interface) for real-time audio/video communication. Unity package name: io.livekit.livekit-sdk.
Scripts~/run_unity.sh test [-f FILTER] [-m EditMode|PlayMode|both] [-n N]
Scripts~/run_unity.sh build <platform>UNITY_PATHoverrides the Unity binary (auto-detect picks the oldest editor installed via Unity Hub, which may not match the project — e.g.Samples~/Meettargets Unity 6)PROJECT_PATHoverrides the Unity project (default:Samples~/Meet)- Test results go to
Logs~/by default
# Requires the client-sdk-rust~ submodule and Rust toolchain
Scripts~/build_ffi_locally.sh <platform> [build_type]
# Platforms: macos, android, ios
# Build types: debug (default), release- macOS: requires
aarch64-apple-darwintarget - Android: requires
cargo-ndkand Android NDK - iOS: builds static lib (
liblivekit_ffi.a) - After macOS builds, Unity must be restarted to load the new dylib
download_libs.py— downloads the prebuilt FFI binaries for all platforms; the release tag is pinned inversion.inigenerate_proto.sh— regeneratesRuntime/Scripts/Proto/from the protobuf definitions inclient-sdk-rust~/livekit-ffi/protocol(requiresprotoc)build_docs.sh,prepare_release.py,unity_test_results_utils.py— docs generation, release preparation, CI test-result parsing
Tests require a local LiveKit server running:
# Install and run LiveKit server
curl -sSL https://get.livekit.io | bash
livekit-server --dev &Tests run via Unity Test Framework (game-ci/unity-test-runner in CI; CI starts the server via livekit/dev-server-action). Tested against Unity 6000.0.49f1 and 2023.2.20f1. Tests are in Tests/EditMode/ and Tests/PlayMode/.
The SDK wraps a Rust native library (liblivekit_ffi) via P/Invoke. The communication flow:
- C# public API (
Runtime/Scripts/, feature folders) —Room,Participant,Track, audio/video sources, data streams, RPC - FFI layer (
Runtime/Scripts/Internal/) — serializes requests via Protocol Buffers, sends through P/Invoke to Rust - Native library (
Runtime/Plugins/ffi-*/liblivekit_ffi.*) — Rust implementation per platform/arch
Runtime/Scripts/ is organized into feature folders:
Core/—Room,Participant,Track,TrackPublication,Rpc,E2EEAudio/— audio sources (RtcAudioSource,MicrophoneSource, …),AudioStream,AudioResamplerVideo/— video sources (CameraVideoSource,ScreenVideoSource, …),VideoStream, YUV conversionDataStreams/— byte/text data streams and data tracksTokenSource/— token generation/fetching helpers and MonoBehaviour componentUniTask/— optional UniTask integration (own asmdef:livekit.unity.Runtime.UniTask.asmdef)Internal/,Proto/— FFI plumbing and generated protobuf code
Key internal files:
Internal/FFI/FFIClient.cs— singleton managing request/response lifecycle with Rust via protobufInternal/FFI/Requests/FFIBridge.cs— request factoryInternal/FFI/NativeMethods.cs— P/Invoke declarations (DllImport)Internal/Threading/YieldInstruction.cs— custom awaitables for async FFI operations (coroutine-based)
Runtime/Scripts/Proto/ contains auto-generated C# from protobuf definitions in the Rust SDK. Do not edit these files manually; regenerate with Scripts~/generate_proto.sh.
10 platform/arch combinations in Runtime/Plugins/ffi-{platform}-{arch}/. These are large binary files tracked with Git LFS. The .meta files configure Unity platform targeting.
Samples~/Common— shared components used by the other samplesSamples~/Basic— minimal connection example, also used as the CI build targetSamples~/Meet— more complete multi-participant example (LiveKit Meet-like), default project forrun_unity.shSamples~/Agents— connect to an agent and display the transcript
client-sdk-rust~/ is a git submodule pointing to the shared Rust SDK. The ~ suffix tells Unity to ignore the directory.
- Minimum Unity version: 2022.3
- Unsafe code is enabled via
Runtime/csc.rspandTests/csc.rsp - Assembly definitions:
livekit.unity.Runtime.asmdef,livekit.unity.Editor.asmdef,livekit.unity.Runtime.UniTask.asmdef, plus test asmdefs - Dependencies:
Google.Protobuf.dllandSystem.Runtime.CompilerServices.Unsafe.dllshipped as managed plugins