23#include "livekit/data_stream.h"
24#include "livekit/e2ee.h"
25#include "livekit/ffi_handle.h"
26#include "livekit/room_event_types.h"
27#include "livekit/stats.h"
28#include "livekit/subscription_thread_dispatcher.h"
29#include "livekit/visibility.h"
41class LocalParticipant;
42class RemoteParticipant;
299 friend class RoomCallbackTest;
301 mutable std::mutex lock_;
305 std::shared_ptr<FfiHandle> room_handle_;
308 std::shared_ptr<LocalParticipant> local_participant_;
309 std::unordered_map<std::string, std::shared_ptr<RemoteParticipant>> remote_participants_;
311 std::unordered_map<std::string, TextStreamHandler> text_stream_handlers_;
312 std::unordered_map<std::string, ByteStreamHandler> byte_stream_handlers_;
313 std::unordered_map<std::string, std::shared_ptr<TextStreamReader>> text_stream_readers_;
314 std::unordered_map<std::string, std::shared_ptr<ByteStreamReader>> byte_stream_readers_;
317 std::shared_ptr<E2EEManager> e2ee_manager_;
318 std::shared_ptr<SubscriptionThreadDispatcher> subscription_thread_dispatcher_;
323 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:98
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:45
std::string username
Optional username for TURN authentication.
Definition room.h:50
std::string url
TURN/STUN server URL (e.g. "stun:stun.l.google.com:19302").
Definition room.h:47
std::string credential
Optional credential (password) for TURN authentication.
Definition room.h:53
Snapshot of core room information.
Definition room_event_types.h:125
Top-level room connection options.
Definition room.h:70
bool single_peer_connection
Enable single peer connection mode.
Definition room.h:83
std::optional< RtcConfig > rtc_config
Optional WebRTC configuration (ICE policy, servers, etc.)
Definition room.h:86
bool dynacast
Enable dynacast (server sends optimal layers depending on subscribers).
Definition room.h:78
std::optional< E2EEOptions > encryption
Optional end-to-end encryption settings.
Definition room.h:89
bool auto_subscribe
If true (default), automatically subscribe to all remote tracks.
Definition room.h:75
WebRTC configuration (ICE, transport, etc.).
Definition room.h:57
int continual_gathering_policy
Continuous or single ICE gathering.
Definition room.h:63
std::vector< IceServer > ice_servers
List of STUN/TURN servers for ICE candidate generation.
Definition room.h:66
int ice_transport_type
ICE transport type (e.g., ALL, RELAY). Maps to proto::IceTransportType.
Definition room.h:59
Options for creating a decoded video frame stream.
Definition video_stream.h:69