DataChannelDotnet 1.1.2
dotnet add package DataChannelDotnet --version 1.1.2
NuGet\Install-Package DataChannelDotnet -Version 1.1.2
<PackageReference Include="DataChannelDotnet" Version="1.1.2" />
<PackageVersion Include="DataChannelDotnet" Version="1.1.2" />
<PackageReference Include="DataChannelDotnet" />
paket add DataChannelDotnet --version 1.1.2
#r "nuget: DataChannelDotnet, 1.1.2"
#:package DataChannelDotnet@1.1.2
#addin nuget:?package=DataChannelDotnet&version=1.1.2
#tool nuget:?package=DataChannelDotnet&version=1.1.2
DataChannelDotnet - C# WebRtc library
DataChannelDotnet is a high performance, minimal overhead wrapper around libdatachannel for WebRtc, it supports both datachannels and media tracks. Raw bindings are generated automatically via clangsharp using Github Actions, and are included in the DataChannel.Bindings package.
Usage (Managed version)
IRtcPeerConnection host = new RtcPeerConnection(new RtcPeerConfiguration()
{
IceServers = ["stun:stun.l.google.com:19302"]
});
IRtcPeerConnection client = new RtcPeerConnection(new RtcPeerConfiguration()
{
IceServers = ["stun:stun.l.google.com:19302"]
});
host.OnConnectionStateChange += (_, state) => Console.WriteLine($"Host connection state -> {state}");
client.OnConnectionStateChange += (_, state) => Console.WriteLine($"Client connection state -> {state}");
host.OnCandidateSafe += (_, candidate) => client.AddRemoteCandidate(candidate);
client.OnCandidateSafe += (_, candidate) => host.AddRemoteCandidate(candidate);
host.OnLocalDescriptionSafe += (_, description) => client.SetRemoteDescription(description);
client.OnLocalDescriptionSafe += (_, description) => host.SetRemoteDescription(description);
client.OnDataChannel += (_, channel) =>
{
channel.OnTextReceivedSafe += (dataChannel, data) =>
{
Console.WriteLine($"Client: received '{data.Text}'");
};
};
var hostChannel = host.CreateDataChannel(new RtcCreateDataChannelArgs()
{
Label = "testchannel1"
});
hostChannel.OnOpen += channel =>
{
channel.Send("Hello :)");
};
Raw C bindings can also be used via the static Rtc class in DataChannel.Bindings. Check the C API Documentation from Libdatachannel for usage. Note that using the raw bindings will require unsafe code to be enabled in your project.
Logging
You can enable Libdatachannel log output by calling RtcLog.Initialize(level, callback);
Unhandled exceptions
If an unhandled exception is thrown on an RtcThread callback, RtcTools.UnhandledException will be raised.
Performance
This is a thin wrapper, so the performance should be very close to the native Libdatachannel library. Sending & receiving data (via Track or Datachannel) is entirely allocation free.
Here is the results of a throughput benchmark, sending & receiving data on localhost, running on .net 9 on a Ryzen 5500. This shows around 55-60MB/s throughput, which is consistent with Libdatachannels own benchmark. This also shows zero allocation sending & receiving. It should be noted that WebRtc is generally not designed for large file transfer scenarios.
Method | Mean | Error | StdDev | Allocated |
---|---|---|---|---|
SendAndReceive100MB | 1,728.885 ms | 12.9256 ms | 12.0906 ms | - |
SendAndReceive50MB | 849.148 ms | 11.5134 ms | 10.7696 ms | - |
SendAndReceive1MB | 16.517 ms | 0.3237 ms | 0.3854 ms | - |
SendAndReceive256KB | 3.818 ms | 0.1247 ms | 0.3657 ms | - |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- DataChannelDotnet.Bindings (= 0.23.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.