Class Room
- Namespace
- LiveKit.Rtc
- Assembly
- LivekitRtc.dll
A connection to a LiveKit room: joins it with ConnectAsync(string, string, RoomOptions?, CancellationToken), exposes the local and remote participants and their tracks, and raises an event for every change.
public class Room : IDisposable
- Inheritance
-
Room
- Implements
- Inherited Members
Examples
using var room = new Room();
room.ParticipantConnected += (sender, participant) =>
Console.WriteLine($"{participant.Identity} joined");
room.TrackSubscribed += (sender, e) =>
Console.WriteLine($"Subscribed to {e.Track.Name} of {e.Participant.Identity}");
await room.ConnectAsync("wss://my.livekit.instance", token);
// Publish an audio track and feed it 10 ms frames of 16-bit PCM
var source = new AudioSource(48000, 1);
var track = LocalAudioTrack.Create("microphone", source);
await room.LocalParticipant!.PublishTrackAsync(track);
await source.CaptureFrameAsync(new AudioFrame(new short[480], 48000, 1, 480));
await room.DisconnectAsync();
Constructors
Room()
Creates a new Room instance.
public Room()
Properties
ActiveRecording
Whether the room has an active recording.
public bool ActiveRecording { get; }
Property Value
ConnectionState
Current connection state.
public ConnectionState ConnectionState { get; }
Property Value
CreationTime
The time when the room was created.
public DateTime CreationTime { get; }
Property Value
DepartureTimeout
The time in seconds after which a room will be closed after the last participant has disconnected.
public double DepartureTimeout { get; }
Property Value
E2EEManager
The E2EE manager for this room. Null if E2EE is not enabled.
public E2EEManager? E2EEManager { get; }
Property Value
EmptyTimeout
The time in seconds after which an empty room will be automatically closed.
public double EmptyTimeout { get; }
Property Value
IsConnected
Whether the room is currently connected.
public bool IsConnected { get; }
Property Value
LocalParticipant
The local participant in this room.
public LocalParticipant? LocalParticipant { get; }
Property Value
Metadata
Room metadata.
public string? Metadata { get; }
Property Value
Name
Room name.
public string? Name { get; }
Property Value
NumParticipants
Number of participants in the room.
public uint NumParticipants { get; }
Property Value
NumPublishers
Number of publishers in the room.
public uint NumPublishers { get; }
Property Value
RemoteDataTracks
Data tracks currently published by remote participants, by SID.
public IReadOnlyDictionary<string, RemoteDataTrack> RemoteDataTracks { get; }
Property Value
RemoteParticipants
Remote participants in the room (keyed by identity).
public IReadOnlyDictionary<string, RemoteParticipant> RemoteParticipants { get; }
Property Value
Sid
Room session ID (assigned by the server).
public string? Sid { get; }
Property Value
Methods
ConnectAsync(string, string, RoomOptions?, CancellationToken)
Connects to a LiveKit room.
public Task ConnectAsync(string url, string token, RoomOptions? options = null, CancellationToken cancellationToken = default)
Parameters
urlstringThe LiveKit server URL (e.g., wss://your-server.livekit.cloud).
tokenstringThe access token for authentication.
optionsRoomOptionsOptional room options.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task that completes when the connection is established.
Disconnect()
Disconnects from the room, blocking the calling thread until it is done. Prefer DisconnectAsync() in asynchronous code.
public void Disconnect()
DisconnectAsync()
Disconnects from the room.
public Task DisconnectAsync()
Returns
- Task
A task that completes once the room is disconnected and its resources are released.
Dispose()
Disconnects from the room if it is still connected, raising the usual teardown events, and releases the native resources.
public void Dispose()
GetRtcStatsAsync()
Gets RTC statistics for the current session.
public Task<RtcStats> GetRtcStatsAsync()
Returns
Exceptions
- InvalidOperationException
Thrown when not connected to a room.
RegisterByteStreamHandler(string, ByteStreamHandler)
Registers a handler for incoming byte data streams on a specific topic.
public void RegisterByteStreamHandler(string topic, ByteStreamHandler handler)
Parameters
topicstringThe topic to listen for byte streams on.
handlerByteStreamHandlerHandler to process incoming byte streams.
Exceptions
- StreamException
Thrown when a handler for this topic is already registered.
RegisterTextStreamHandler(string, TextStreamHandler)
Registers a handler for incoming text data streams on a specific topic.
public void RegisterTextStreamHandler(string topic, TextStreamHandler handler)
Parameters
topicstringThe topic to listen for text streams on.
handlerTextStreamHandlerHandler to process incoming text streams.
Exceptions
- StreamException
Thrown when a handler for this topic is already registered.
SimulateScenarioAsync(SimulateScenarioKind, CancellationToken)
Forces a reconnection scenario, for tests. With SimulateFullReconnect the SDK rebuilds its session and republishes the local tracks: Reconnecting fires, then one LocalTrackRepublished per published track, then Reconnected. With SimulateSignalReconnect only the signaling connection is re-established (a resume) and the publications are kept. See SimulateScenarioKind for the other variants. The returned task completes once the SDK has started the scenario, not when the reconnection has finished: observe that through the room events.
public Task SimulateScenarioAsync(SimulateScenarioKind scenario, CancellationToken cancellationToken = default)
Parameters
scenarioSimulateScenarioKindThe scenario to simulate.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task that completes once the SDK has started the scenario, not when the reconnection has finished.
Exceptions
- InvalidOperationException
Thrown when not connected to a room.
- RoomException
Thrown when the SDK reports that the scenario failed.
UnregisterByteStreamHandler(string)
Unregisters a byte stream handler for a specific topic.
public void UnregisterByteStreamHandler(string topic)
Parameters
topicstringThe topic to unregister.
UnregisterTextStreamHandler(string)
Unregisters a text stream handler for a specific topic.
public void UnregisterTextStreamHandler(string topic)
Parameters
topicstringThe topic to unregister.
Events
ActiveSpeakersChanged
Event raised when active speakers change.
public event EventHandler<ActiveSpeakersChangedEventArgs>? ActiveSpeakersChanged
Event Type
ChatMessageReceived
Event raised when a chat message is received.
public event EventHandler<ChatMessageReceivedEventArgs>? ChatMessageReceived
Event Type
Connected
Event raised when room is connected.
public event EventHandler? Connected
Event Type
ConnectionQualityChanged
Event raised when connection quality changes for a participant.
public event EventHandler<ConnectionQualityChangedEventArgs>? ConnectionQualityChanged
Event Type
ConnectionStateChanged
Event raised when connection state changes.
public event EventHandler<ConnectionState>? ConnectionStateChanged
Event Type
DataChannelBufferedAmountLowThresholdChanged
Raised after SetDataChannelBufferedAmountLowThreshold(ulong, DataPacketKind) changed the threshold of a data channel.
public event EventHandler<DataChannelBufferedAmountLowThresholdChangedEventArgs>? DataChannelBufferedAmountLowThresholdChanged
Event Type
DataReceived
Event raised when data is received.
public event EventHandler<DataReceivedEventArgs>? DataReceived
Event Type
DataTrackPublished
Raised when a remote participant publishes a data track. Subscribe to it with Subscribe(uint?).
public event EventHandler<RemoteDataTrack>? DataTrackPublished
Event Type
DataTrackUnpublished
Raised when a remote data track is unpublished.
public event EventHandler<DataTrackUnpublishedEventArgs>? DataTrackUnpublished
Event Type
Disconnected
Event raised when room is disconnected.
public event EventHandler<DisconnectReason>? Disconnected
Event Type
E2EEStateChanged
Raised when the encryption state of a participant changes: Ok once its frames encrypt or
decrypt, or a failure such as MissingKey or DecryptionFailed.
public event EventHandler<E2EEStateChangedEventArgs>? E2EEStateChanged
Event Type
LocalTrackPublished
Event raised when a local track is published.
public event EventHandler<LocalTrackPublishedEventArgs>? LocalTrackPublished
Event Type
LocalTrackRepublished
Raised when the SDK re-published a local track during a full reconnect. The publication object is updated in place with the new server-assigned SIDs; the previous SID is passed so state keyed by it can be reconciled.
public event EventHandler<LocalTrackRepublishedEventArgs>? LocalTrackRepublished
Event Type
LocalTrackSubscribed
Event raised when a local track is subscribed by a remote participant.
public event EventHandler<LocalTrackSubscribedEventArgs>? LocalTrackSubscribed
Event Type
LocalTrackUnpublished
Event raised when a local track is unpublished.
public event EventHandler<LocalTrackPublishedEventArgs>? LocalTrackUnpublished
Event Type
Moved
Event raised when the local participant is moved to a new room.
public event EventHandler<RoomInfo>? Moved
Event Type
ParticipantActive
Raised when a remote participant becomes active and is ready to receive data messages.
public event EventHandler<RemoteParticipant>? ParticipantActive
Event Type
ParticipantAttributesChanged
Event raised when a participant's attributes change.
public event EventHandler<ParticipantAttributesChangedEventArgs>? ParticipantAttributesChanged
Event Type
ParticipantConnected
Event raised when a participant connects to the room.
public event EventHandler<Participant>? ParticipantConnected
Event Type
ParticipantDisconnected
Event raised when a participant disconnects from the room.
public event EventHandler<Participant>? ParticipantDisconnected
Event Type
ParticipantEncryptionStatusChanged
Event raised when a participant's encryption status changes.
public event EventHandler<ParticipantEncryptionStatusChangedEventArgs>? ParticipantEncryptionStatusChanged
Event Type
ParticipantMetadataChanged
Event raised when a participant's metadata changes.
public event EventHandler<Participant>? ParticipantMetadataChanged
Event Type
ParticipantNameChanged
Event raised when a participant's name changes.
public event EventHandler<Participant>? ParticipantNameChanged
Event Type
ParticipantPermissionsChanged
Raised when the permissions of a participant (local or remote) change. Permissions is already updated when the event fires.
public event EventHandler<ParticipantPermissionsChangedEventArgs>? ParticipantPermissionsChanged
Event Type
Reconnected
Event raised when room has reconnected.
public event EventHandler? Reconnected
Event Type
Reconnecting
Event raised when room is reconnecting.
public event EventHandler? Reconnecting
Event Type
RoomMetadataChanged
Event raised when room metadata changes.
public event EventHandler<string>? RoomMetadataChanged
Event Type
RoomSidChanged
Event raised when the room SID changes.
public event EventHandler<string>? RoomSidChanged
Event Type
RoomUpdated
Event raised when room information is updated.
public event EventHandler<RoomInfo>? RoomUpdated
Event Type
SipDtmfReceived
Event raised when a SIP DTMF tone is received.
public event EventHandler<SipDtmfReceivedEventArgs>? SipDtmfReceived
Event Type
TokenRefreshed
Event raised when the access token is refreshed.
public event EventHandler<string>? TokenRefreshed
Event Type
TrackMuted
Event raised when a track is muted.
public event EventHandler<TrackMutedEventArgs>? TrackMuted
Event Type
TrackPublished
Event raised when a remote track is published.
public event EventHandler<TrackPublishedEventArgs>? TrackPublished
Event Type
TrackSubscribed
Event raised when a remote track is subscribed.
public event EventHandler<TrackSubscribedEventArgs>? TrackSubscribed
Event Type
TrackSubscriptionFailed
Event raised when track subscription fails.
public event EventHandler<TrackSubscriptionFailedEventArgs>? TrackSubscriptionFailed
Event Type
TrackUnmuted
Event raised when a track is unmuted.
public event EventHandler<TrackMutedEventArgs>? TrackUnmuted
Event Type
TrackUnpublished
Event raised when a remote track is unpublished.
public event EventHandler<TrackPublishedEventArgs>? TrackUnpublished
Event Type
TrackUnsubscribed
Event raised when a remote track is unsubscribed.
public event EventHandler<TrackSubscribedEventArgs>? TrackUnsubscribed
Event Type
TranscriptionReceived
Event raised when a transcription is received.
public event EventHandler<TranscriptionReceivedEventArgs>? TranscriptionReceived