25#include "livekit/data_stream.h"
26#include "livekit/e2ee.h"
27#include "livekit/ffi_handle.h"
28#include "livekit/room_event_types.h"
29#include "livekit/stats.h"
30#include "livekit/subscription_thread_dispatcher.h"
31#include "livekit/visibility.h"
43class LocalParticipant;
44class RemoteParticipant;
333 friend class RoomCallbackTest;
335 mutable std::mutex lock_;
339 std::shared_ptr<FfiHandle> room_handle_;
342 std::shared_ptr<LocalParticipant> local_participant_;
343 std::unordered_map<std::string, std::shared_ptr<RemoteParticipant>> remote_participants_;
345 std::unordered_map<std::string, TextStreamHandler> text_stream_handlers_;
346 std::unordered_map<std::string, ByteStreamHandler> byte_stream_handlers_;
347 std::unordered_map<std::string, std::shared_ptr<TextStreamReader>> text_stream_readers_;
348 std::unordered_map<std::string, std::shared_ptr<ByteStreamReader>> byte_stream_readers_;
351 std::shared_ptr<E2EEManager> e2ee_manager_;
352 std::shared_ptr<SubscriptionThreadDispatcher> subscription_thread_dispatcher_;
357 void onEvent(
const proto::FfiEvent& event);
Interface for receiving room-level events.
Definition room_delegate.h:33
Represents a LiveKit room session.
Definition room.h:132
void registerByteStreamHandler(const std::string &topic, ByteStreamHandler handler)
Register a handler for incoming byte streams on a specific topic.
void setDelegate(RoomDelegate *delegate)
Assign a RoomDelegate that receives room lifecycle callbacks.
bool disconnect(DisconnectReason reason=DisconnectReason::ClientInitiated)
Disconnect from the room.
void setOnVideoFrameEventCallback(const std::string &participant_identity, const std::string &track_name, VideoFrameEventCallback callback, const VideoStream::Options &opts={})
Sets the video frame event callback via SubscriptionThreadDispatcher.
std::future< SessionStats > getStats() const
Retrieve aggregated WebRTC stats for this room session.
void unregisterByteStreamHandler(const std::string &topic)
Unregister the byte stream handler for the given topic.
std::weak_ptr< E2EEManager > e2eeManager() const
Returns the room's E2EE manager as a weak handle, or an empty handle if E2EE was not enabled at conne...
std::weak_ptr< LocalParticipant > localParticipant() const
Get the local participant.
void registerTextStreamHandler(const std::string &topic, TextStreamHandler handler)
Register a handler for incoming text streams on a specific topic.
void removeOnDataFrameCallback(DataFrameCallbackId id)
Removes the data frame callback via SubscriptionThreadDispatcher.
void unregisterTextStreamHandler(const std::string &topic)
Unregister the text stream handler for the given topic.
void setOnVideoFrameCallback(const std::string &participant_identity, const std::string &track_name, VideoFrameCallback callback, const VideoStream::Options &opts={})
Sets the video frame callback via SubscriptionThreadDispatcher.
RoomInfoData roomInfo() const
Retrieve static metadata about the room.
bool connect(const std::string &url, const std::string &token, const RoomOptions &options)
Connect to a LiveKit room using the given URL and token, applying the supplied connection options.
void clearOnVideoFrameCallback(const std::string &participant_identity, const std::string &track_name)
Clears the video frame callback via SubscriptionThreadDispatcher.
void setOnAudioFrameCallback(const std::string &participant_identity, const std::string &track_name, AudioFrameCallback callback, const AudioStream::Options &opts={})
Sets the audio frame callback via SubscriptionThreadDispatcher.
DataFrameCallbackId addOnDataFrameCallback(const std::string &participant_identity, const std::string &track_name, DataFrameCallback callback)
Adds a data frame callback via SubscriptionThreadDispatcher.
std::vector< std::weak_ptr< RemoteParticipant > > remoteParticipants() const
Returns a snapshot of all current remote participants.
void clearOnAudioFrameCallback(const std::string &participant_identity, const std::string &track_name)
Clears the audio frame callback via SubscriptionThreadDispatcher.
ConnectionState connectionState() const
Returns the current connection state of the room.
std::weak_ptr< RemoteParticipant > remoteParticipant(const std::string &identity) const
Look up a remote participant by identity.
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
std::function< void(const VideoFrameEvent &)> VideoFrameEventCallback
Callback type for incoming video frame events.
Definition subscription_thread_dispatcher.h:51
std::uint64_t DataFrameCallbackId
Opaque identifier returned by addOnDataFrameCallback, used to remove an individual subscription via r...
Definition subscription_thread_dispatcher.h:62
std::function< void(const std::vector< std::uint8_t > &payload, std::optional< std::uint64_t > user_timestamp)> DataFrameCallback
Callback type for incoming data track frames.
Definition subscription_thread_dispatcher.h:58
std::function< void(std::shared_ptr< ByteStreamReader >, const std::string &participant_identity)> ByteStreamHandler
Callback invoked when a new incoming byte stream is opened.
Definition data_stream.h:278
std::function< void(std::shared_ptr< TextStreamReader >, const std::string &participant_identity)> TextStreamHandler
Callback invoked when a new incoming text stream is opened.
Definition data_stream.h:270
std::function< void(const AudioFrame &)> AudioFrameCallback
Callback type for incoming audio frames.
Definition subscription_thread_dispatcher.h:43
ConnectionState
Current connection state of the room.
Definition room_event_types.h:49
DisconnectReason
Reason why a participant or room was disconnected.
Definition room_event_types.h:80
std::function< void(const VideoFrame &frame, std::int64_t timestamp_us)> VideoFrameCallback
Callback type for incoming video frames.
Definition subscription_thread_dispatcher.h:47
Configuration options for AudioStream creation.
Definition audio_stream.h:66
Represents a single ICE server configuration.
Definition room.h:47
std::string username
Optional username for TURN authentication.
Definition room.h:52
std::string url
TURN/STUN server URL (e.g. "stun:stun.l.google.com:19302").
Definition room.h:49
std::string credential
Optional credential (password) for TURN authentication.
Definition room.h:55
Snapshot of core room information.
Definition room_event_types.h:125
Top-level room connection options.
Definition room.h:72
std::optional< bool > adaptive_stream
Enable adaptive stream for subscribed video tracks.
Definition room.h:93
bool single_peer_connection
Enable single peer connection mode.
Definition room.h:118
std::optional< std::uint32_t > join_retries
Number of retries for the initial room join after the first attempt.
Definition room.h:113
std::optional< std::chrono::milliseconds > connect_timeout
Timeout for each individual signal connection attempt.
Definition room.h:123
std::optional< RtcConfig > rtc_config
Optional WebRTC configuration (ICE policy, servers, etc.)
Definition room.h:108
bool dynacast
Enable dynacast (server sends optimal layers depending on subscribers).
Definition room.h:98
std::optional< E2EEOptions > encryption
Optional end-to-end encryption settings.
Definition room.h:103
bool auto_subscribe
If true (default), automatically subscribe to all remote tracks.
Definition room.h:79
WebRTC configuration (ICE, transport, etc.).
Definition room.h:59
int continual_gathering_policy
Continuous or single ICE gathering.
Definition room.h:65
std::vector< IceServer > ice_servers
List of STUN/TURN servers for ICE candidate generation.
Definition room.h:68
int ice_transport_type
ICE transport type (e.g., ALL, RELAY). Maps to proto::IceTransportType.
Definition room.h:61
Options for creating a decoded video frame stream.
Definition video_stream.h:69