.NET SDK to integrate LiveKit's real-time video, audio, and data capabilities into your .NET applications using WebRTC. Access the same powerful API offered by client SDKs, but directly from your .NET server: connect to rooms as a participant, publish and subscribe to audio/video tracks, send and receive data messages, perform RPC calls, and more.
Note
This SDK does not provide Server APIs to manage LiveKit resources such as Rooms, Egress, Ingress or SIP. If you want to manage LiveKit APIs from your .NET backend, please check Livekit.Server.Sdk.Dotnet instead.
This library is crafted based on three core principles:
- Livekit.Rtc.Dotnet uses the C# auto-generated protobuf implementation of LiveKit RTC protocol. This ensures compatibility and ease of maintenance as the API evolves.
- Livekit.Rtc.Dotnet uses C# FFI bindings to the LiveKit Rust SDK. This allows us to leverage existing, well-tested code for WebRTC functionality that is already in use in other LiveKit SDKs. It brings the benefits of native performance for any OS platform while providing a common .NET interface. The library includes precompiled native binaries for Windows, Linux, and macOS, for both x64 and ARM64 architectures.
- Livekit.Rtc.Dotnet maintains full feature parity with other LiveKit RTC SDKs for the server side, especially the two more mature ones: Node.js and Python.
Publish and subscribe to audio/video tracks with full programmatic control. Process frames in real-time, mix audio sources, and build custom media pipelines. Perfect for server-side processing.
Send reliable or lossy data messages, implement RPC request-response patterns, and build real-time chat with topic-based channels. Full control over data flow between participants.
Active speaker detection, transcription support, connection quality monitoring, and 25+ event types for comprehensive room state management.
Built-in end-to-end encryption (E2EE) with AES-GCM, key rotation, and per-participant key management. Keep your sensitive communications secure, also in your .NET server.
Automatic reconnection, multi-room support, isolated contexts, and battle-tested WebRTC implementation from the LiveKit Rust SDK.
dotnet add package Livekit.Rtc.Dotnetusing LiveKit.Rtc;
var room = new Room();
await room.ConnectAsync("wss://your-livekit-server.com", "your-access-token",
new RoomOptions { AutoSubscribe = true });
Console.WriteLine($"Connected to {room.Name}");
await room.DisconnectAsync();var audioSource = new AudioSource(48000, 1); // 48kHz, mono
var audioTrack = LocalAudioTrack.Create("my-audio", audioSource);
var publication = await room.LocalParticipant!.PublishTrackAsync(audioTrack);
// Capture audio frames
var audioData = new short[480]; // 10ms at 48kHz
var audioFrame = new AudioFrame(audioData, 48000, 1, 480);
await audioSource.CaptureFrameAsync(audioFrame);var videoSource = new VideoSource(1920, 1080);
var videoTrack = LocalVideoTrack.Create("my-video", videoSource);
await room.LocalParticipant!.PublishTrackAsync(videoTrack);
// Capture video frames
var videoData = new byte[1920 * 1080 * 4]; // RGBA
var videoFrame = new VideoFrame(1920, 1080, Proto.VideoBufferType.Rgba, videoData);
videoSource.CaptureFrame(videoFrame);room.TrackSubscribed += async (sender, e) => {
if (e.Track is RemoteVideoTrack videoTrack) {
using var videoStream = new VideoStream(videoTrack);
await foreach (var frame in videoStream.WithCancellation(cts.Token)) {
// Process video frame
Console.WriteLine($"Frame: {frame.Frame.Width}x{frame.Frame.Height}");
}
}
};room.ParticipantConnected += (sender, participant) => {
Console.WriteLine($"{participant.Identity} joined");
};
room.ActiveSpeakersChanged += (sender, e) => {
Console.WriteLine($"Active speakers: {e.Speakers.Count}");
};
room.DataReceived += (sender, e) => {
var message = Encoding.UTF8.GetString(e.Data);
Console.WriteLine($"Data from {e.Participant.Identity}: {message}");
};var key = new byte[32]; // AES-256 key
var options = new RoomOptions {
E2EE = new E2EEOptions {
KeyProviderOptions = new KeyProviderOptions { SharedKey = key }
}
};
await room.ConnectAsync(url, token, options);
// All tracks automatically encrypted/decrypted// Register RPC method handler
room.LocalParticipant!.RegisterRpcMethod("greet", async (data) => {
return $"Hello, {data.CallerIdentity}!";
});
// Call RPC method on another participant
var response = await room.LocalParticipant!.PerformRpcAsync(
destinationIdentity: "other-participant",
method: "greet",
payload: "{}",
responseTimeout: 5
);At LivekitRtc.Example you can find several example applications demonstrating the usage of LiveKit.Rtc.Dotnet SDK. See the examples README for more details.
Make sure to clone with submodule option:
git clone --recurse-submodules https://github.com/pabloFuente/livekit-server-sdk-dotnet.gitAll E2E tests automatically launch necessary services as Docker containers with Testcontainers.
dotnet test LivekitRtc.TestsPrerequisites:
- .NET 8.0+ SDK
- protoc
- Rust 1.85.0+ (only if also building native libraries from source)
The easiest way to get the latest FFI binaries without building from source:
# From LivekitRtc directory
./download_ffi.sh # Downloads latest version
./download_ffi.sh 0.12.44 # Or specify a versionThis downloads pre-compiled binaries from LiveKit Rust SDK releases for all supported platforms (Windows, Linux, macOS on x64 and ARM64).
If you want to modify the Rust/FFI code or use unreleased features. You will need:
# From LivekitRtc directory
git submodule update --init --recursive
cd rust-sdks/livekit-ffi
cargo build --releaseAfter building, copy the native libraries from target/release/ to the appropriate runtimes/{rid}/native/ folders. Take into account that Rust builds for the host platform by default, so you may need to cross-compile for other platforms.
# From the root directory (livekit-server-sdk-dotnet/.)
./generate_proto.sh# From LivekitRtc directory
dotnet buildTo upgrade the version of the rust-sdks Git submodule:
cd rust-sdks
git fetch --all
git checkout <COMMIT_HASH/TAG/BRANCH> # e.g. git checkout livekit-ffi/v0.12.50
cd ..
./generate_proto.sh
dotnet pack -c Debug -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkgThen commit:
git commit -m "Update rust-sdks to <VERSION>"
git push- Create a commit for the new version updating the
<Version>property inLivekitRtc.csproj. - Make sure to run script
./build_local.shto properly format all files with csharpier. Commit any changes in the repo after the script finishes. - Create a new release in GitHub with:
- Release title
rtc-X.Y.Z - A new tag
rtc-X.Y.Z - Description with relevant changes (e.g.,
Update to LiveKit Rust SDK vA.B.C)
- Release title
Important
The rtc- prefix in the tag is mandatory for the publish workflow to identify that it is a release for package Livekit.Rtc.Dotnet specifically.
After creating the release, workflow publish.yml will automatically publish the new version to NuGet and will perform the necessary post-release tasks.