### VideoStream Usage Example Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/video-audio-streams.md Example demonstrating how to initialize a VideoStream, subscribe to frame and texture events, and start the update coroutine. It shows how to set the received texture to a material. ```csharp void OnRemoteVideoTrackSubscribed(RemoteVideoTrack track) { var videoStream = new VideoStream(track); videoStream.FrameReceived += OnVideoFrameReceived; videoStream.TextureReceived += OnTextureReceived; StartCoroutine(videoStream.UpdateRoutine()); } void OnTextureReceived(Texture tex) { GetComponent().material.mainTexture = tex; } ``` -------------------------------- ### Install and Run LiveKit Server Source: https://github.com/livekit/client-sdk-unity/blob/main/CLAUDE.md Installs the LiveKit server and runs it in development mode. This is required for running tests locally. ```bash # Install and run LiveKit server curl -sSL https://get.livekit.io | bash livekit-server --dev & ``` -------------------------------- ### KeyProvider Example: Setting Shared Key Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/e2ee.md Example demonstrating how to set a shared encryption key using the KeyProvider. It shows retrieving or generating a key and then setting it with an index. ```csharp byte[] encryptionKey = GetOrGenerateKey(); keyProvider.SetSharedKey(encryptionKey, 0); ``` -------------------------------- ### AudioStream Usage Example Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/video-audio-streams.md Example of how to create and use an AudioStream when a remote audio track is subscribed. The stream automatically renders audio until disposed. ```csharp void OnRemoteAudioTrackSubscribed(RemoteAudioTrack track) { var audioSource = gameObject.AddComponent(); var audioStream = new AudioStream(track, audioSource); // Stream automatically renders audio until disposed } ``` -------------------------------- ### Clone LiveKit Unity SDK Repository Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md Clone the LiveKit Unity SDK repository to start the installation process. ```sh git clone https://github.com/livekit/client-sdk-unity.git cd client-sdk-unity ``` -------------------------------- ### RoomOptions Example Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/types.md Configure connection settings for a room, including auto-subscription, dynamic casting, and join retries. Custom ICE and E2EE configurations can also be provided. ```csharp var options = new RoomOptions { AutoSubscribe = true, Dynacast = true, AdaptiveStream = true, JoinRetries = 3, RtcConfig = new RTCConfiguration { /* ... */ }, E2EE = null // No encryption }; ``` -------------------------------- ### Example: Creating a frame with a timestamp and pushing it Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/data-track.md Shows how to create a DataTrackFrame, associate it with the current system time using WithUserTimestampNow(), and then push it to subscribers. ```csharp var frame = new DataTrackFrame(data).WithUserTimestampNow(); track.TryPush(frame); ``` -------------------------------- ### Create VideoStream for RemoteVideoTrack Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/track.md An example of creating a VideoStream to render a remote video track. This involves creating the stream and starting its update routine. ```csharp var videoStream = new VideoStream(remoteVideoTrack); yield return StartCoroutine(videoStream.UpdateRoutine()); ``` -------------------------------- ### Enable E2EE on Connection and Manage Keys Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/e2ee.md Example demonstrating how to enable E2EE with GCM encryption and shared key options when connecting to a room, and how to access and manage the E2EE manager and key provider post-connection. ```csharp // Enable E2EE when connecting var e2eeOptions = new E2EEOptions { EncryptionType = EncryptionType.GCM, KeyProviderOptions = new KeyProviderOptions { SharedKey = GenerateOrLoadKey(), RatchetWindowSize = 16, FailureTolerance = 10 } }; var roomOptions = new RoomOptions { E2EE = e2eeOptions }; yield return room.Connect(url, token, roomOptions); // Access the E2EE manager after successful connection var e2eeManager = room.E2EEManager; if (e2eeManager != null) { e2eeManager.setEnabled(true); // Manage keys var keyProvider = e2eeManager.KeyProvider; keyProvider.SetSharedKey(myKey, 0); } ``` -------------------------------- ### Example: Sending telemetry data Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/data-track.md Demonstrates how to create a DataTrackFrame with byte data and push it to subscribers using the TryPush method. Includes error handling for potential push failures. ```csharp try { var frame = new DataTrackFrame(Encoding.UTF8.GetBytes("telemetry data")); track.TryPush(frame); } catch (PushFrameError ex) { Debug.LogError($"Failed to push frame: {ex.Message}"); } ``` -------------------------------- ### Receiving and Displaying Remote Tracks Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md This example demonstrates how to connect to a LiveKit room and handle incoming audio and video tracks. It subscribes to track events, displaying remote video on a RawImage component and playing remote audio using an AudioSource. ```csharp IEnumerator Start() { var room = new Room(); room.TrackSubscribed += TrackSubscribed; var connect = room.Connect("ws://localhost:7880", ""); yield return connect; // .... } void TrackSubscribed(IRemoteTrack track, RemoteTrackPublication publication, RemoteParticipant participant) { if (track is RemoteVideoTrack videoTrack) { var rawImage = GetComponent(); var stream = new VideoStream(videoTrack); stream.TextureReceived += (tex) => { rawImage.texture = tex; }; StartCoroutine(stream.Update()); // The video data is displayed on the rawImage } else if (track is RemoteAudioTrack audioTrack) { GameObject audObject = new GameObject(audioTrack.Sid); var source = audObject.AddComponent(); var stream = new AudioStream(audioTrack, source); // Audio is being played on the source .. } } ``` -------------------------------- ### Create AudioStream for RemoteAudioTrack Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/track.md An example of creating an AudioStream to render a remote audio track. Requires the remote audio track and an audio source. ```csharp var audioStream = new AudioStream(remoteAudioTrack, audioSource); ``` -------------------------------- ### Custom RPC Error Example Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/errors.md Demonstrates how to throw a custom RPC error with a specific code, message, and additional data. ```csharp throw new RpcError(2001, "Custom error", "Additional error data"); ``` -------------------------------- ### Example RPC Handler Implementation Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/rpc.md An example of an asynchronous RPC handler that processes a payload and returns it, or throws an RpcError if the payload is invalid. This handler is registered using RegisterRpcMethod. ```csharp async Task EchoHandler(RpcInvocationData data) { // Simulate some processing await Task.Delay(100); if (string.IsNullOrEmpty(data.Payload)) throw new RpcError(400, "Payload is required"); return data.Payload; } localParticipant.RegisterRpcMethod("echo", EchoHandler); ``` -------------------------------- ### Connect to LiveKit Room Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md Connects to a LiveKit room using a WebSocket URL and a join token. Ensure the 'LiveKit' namespace is imported. This example demonstrates basic room connection and error checking. ```csharp using LiveKit; IEnumerator Start() { var room = new Room(); room.TrackSubscribed += TrackSubscribed; var connect = room.Connect("ws://localhost:7880", ""); yield return connect; if (!connect.IsError) { Debug.Log("Connected to " + room.Name); } } ``` -------------------------------- ### Example: Logging frame latency Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/data-track.md Demonstrates how to calculate and log the latency of a DataTrackFrame using DurationSinceTimestamp(). It checks if a timestamp exists before attempting to calculate the duration. ```csharp var elapsed = frame.DurationSinceTimestamp(); if (elapsed.HasValue) { Debug.Log($"Frame latency: {elapsed.Value} seconds"); } ``` -------------------------------- ### Open Text Stream Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/participant.md Opens a text stream for incremental transmission. Use the returned instruction to get a TextStreamWriter for sending data. ```csharp var instruction = localParticipant.StreamText("logs"); yield return instruction; if (!instruction.IsError) { var writer = instruction.Writer; // Use writer to send text incrementally } ``` -------------------------------- ### VideoStream UpdateRoutine Method Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/video-audio-streams.md A coroutine for processing video frames and uploading them to the GPU. This should be started to enable video rendering. ```APIDOC ## UpdateRoutine Method ### Description Provides a coroutine for continuous frame processing and GPU upload. ### Method ```csharp public IEnumerator UpdateRoutine() ``` ### Returns A coroutine enumerator. ### Remarks Call as `StartCoroutine(videoStream.UpdateRoutine())` to process frames. The coroutine yields to allow other Unity tasks to run between frames. ``` -------------------------------- ### Publish Data Track Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/participant.md Publishes a data track for sending structured data. Use the returned instruction to get the published LocalDataTrack. ```csharp var instruction = localParticipant.PublishDataTrack("telemetry"); yield return instruction; if (!instruction.IsError) { var track = instruction.Track; var frame = new DataTrackFrame(data); track.TryPush(frame); } ``` -------------------------------- ### Publish Microphone Track Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md Publishes audio from the microphone to a LiveKit room. Configures audio encoding and sets the track source to microphone. The microphone must be started after the track is published. ```csharp var localSid = "my-audio-source"; GameObject audObject = new GameObject(localSid); _audioObjects[localSid] = audObject; var rtcSource = new MicrophoneSource(Microphone.devices[0], _audioObjects[localSid]); var track = LocalAudioTrack.CreateAudioTrack("my-audio-track", rtcSource, room); var options = new TrackPublishOptions(); options.AudioEncoding = new AudioEncoding(); options.AudioEncoding.MaxBitrate = 64000; options.Source = TrackSource.SourceMicrophone; var publish = room.LocalParticipant.PublishTrack(track, options); yield return publish; if (!publish.IsError) { Debug.Log("Track published!"); } rtcSource.Start(); ``` -------------------------------- ### Registering an RPC Handler on Receiver Side Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/rpc.md Shows how to register an RPC method handler on the receiver side using RegisterRpcMethod. This example handles a 'get-status' request and returns system health information. ```csharp // Receiver side localParticipant.RegisterRpcMethod("get-status", async (data) => { var request = JsonUtility.FromJson(data.Payload); var status = new StatusResponse { health = GetSystemHealth(), timestamp = DateTime.UtcNow }; return JsonUtility.ToJson(status); }); ``` -------------------------------- ### VideoStream UpdateRoutine Method Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/video-audio-streams.md A coroutine that should be started to process incoming video frames and upload textures to the GPU. It yields between frames to allow other Unity tasks to run. ```csharp public IEnumerator UpdateRoutine() ``` -------------------------------- ### Initialize WebCameraSource Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md Create a WebCameraSource to capture video from a device's web camera. You can specify the camera device name, resolution, and frame rate. ```csharp // List available cameras var cameras = WebCamTexture.devices; if (cameras.Length > 0) { var source = new WebCameraSource(cameras[0].name, 1280, 720, 30); } ``` -------------------------------- ### Get Encryption Key Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/e2ee.md Retrieves the encryption key for a specific participant and key index. ```csharp public byte[] GetKey(string participantIdentity, int keyIndex) ``` -------------------------------- ### Connect Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/room.md Initiates a connection to a LiveKit room with the specified URL, token, and options. Returns a ConnectInstruction to track connection status. ```APIDOC ## Connect ### Description Initiates a connection to a LiveKit room. ### Method `Connect` ### Parameters #### Path Parameters - **url** (string) - Required - LiveKit server URL (e.g., `wss://livekit.example.com`) - **token** (string) - Required - Access token generated by the server - **options** (RoomOptions) - Required - Connection options and configuration ### Returns `ConnectInstruction` — A yield instruction that completes when connection succeeds or fails. Check `IsError` property to determine success. ### Example ```csharp var room = new Room(); var options = new RoomOptions { AutoSubscribe = true }; var connectInstruction = room.Connect("wss://livekit.example.com", token, options); yield return connectInstruction; if (!connectInstruction.IsError) { Debug.Log($"Connected to room: {room.Name}"); } ``` ``` -------------------------------- ### Connect to a LiveKit Room Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/room.md Initiates a connection to a LiveKit room. Use the returned instruction to await connection completion and check for errors. ```csharp var room = new Room(); var options = new RoomOptions { AutoSubscribe = true }; var connectInstruction = room.Connect("wss://livekit.example.com", token, options); yield return connectInstruction; if (!connectInstruction.IsError) { Debug.Log($"Connected to room: {room.Name}"); } ``` -------------------------------- ### Publish Local Track with Options Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/participant.md Publishes a local audio or video track to the room with specified publishing options. Use this to control encoding and other track properties. ```csharp var videoSource = new CameraVideoSource(camera); var videoTrack = LocalVideoTrack.CreateVideoTrack("camera", videoSource, room); var options = new TrackPublishOptions { Encoding = new VideoEncoding { MaxBitrate = 2500000 } }; var publishInstruction = localParticipant.PublishTrack(videoTrack, options); yield return publishInstruction; ``` -------------------------------- ### MicrophoneSource Constructor and Usage Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md Captures audio from the device microphone. Initialize with the desired number of channels and use it to create an audio track. ```csharp public MicrophoneSource(int channels = 2) ``` ```csharp var microphoneSource = new MicrophoneSource(2); var audioTrack = LocalAudioTrack.CreateAudioTrack("microphone", microphoneSource, room); ``` -------------------------------- ### KeyProvider Constructor Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/e2ee.md Initializes the KeyProvider with a room FFI handle and key provider options. ```csharp public KeyProvider(FfiHandle roomHandle, KeyProviderOptions keyProviderOptions) ``` -------------------------------- ### Publish Audio and Video Tracks Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/README.md Publishes local audio and video tracks to a LiveKit room. Requires setting up audio and video sources and configuring publish options for encoding. Ensure camera and microphone permissions are granted. ```csharp var micSource = new MicrophoneSource(); var audioTrack = LocalAudioTrack.CreateAudioTrack("mic", micSource, room); var cameraSource = new CameraVideoSource(Camera.main); var videoTrack = LocalVideoTrack.CreateVideoTrack("camera", cameraSource, room); var publishOptions = new TrackPublishOptions { Encoding = new VideoEncoding { MaxBitrate = 2500000 } }; yield return room.LocalParticipant.PublishTrack(audioTrack, publishOptions); yield return room.LocalParticipant.PublishTrack(videoTrack, publishOptions); ``` -------------------------------- ### PublishDataTrackError Handling Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/errors.md Provides an example of handling PublishDataTrackError when publishing a data track. It checks the IsError flag on the instruction and logs the error message if publishing fails. ```csharp var instruction = localParticipant.PublishDataTrack("telemetry"); yield return instruction; if (instruction.IsError) { Debug.LogError($"Failed to publish data track: {instruction.Error.Message}"); } else { var track = instruction.Track; } ``` -------------------------------- ### ScreenVideoSource Constructor Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md Captures video from the screen or a display. Configure capture width, height, and target frame rate during initialization. ```csharp public ScreenVideoSource(int width = 1920, int height = 1080, int frameRate = 30) ``` -------------------------------- ### RtcVideoSource Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md Base class for local video sources, extending IRtcSource and IDisposable. It provides methods to get video dimensions and properties related to video capture. ```APIDOC ## RtcVideoSource Base class for local video sources. ```csharp public abstract class RtcVideoSource : IRtcSource, IDisposable ``` ### Properties | Property | Type | Description | |----------|------|-------------| | `Handle` | `FfiHandle` | Internal FFI handle. | | `Muted` | `bool` | Muted status. | | `MetadataProvider` | `FrameMetadataDelegate` | Optional delegate for custom frame metadata. | ### Methods #### GetWidth ```csharp public abstract int GetWidth() ``` **Returns:** Width in pixels. #### GetHeight ```csharp public abstract int GetHeight() ``` **Returns:** Height in pixels. ### Events | Event | Signature | Description | |-------|-----------|-------------| | `TextureReceived` | `TextureReceiveDelegate(Texture2D)` | Fired when a new texture is available or resolution changes. | ### Enums ```csharp public enum VideoStreamSource { Texture = 0, // Texture source Screen = 1, // Screen/display capture Camera = 2 // Camera capture } ``` ``` -------------------------------- ### CreateAudioTrack Factory Method Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/track.md Factory method to create and initialize a local audio track. Requires a name, an RtcAudioSource, and the Room instance. ```csharp public static LocalAudioTrack CreateAudioTrack(string name, RtcAudioSource source, Room room) ``` ```csharp var micSource = new MicrophoneSource(); var audioTrack = LocalAudioTrack.CreateAudioTrack("microphone", micSource, room); ``` -------------------------------- ### Configure Room Connection Options Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Set up RoomOptions to control auto-subscription, dynamic casting, adaptive streaming, join retries, and WebRTC/E2EE configurations. ```csharp var options = new RoomOptions { AutoSubscribe = true, Dynacast = true, AdaptiveStream = true, JoinRetries = 3, RtcConfig = new RTCConfiguration { /* ... */ }, E2EE = new E2EEOptions { /* ... */ } }; yield return room.Connect(url, token, options); ``` -------------------------------- ### Connect to a LiveKit Room Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/README.md Establishes a connection to a LiveKit room with specified options. Ensure the URL and token are valid. AutoSubscribe is enabled by default. ```csharp var room = new Room(); var options = new RoomOptions { AutoSubscribe = true }; var connectInstruction = room.Connect(url, token, options); yield return connectInstruction; ``` -------------------------------- ### CreateVideoTrack Factory Method Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/track.md Factory method to create and initialize a local video track. Requires a name, an RtcVideoSource, and the Room instance. ```csharp public static LocalVideoTrack CreateVideoTrack(string name, RtcVideoSource source, Room room) ``` ```csharp var cameraSource = new CameraVideoSource(Camera.main); var videoTrack = LocalVideoTrack.CreateVideoTrack("camera", cameraSource, room); ``` -------------------------------- ### BasicAudioSource Constructor Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md A basic custom audio source suitable for testing or simple use cases. Initialize with the desired number of channels. ```csharp public BasicAudioSource(int channels = 2) ``` -------------------------------- ### Perform RPC on Another Participant Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/participant.md Performs a remote procedure call on another participant. Use this to send custom messages and receive responses. The example shows how to set up RPC parameters and handle the response. ```csharp var rpcParams = new PerformRpcParams { DestinationIdentity = remotePerson.Identity, Method = "play-sound", Payload = "{\"sound\": \"ping\"}", ResponseTimeout = 15f }; var instruction = localParticipant.PerformRpc(rpcParams); yield return instruction; if (!instruction.IsError) { Debug.Log($"Response: {instruction.Payload}"); } ``` -------------------------------- ### WebCameraSource Constructor Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md Initializes a new instance of the WebCameraSource class, capturing video from a device's web camera. ```APIDOC ## WebCameraSource Constructor ### Description Initializes a new instance of the WebCameraSource class, capturing video from a device's web camera. ### Method Constructor ### Parameters #### Path Parameters - **deviceName** (string) - Yes - Name of the camera device - **width** (int) - No - Capture width in pixels (Default: 1280) - **height** (int) - No - Capture height in pixels (Default: 720) - **frameRate** (int) - No - Target frame rate in FPS (Default: 30) ### Request Example ```csharp // List available cameras var cameras = WebCamTexture.devices; if (cameras.Length > 0) { var source = new WebCameraSource(cameras[0].name, 1280, 720, 30); } ``` ``` -------------------------------- ### Build FFI Locally from Rust Source Source: https://github.com/livekit/client-sdk-unity/blob/main/CLAUDE.md Builds the Rust FFI library for a specified platform and build type. Requires the client-sdk-rust submodule and Rust toolchain. Platforms include macOS, Android, and iOS. Unity may need to be restarted after macOS builds. ```bash # Requires the client-sdk-rust~ submodule and Rust toolchain Scripts/build_ffi_locally.sh [build_type] # Platforms: macos, android, ios # Build types: debug (default), release ``` -------------------------------- ### Create TextureVideoSource Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md Initialize a TextureVideoSource with a Texture2D to use as a video input. This is useful for custom video sources. ```csharp var texture = new Texture2D(1280, 720, TextureFormat.RGBA32, false); var textureSource = new TextureVideoSource(texture); var videoTrack = LocalVideoTrack.CreateVideoTrack("texture", textureSource, room); ``` -------------------------------- ### CameraVideoSource Constructor and Usage Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md Captures video from a specified Unity camera. Initialize with a Camera object and use it to create a video track. ```csharp public CameraVideoSource(Camera camera) ``` ```csharp var cameraSource = new CameraVideoSource(Camera.main); var videoTrack = LocalVideoTrack.CreateVideoTrack("camera", cameraSource, room); ``` -------------------------------- ### RoomOptions Class Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/types.md Configuration for connecting to a room. ```APIDOC ## RoomOptions ### Description Configuration for connecting to a room. ### Properties - **AutoSubscribe** (bool) - Default: `true` - Automatically subscribe to published tracks from other participants. - **Dynacast** (bool) - Default: `true` - Enable dynamic broadcast (adaptive quality). - **AdaptiveStream** (bool) - Default: `true` - Enable adaptive bitrate streaming. - **JoinRetries** (uint) - Default: `3` - Number of reconnection attempts. - **RtcConfig** (RTCConfiguration) - Default: `null` - ICE and TURN server configuration. - **E2EE** (E2EEOptions) - Default: `null` - End-to-end encryption configuration. ### Example ```csharp var options = new RoomOptions { AutoSubscribe = true, Dynacast = true, AdaptiveStream = true, JoinRetries = 3, RtcConfig = new RTCConfiguration { /* ... */ }, E2EE = null // No encryption }; ``` ``` -------------------------------- ### Fetch Connection Details with Overrides Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md Fetches connection details with dynamic overrides for room name and participant name. This allows for per-connection customization while falling back to the configured defaults. ```csharp var task = _tokenSourceComponent.FetchConnectionDetails(new TokenSourceFetchOptions { RoomName = "lobby-" + System.Guid.NewGuid(), ParticipantName = playerName, }); ``` -------------------------------- ### Making a Simple RPC Request Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/rpc.md Demonstrates how to make an RPC request from the caller side using PerformRpc. It includes yielding the instruction and checking for errors. ```csharp // Caller side var rpcParams = new PerformRpcParams { DestinationIdentity = remotePerson.Identity, Method = "get-status", Payload = "{\"query\": \"health\"}" }; var instruction = localParticipant.PerformRpc(rpcParams); yield return instruction; if (!instruction.IsError) { var response = JsonUtility.FromJson(instruction.Payload); Debug.Log($ ``` ```csharp Status: {response.health} ``` -------------------------------- ### RtcVideoSource GetWidth and GetHeight Methods Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md Abstract methods to retrieve the width and height of the video source in pixels. These must be implemented by derived classes. ```csharp public abstract int GetWidth() ``` ```csharp public abstract int GetHeight() ``` -------------------------------- ### Send File All at Once Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md Sends a complete file to a room. Use this for sending discrete files like images or documents. ```csharp IEnumerator PerformSendFile() { var filePath = "path/to/file.jpg"; var sendFileCall = room.LocalParticipant.SendFile(filePath, "some-topic"); yield return sendFileCall; Debug.Log($"Sent file with stream ID: {sendFileCall.Info.Id}"); } ``` -------------------------------- ### Publishing a Unity Camera Video Track Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md This snippet shows how to publish a video track from a Unity Camera. It configures a RenderTexture, sets it as the camera's target, and then creates a TextureVideoSource to publish. It also configures track publishing options like codec, bitrate, framerate, simulcast, and source. ```csharp var rt = new UnityEngine.RenderTexture(1920, 1080, 24, RenderTextureFormat.ARGB32); rt.Create(); Camera.main.targetTexture = rt; var source = new TextureVideoSource(rt); var track = LocalVideoTrack.CreateVideoTrack("my-video-track", source, room); var options = new TrackPublishOptions(); options.VideoCodec = VideoCodec.Vp8; var videoCoding = new VideoEncoding(); videoCoding.MaxBitrate = 512000; videoCoding.MaxFramerate = frameRate; options.VideoEncoding = videoCoding; options.Simulcast = true; options.Source = TrackSource.SourceCamera; var publish = room.LocalParticipant.PublishTrack(track, options); yield return publish; if (!publish.IsError) { Debug.Log("Track published!"); } source.Start(); StartCoroutine(source.Update()); ``` -------------------------------- ### TextureVideoSource Constructor Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md Initializes a new instance of the TextureVideoSource class using a provided Texture2D object. ```APIDOC ## TextureVideoSource Constructor ### Description Initializes a new instance of the TextureVideoSource class using a provided Texture2D object. ### Method Constructor ### Parameters #### Path Parameters - **texture** (Texture2D) - Yes - Texture to use as video source ### Request Example ```csharp var texture = new Texture2D(1280, 720, TextureFormat.RGBA32, false); var textureSource = new TextureVideoSource(texture); var videoTrack = LocalVideoTrack.CreateVideoTrack("texture", textureSource, room); ``` ``` -------------------------------- ### AudioStream Constructor Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/video-audio-streams.md Initializes an AudioStream to render a remote audio track to a Unity AudioSource. It automatically manages the subscription lifecycle. ```csharp public sealed class AudioStream : IDisposable ``` ```csharp public AudioStream(RemoteAudioTrack audioTrack, AudioSource source) ``` -------------------------------- ### Fetch Connection Details Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md Fetches connection details from a token source component. Use this before connecting to a LiveKit room. Ensure the TokenSourceComponent is set up with a valid TokenSourceComponentConfig asset. ```csharp var connectionDetailsTask = _tokenSourceComponent.FetchConnectionDetails(); yield return new WaitUntil(() => connectionDetailsTask.IsCompleted); if (connectionDetailsTask.IsFaulted) { Debug.LogError($"Failed to fetch connection details: {connectionDetailsTask.Exception?.InnerException?.Message}"); yield break; } var details = connectionDetailsTask.Result; _room = new Room(); var connect = _room.Connect(details.ServerUrl, details.ParticipantToken, new RoomOptions()); ``` -------------------------------- ### Configure Track Publish Options Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Define VideoEncoding settings for publishing tracks, including max bitrate, framerate, and simulcast. ```csharp var publishOptions = new TrackPublishOptions { Encoding = new VideoEncoding { MaxBitrate = 2500000, // 2.5 Mbps MaxFramerate = 30, Simulcast = true } }; var publishInstruction = localParticipant.PublishTrack(videoTrack, publishOptions); ``` -------------------------------- ### LiveKit Event Model in Unity Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/README.md Utilize the Room class's event model to react to various events such as participant connections, track publications/subscriptions, data reception, and connection state changes. ```csharp room.ParticipantConnected += (participant) => { /* ... */ }; room.TrackPublished += (publication, participant) => { /* ... */ }; room.TrackSubscribed += (track, publication, participant) => { /* ... */ }; room.DataReceived += (data, participant, kind, topic) => { /* ... */ }; room.ConnectionStateChanged += (state) => { /* ... */ }; ``` -------------------------------- ### AudioStream Constructor Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/video-audio-streams.md Renders a remote audio track to a Unity AudioSource. It automatically subscribes to the track, manages audio rendering, and handles buffering and system audio changes. ```APIDOC ## AudioStream Constructor ### Description Initializes a new instance of the `AudioStream` class, which renders a remote audio track to a Unity `AudioSource`. ### Method ```csharp public AudioStream(RemoteAudioTrack audioTrack, AudioSource source) ``` ### Parameters #### Path Parameters - **audioTrack** (`RemoteAudioTrack`) - Required - The remote audio track to stream. - **source** (`AudioSource`) - Required - Unity AudioSource component to play audio through. ### Returns An `AudioStream` instance that automatically manages the subscription lifecycle. ### Throws - `InvalidOperationException` if the track's room or participant is invalid. ### Remarks - Automatically subscribes to the track and starts audio rendering. - Handles audio resampling, drift correction, and underrun buffering. - Manages system audio configuration changes (e.g., unplugging headphones). - Pre-buffers 200ms and waits for 30ms of data before playing. - Skips samples on buffer overflow to avoid audio delays from clock drift. ### Example ```csharp void OnRemoteAudioTrackSubscribed(RemoteAudioTrack track) { var audioSource = gameObject.AddComponent(); var audioStream = new AudioStream(track, audioSource); // Stream automatically renders audio until disposed } ``` ``` -------------------------------- ### Instantiate Token Source Directly Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md Instantiates various token source types directly, bypassing the ScriptableObject configuration. Useful for custom authentication flows or when not using the Unity inspector. ```csharp ITokenSourceFixed source = new TokenSourceLiteral("wss://your.livekit.host", ""); // or: new TokenSourceSandbox(""); // or: new TokenSourceEndpoint("https://your.token-server/api/token", headers); // or: new TokenSourceCustom(async () => await MyAuthFlow()); ``` -------------------------------- ### Configure WebRTC Settings Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Customize WebRTC behavior, including ICE transport type, continual gathering policy, and specifying ICE servers for TURN relays. ```csharp var rtcConfig = new RTCConfiguration { IceTransportType = IceTransportType.TRANSPORT_ALL, ContinualGatheringPolicy = ContinualGatheringPolicy.GATHER_ONCE, IceServers = new[] { new IceServer { Urls = new[] { "turn:example.com:3478" }, Username = "user", Password = "pass" } } }; var options = new RoomOptions { RtcConfig = rtcConfig }; ``` -------------------------------- ### Build FFI Libraries Locally Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md Use this script to build LiveKit FFI libraries locally for development. Specify the target platform (e.g., macos, android, ios) and build mode (debug or release). ```sh ./Scripts~/build_ffi_locally.sh macos release ``` -------------------------------- ### Configure End-to-End Encryption Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Set up E2EEOptions for room encryption, specifying the encryption type and key provider configurations. ```csharp var e2eeOptions = new E2EEOptions { EncryptionType = EncryptionType.GCM, KeyProviderOptions = new KeyProviderOptions { SharedKey = myEncryptionKey, RatchetWindowSize = 16, RatchetSalt = mySalt, FailureTolerance = 10 } }; var options = new RoomOptions { E2EE = e2eeOptions }; ``` -------------------------------- ### E2EEOptions ToProto Method Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/e2ee.md Internal method to convert E2EEOptions to its protobuf representation. ```csharp public Proto.E2eeOptions ToProto() ``` -------------------------------- ### Configure End-to-End Encryption (E2EE) Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Set up E2EE with GCM encryption and a shared key provider. Configures ratchet window size and failure tolerance for secure communication. ```csharp var e2eeOptions = new E2EEOptions { EncryptionType = EncryptionType.GCM, KeyProviderOptions = new KeyProviderOptions { SharedKey = GenerateOrLoadKey(32), // 32 bytes for AES-256 RatchetWindowSize = 16, FailureTolerance = 10 } }; var options = new RoomOptions { E2EE = e2eeOptions }; ``` -------------------------------- ### IceServer Class Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/types.md Configuration for a TURN relay server. ```APIDOC ## IceServer ### Description Configuration for a TURN relay server. ### Properties - **Urls** (string[]) - TURN server URLs (e.g., `["turn:example.com:3478"]`). - **Username** (string) - Authentication username. - **Password** (string) - Authentication password. ``` -------------------------------- ### Subscribe to Remote Audio and Video Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/README.md Subscribe to remote audio and video tracks to render them in your Unity application. Audio tracks require an AudioSource component, while video tracks can be rendered to a material's texture. ```csharp void OnRemoteAudioTrackSubscribed(RemoteAudioTrack track) { var audioSource = gameObject.AddComponent(); var audioStream = new AudioStream(track, audioSource); } void OnRemoteVideoTrackSubscribed(RemoteVideoTrack track) { var videoStream = new VideoStream(track); GetComponent().material.mainTexture = videoStream.Texture; StartCoroutine(videoStream.UpdateRoutine()); } ``` -------------------------------- ### RTCConfiguration Class Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/types.md WebRTC configuration for ICE transport. ```APIDOC ## RTCConfiguration ### Description WebRTC configuration for ICE transport. ### Properties - **IceTransportType** (IceTransportType) - Default: `TRANSPORT_ALL` - ICE transport strategy. - **ContinualGatheringPolicy** (ContinualGatheringPolicy) - Default: `GATHER_ONCE` - ICE candidate gathering policy. - **IceServers** (IceServer[]) - Default: `null` - Custom TURN servers. ``` -------------------------------- ### VideoStream Constructor Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/video-audio-streams.md Initializes a VideoStream to render a remote video track. It automatically creates and manages render textures. ```csharp public VideoStream(IVideoTrack videoTrack) ``` -------------------------------- ### Configure Room for Low-Latency Streaming Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Sets room options for low-latency streaming by disabling adaptive streaming and dynacast, and enabling auto-subscribe. ```csharp var options = new RoomOptions { AutoSubscribe = true, Dynacast = false, // Disable bandwidth adaptation AdaptiveStream = false, JoinRetries = 1 }; ``` -------------------------------- ### PublishTrack Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/participant.md Publishes a local audio or video track to the room with specified options. This method returns a yield instruction that completes once the track has been successfully published. ```APIDOC ## PublishTrack ### Description Publishes a local audio or video track. This method returns a yield instruction that completes once the track has been successfully published. ### Method POST ### Endpoint /participant/publishTrack ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **localTrack** (ILocalTrack) - Required - The local audio or video track to publish. - **options** (TrackPublishOptions) - Required - Publishing options, such as codec and bitrate. ### Request Example ```csharp var videoSource = new CameraVideoSource(camera); var videoTrack = LocalVideoTrack.CreateVideoTrack("camera", videoSource, room); var options = new TrackPublishOptions { Encoding = new VideoEncoding { MaxBitrate = 2500000 } }; var publishInstruction = localParticipant.PublishTrack(videoTrack, options); yield return publishInstruction; ``` ### Response #### Success Response (200) - **PublishTrackInstruction** (PublishTrackInstruction) - Yield instruction that completes when the track is published. #### Response Example ```json { "instruction": "PublishTrackInstruction" } ``` ``` -------------------------------- ### TrackPublishOptions Class Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/types.md Configuration for publishing a local track. ```APIDOC ## TrackPublishOptions ### Description Configuration for publishing a local track. ### Common Properties - **Encoding** (VideoEncoding / AudioEncoding) - Codec and bitrate settings. - **PacketTrailerFeatures** (RepeatedField) - Custom packet metadata to send. ``` -------------------------------- ### Publish Web Camera Video Track Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Configures and publishes a video track from a device web camera. Selects a camera by name and sets capture resolution and frame rate. ```csharp var cameras = WebCamTexture.devices; if (cameras.Length > 0) { var webCamSource = new WebCameraSource( deviceName: cameras[0].name, width: 1280, height: 720, frameRate: 30 ); var videoTrack = LocalVideoTrack.CreateVideoTrack("webcam", webCamSource, room); } ``` -------------------------------- ### DataTrackOptions Class Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/data-track.md Configuration options for publishing a data track. Requires a unique name for the track. ```csharp public class DataTrackOptions ``` ```csharp public DataTrackOptions(string name) ``` -------------------------------- ### E2EEManager Constructor Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/e2ee.md Initializes the E2EEManager with a room FFI handle and E2EE configuration. Typically created automatically when connecting with E2EE enabled. ```csharp public E2EEManager(FfiHandle roomHandle, E2EEOptions e2EEOptions) ``` -------------------------------- ### Handle Incoming Byte Streams Source: https://github.com/livekit/client-sdk-unity/blob/main/README.md Registers a handler for incoming byte streams on a specific topic. It demonstrates processing bytes incrementally, retrieving all bytes at once, or writing the stream directly to a file. ```csharp IEnumerator HandleByteStream(ByteStreamReader reader, string participantIdentity) { var info = reader.Info; // Option 1: Process the stream incrementally var readIncremental = reader.ReadIncremental(); while (true) { readIncremental.Reset(); yield return readIncremental; if (readIncremental.IsEos) break; Debug.Log($"Next chunk: {readIncremental.Bytes}"); } // Option 2: Get the entire file after the stream completes var readAllCall = reader.ReadAll(); yield return readAllCall; var data = readAllCall.Bytes; // Option 3: Write the stream to a local file on disk as it arrives var writeToFileCall = reader.WriteToFile(); yield return writeToFileCall; var path = writeToFileCall.FilePath; Debug.Log($"Wrote to file: {path}"); Debug.Log($@" Byte stream received from {participantIdentity} Topic: {info.Topic} Timestamp: {info.Timestamp} ID: {info.Id} Size: {info.TotalLength} (only available if the stream was sent with `SendFile`) "); } // Register the topic after connection to the room room.RegisterByteStreamHandler("my-topic", (reader, identity) => StartCoroutine(HandleByteStream(reader, identity)) ); ``` -------------------------------- ### ConnectionState Enumeration Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/types.md Connection state of a room. ```APIDOC ## ConnectionState ### Description Connection state of a room. ### Enum Members - **ConnConnecting** - **ConnConnected** - **ConnDisconnected** - **ConnReconnecting** ``` -------------------------------- ### Subscribe to Data Track with Buffer Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Subscribes to a remote data track and configures an internal buffer size. Larger buffers increase latency but reduce frame drops. ```csharp var subscribeOptions = new DataTrackSubscribeOptions { BufferSize = 32 // Buffer up to 32 frames }; var stream = remoteDataTrack.Subscribe(subscribeOptions); ``` -------------------------------- ### VideoStream Constructor Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/video-audio-streams.md Initializes a new instance of the `VideoStream` class, which renders a remote video track to a texture for display. It automatically creates and manages render textures and converts YUV to RGB for GPU rendering. ```APIDOC ## VideoStream Constructor ### Description Initializes a new instance of the `VideoStream` class, which renders a remote video track to a texture for display. ### Method ```csharp public VideoStream(IVideoTrack videoTrack) ``` ### Parameters #### Path Parameters - **videoTrack** (`IVideoTrack`) - Required - The remote video track to stream. ### Returns A `VideoStream` instance. ### Throws - `InvalidOperationException` if the track's room or participant is invalid. ### Remarks - Receives I420-formatted video frames from the Rust FFI layer. - Automatically creates and manages render textures as resolution changes. - Converts YUV to RGB for GPU rendering. - Should be updated periodically via a coroutine. ### Example ```csharp void OnRemoteVideoTrackSubscribed(RemoteVideoTrack track) { var videoStream = new VideoStream(track); videoStream.FrameReceived += OnVideoFrameReceived; videoStream.TextureReceived += OnTextureReceived; StartCoroutine(videoStream.UpdateRoutine()); } void OnTextureReceived(Texture tex) { GetComponent().material.mainTexture = tex; } ``` ``` -------------------------------- ### Publish Camera Video Track Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Configures and publishes a video track from a Unity camera. Sets maximum bitrate and frame rate for video encoding. ```csharp var cameraSource = new CameraVideoSource(Camera.main); var videoTrack = LocalVideoTrack.CreateVideoTrack("camera", cameraSource, room); var publishOptions = new TrackPublishOptions { Encoding = new VideoEncoding { MaxBitrate = 2500000, MaxFramerate = 30 } }; ``` -------------------------------- ### Create DataTrackFrame with Timestamp Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/data-track.md Creates a new DataTrackFrame with the current system time as its timestamp. Use this when you need to track the frame's creation time for latency calculations. ```csharp public DataTrackFrame WithUserTimestampNow() ``` -------------------------------- ### Register and Perform RPC Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/README.md Register an RPC method on the local participant to handle incoming calls, and perform RPC calls to remote participants with specified parameters and timeouts. ```csharp // Register handler room.LocalParticipant.RegisterRpcMethod("ping", async (data) => { return "pong"; }); // Perform RPC var rpcParams = new PerformRpcParams { DestinationIdentity = remote.Identity, Method = "ping", Payload = "{}", ResponseTimeout = 15f }; var instruction = room.LocalParticipant.PerformRpc(rpcParams); yield return instruction; if (!instruction.IsError) Debug.Log($ ``` -------------------------------- ### DataTrackFrame.WithUserTimestampNow Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/data-track.md Creates a new DataTrackFrame with the current system time as its timestamp. The original frame remains unchanged. ```APIDOC ## DataTrackFrame.WithUserTimestampNow ### Description Associates the current system time with the frame. Returns a new `DataTrackFrame` with the timestamp set, leaving the original frame unchanged. ### Method ```csharp public DataTrackFrame WithUserTimestampNow() ``` ### Returns New `DataTrackFrame` with timestamp set (original unchanged). ### Example ```csharp var frame = new DataTrackFrame(data).WithUserTimestampNow(); track.TryPush(frame); ``` ``` -------------------------------- ### CameraVideoSource Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md Captures video from a Unity camera. It requires a Unity Camera object during instantiation. ```APIDOC ## CameraVideoSource Captures video from a Unity camera. ```csharp public class CameraVideoSource : RtcVideoSource ``` ### Constructor ```csharp public CameraVideoSource(Camera camera) ``` **Parameters:** | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | `camera` | `Camera` | Yes | Unity camera to capture from | **Example:** ```csharp var cameraSource = new CameraVideoSource(Camera.main); var videoTrack = LocalVideoTrack.CreateVideoTrack("camera", cameraSource, room); ``` ``` -------------------------------- ### BasicAudioSource Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/sources.md A basic custom audio source suitable for testing or simple use cases. It can be instantiated with a specified number of channels. ```APIDOC ## BasicAudioSource A basic custom audio source for testing or simple use cases. ```csharp public class BasicAudioSource : RtcAudioSource ``` ### Constructor ```csharp public BasicAudioSource(int channels = 2) ``` ``` -------------------------------- ### Configure Room for High-Reliability Network Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Sets room options for high-reliability networks, configuring ICE transport and enabling adaptive streaming. ```csharp var rtcConfig = new RTCConfiguration { IceTransportType = IceTransportType.TRANSPORT_ALL, ContinualGatheringPolicy = ContinualGatheringPolicy.GATHER_CONTINUALLY }; var options = new RoomOptions { RtcConfig = rtcConfig, AdaptiveStream = true }; ``` -------------------------------- ### Publish Microphone Audio Track Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/configuration.md Configures and publishes an audio track from the microphone. Sets maximum bitrate for audio encoding. ```csharp var micSource = new MicrophoneSource(channels: 2); var audioTrack = LocalAudioTrack.CreateAudioTrack("microphone", micSource, room); var publishOptions = new TrackPublishOptions { Encoding = new AudioEncoding { MaxBitrate = 64000 } }; var publishInstruction = localParticipant.PublishTrack(audioTrack, publishOptions); ``` -------------------------------- ### Configure End-to-End Encryption Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/README.md Set up end-to-end encryption for the room connection by providing encryption options, including the encryption type and key provider details. After connecting, enable the E2EEManager. ```csharp var e2eeOptions = new E2EEOptions { EncryptionType = EncryptionType.GCM, KeyProviderOptions = new KeyProviderOptions { SharedKey = myEncryptionKey, RatchetWindowSize = 16, FailureTolerance = 10 } }; var options = new RoomOptions { E2EE = e2eeOptions }; yield return room.Connect(url, token, options); var e2eeManager = room.E2EEManager; e2eeManager?.setEnabled(true); ``` -------------------------------- ### PushFrameError Handling Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/errors.md Shows how to catch and handle a PushFrameError when attempting to push data to a local data track. It suggests checking track publication status and room connection. ```csharp try { track.TryPush(frame); } catch (PushFrameError ex) { Debug.LogError($"Failed to push frame: {ex.Message}"); // Check track.IsPublished() and room.IsConnected } ``` -------------------------------- ### Handle RPC Timeout Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/errors.md Demonstrates how to set a response timeout for Remote Procedure Calls (RPCs) and check for `RESPONSE_TIMEOUT` errors. This is useful for detecting unresponsive participants. ```csharp var rpcParams = new PerformRpcParams { DestinationIdentity = remote.Identity, Method = "ping", ResponseTimeout = 5f // Short timeout for ping }; var instruction = localParticipant.PerformRpc(rpcParams); yield return instruction; if (instruction.IsError && instruction.Error.Code == (uint)RpcError.ErrorCode.RESPONSE_TIMEOUT) { Debug.LogWarning($"Remote participant '{remote.Identity}' not responding"); } ``` -------------------------------- ### DataTrackSubscribeOptions Class Source: https://github.com/livekit/client-sdk-unity/blob/main/_autodocs/api-reference/data-track.md Configuration options for subscribing to a data track. Allows setting a maximum buffer size for incoming frames. ```csharp public class DataTrackSubscribeOptions ```