Table of Contents

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

bool

ConnectionState

Current connection state.

public ConnectionState ConnectionState { get; }

Property Value

ConnectionState

CreationTime

The time when the room was created.

public DateTime CreationTime { get; }

Property Value

DateTime

DepartureTimeout

The time in seconds after which a room will be closed after the last participant has disconnected.

public double DepartureTimeout { get; }

Property Value

double

E2EEManager

The E2EE manager for this room. Null if E2EE is not enabled.

public E2EEManager? E2EEManager { get; }

Property Value

E2EEManager

EmptyTimeout

The time in seconds after which an empty room will be automatically closed.

public double EmptyTimeout { get; }

Property Value

double

IsConnected

Whether the room is currently connected.

public bool IsConnected { get; }

Property Value

bool

LocalParticipant

The local participant in this room.

public LocalParticipant? LocalParticipant { get; }

Property Value

LocalParticipant

Metadata

Room metadata.

public string? Metadata { get; }

Property Value

string

Name

Room name.

public string? Name { get; }

Property Value

string

NumParticipants

Number of participants in the room.

public uint NumParticipants { get; }

Property Value

uint

NumPublishers

Number of publishers in the room.

public uint NumPublishers { get; }

Property Value

uint

RemoteDataTracks

Data tracks currently published by remote participants, by SID.

public IReadOnlyDictionary<string, RemoteDataTrack> RemoteDataTracks { get; }

Property Value

IReadOnlyDictionary<string, RemoteDataTrack>

RemoteParticipants

Remote participants in the room (keyed by identity).

public IReadOnlyDictionary<string, RemoteParticipant> RemoteParticipants { get; }

Property Value

IReadOnlyDictionary<string, RemoteParticipant>

Sid

Room session ID (assigned by the server).

public string? Sid { get; }

Property Value

string

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

url string

The LiveKit server URL (e.g., wss://your-server.livekit.cloud).

token string

The access token for authentication.

options RoomOptions

Optional room options.

cancellationToken CancellationToken

Cancellation 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

Task<RtcStats>

RTC statistics containing publisher and subscriber stats.

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

topic string

The topic to listen for byte streams on.

handler ByteStreamHandler

Handler 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

topic string

The topic to listen for text streams on.

handler TextStreamHandler

Handler 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

scenario SimulateScenarioKind

The scenario to simulate.

cancellationToken CancellationToken

Cancellation 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

topic string

The topic to unregister.

UnregisterTextStreamHandler(string)

Unregisters a text stream handler for a specific topic.

public void UnregisterTextStreamHandler(string topic)

Parameters

topic string

The topic to unregister.

Events

ActiveSpeakersChanged

Event raised when active speakers change.

public event EventHandler<ActiveSpeakersChangedEventArgs>? ActiveSpeakersChanged

Event Type

EventHandler<ActiveSpeakersChangedEventArgs>

ChatMessageReceived

Event raised when a chat message is received.

public event EventHandler<ChatMessageReceivedEventArgs>? ChatMessageReceived

Event Type

EventHandler<ChatMessageReceivedEventArgs>

Connected

Event raised when room is connected.

public event EventHandler? Connected

Event Type

EventHandler

ConnectionQualityChanged

Event raised when connection quality changes for a participant.

public event EventHandler<ConnectionQualityChangedEventArgs>? ConnectionQualityChanged

Event Type

EventHandler<ConnectionQualityChangedEventArgs>

ConnectionStateChanged

Event raised when connection state changes.

public event EventHandler<ConnectionState>? ConnectionStateChanged

Event Type

EventHandler<ConnectionState>

DataChannelBufferedAmountLowThresholdChanged

Raised after SetDataChannelBufferedAmountLowThreshold(ulong, DataPacketKind) changed the threshold of a data channel.

public event EventHandler<DataChannelBufferedAmountLowThresholdChangedEventArgs>? DataChannelBufferedAmountLowThresholdChanged

Event Type

EventHandler<DataChannelBufferedAmountLowThresholdChangedEventArgs>

DataReceived

Event raised when data is received.

public event EventHandler<DataReceivedEventArgs>? DataReceived

Event Type

EventHandler<DataReceivedEventArgs>

DataTrackPublished

Raised when a remote participant publishes a data track. Subscribe to it with Subscribe(uint?).

public event EventHandler<RemoteDataTrack>? DataTrackPublished

Event Type

EventHandler<RemoteDataTrack>

DataTrackUnpublished

Raised when a remote data track is unpublished.

public event EventHandler<DataTrackUnpublishedEventArgs>? DataTrackUnpublished

Event Type

EventHandler<DataTrackUnpublishedEventArgs>

Disconnected

Event raised when room is disconnected.

public event EventHandler<DisconnectReason>? Disconnected

Event Type

EventHandler<DisconnectReason>

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

EventHandler<E2EEStateChangedEventArgs>

LocalTrackPublished

Event raised when a local track is published.

public event EventHandler<LocalTrackPublishedEventArgs>? LocalTrackPublished

Event Type

EventHandler<LocalTrackPublishedEventArgs>

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

EventHandler<LocalTrackRepublishedEventArgs>

LocalTrackSubscribed

Event raised when a local track is subscribed by a remote participant.

public event EventHandler<LocalTrackSubscribedEventArgs>? LocalTrackSubscribed

Event Type

EventHandler<LocalTrackSubscribedEventArgs>

LocalTrackUnpublished

Event raised when a local track is unpublished.

public event EventHandler<LocalTrackPublishedEventArgs>? LocalTrackUnpublished

Event Type

EventHandler<LocalTrackPublishedEventArgs>

Moved

Event raised when the local participant is moved to a new room.

public event EventHandler<RoomInfo>? Moved

Event Type

EventHandler<RoomInfo>

ParticipantActive

Raised when a remote participant becomes active and is ready to receive data messages.

public event EventHandler<RemoteParticipant>? ParticipantActive

Event Type

EventHandler<RemoteParticipant>

ParticipantAttributesChanged

Event raised when a participant's attributes change.

public event EventHandler<ParticipantAttributesChangedEventArgs>? ParticipantAttributesChanged

Event Type

EventHandler<ParticipantAttributesChangedEventArgs>

ParticipantConnected

Event raised when a participant connects to the room.

public event EventHandler<Participant>? ParticipantConnected

Event Type

EventHandler<Participant>

ParticipantDisconnected

Event raised when a participant disconnects from the room.

public event EventHandler<Participant>? ParticipantDisconnected

Event Type

EventHandler<Participant>

ParticipantEncryptionStatusChanged

Event raised when a participant's encryption status changes.

public event EventHandler<ParticipantEncryptionStatusChangedEventArgs>? ParticipantEncryptionStatusChanged

Event Type

EventHandler<ParticipantEncryptionStatusChangedEventArgs>

ParticipantMetadataChanged

Event raised when a participant's metadata changes.

public event EventHandler<Participant>? ParticipantMetadataChanged

Event Type

EventHandler<Participant>

ParticipantNameChanged

Event raised when a participant's name changes.

public event EventHandler<Participant>? ParticipantNameChanged

Event Type

EventHandler<Participant>

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

EventHandler<ParticipantPermissionsChangedEventArgs>

Reconnected

Event raised when room has reconnected.

public event EventHandler? Reconnected

Event Type

EventHandler

Reconnecting

Event raised when room is reconnecting.

public event EventHandler? Reconnecting

Event Type

EventHandler

RoomMetadataChanged

Event raised when room metadata changes.

public event EventHandler<string>? RoomMetadataChanged

Event Type

EventHandler<string>

RoomSidChanged

Event raised when the room SID changes.

public event EventHandler<string>? RoomSidChanged

Event Type

EventHandler<string>

RoomUpdated

Event raised when room information is updated.

public event EventHandler<RoomInfo>? RoomUpdated

Event Type

EventHandler<RoomInfo>

SipDtmfReceived

Event raised when a SIP DTMF tone is received.

public event EventHandler<SipDtmfReceivedEventArgs>? SipDtmfReceived

Event Type

EventHandler<SipDtmfReceivedEventArgs>

TokenRefreshed

Event raised when the access token is refreshed.

public event EventHandler<string>? TokenRefreshed

Event Type

EventHandler<string>

TrackMuted

Event raised when a track is muted.

public event EventHandler<TrackMutedEventArgs>? TrackMuted

Event Type

EventHandler<TrackMutedEventArgs>

TrackPublished

Event raised when a remote track is published.

public event EventHandler<TrackPublishedEventArgs>? TrackPublished

Event Type

EventHandler<TrackPublishedEventArgs>

TrackSubscribed

Event raised when a remote track is subscribed.

public event EventHandler<TrackSubscribedEventArgs>? TrackSubscribed

Event Type

EventHandler<TrackSubscribedEventArgs>

TrackSubscriptionFailed

Event raised when track subscription fails.

public event EventHandler<TrackSubscriptionFailedEventArgs>? TrackSubscriptionFailed

Event Type

EventHandler<TrackSubscriptionFailedEventArgs>

TrackUnmuted

Event raised when a track is unmuted.

public event EventHandler<TrackMutedEventArgs>? TrackUnmuted

Event Type

EventHandler<TrackMutedEventArgs>

TrackUnpublished

Event raised when a remote track is unpublished.

public event EventHandler<TrackPublishedEventArgs>? TrackUnpublished

Event Type

EventHandler<TrackPublishedEventArgs>

TrackUnsubscribed

Event raised when a remote track is unsubscribed.

public event EventHandler<TrackSubscribedEventArgs>? TrackUnsubscribed

Event Type

EventHandler<TrackSubscribedEventArgs>

TranscriptionReceived

Event raised when a transcription is received.

public event EventHandler<TranscriptionReceivedEventArgs>? TranscriptionReceived

Event Type

EventHandler<TranscriptionReceivedEventArgs>