20#include <condition_variable>
26#include <unordered_map>
29#include "livekit/ffi_handle.h"
30#include "livekit/local_audio_track.h"
31#include "livekit/local_data_track.h"
32#include "livekit/local_video_track.h"
33#include "livekit/participant.h"
34#include "livekit/room_event_types.h"
35#include "livekit/rpc_error.h"
36#include "livekit/visibility.h"
40struct ParticipantTrackPermission;
44class LocalTrackPublication;
48 std::string request_id;
49 std::string caller_identity;
51 double response_timeout_sec;
57 using PublicationMap = std::unordered_map<std::string, std::shared_ptr<LocalTrackPublication>>;
58 using TrackMap = std::unordered_map<std::string, std::weak_ptr<Track>>;
71 std::unordered_map<std::string, std::string> attributes,
ParticipantKind kind,
88 void publishData(
const std::vector<std::uint8_t>& payload,
bool reliable =
true,
89 const std::vector<std::string>& destination_identities = {},
const std::string& topic = {});
125 void setAttributes(
const std::unordered_map<std::string, std::string>& attributes);
132 const std::vector<ParticipantTrackPermission>& participant_permissions = {});
145 const std::shared_ptr<VideoSource>& source,
154 const std::shared_ptr<AudioSource>& source,
198 std::string
performRpc(
const std::string& destination_identity,
const std::string& method,
const std::string& payload,
199 const std::optional<double>& response_timeout = std::nullopt);
237 const std::string& caller_identity,
const std::string& payload,
238 double response_timeout);
247 mutable TrackMap published_tracks_by_sid_;
249 std::unordered_map<std::string, RpcHandler> rpc_handlers_;
254 struct RpcInvocationState {
256 std::condition_variable cv;
257 int active_invocations = 0;
258 bool shutting_down =
false;
260 std::shared_ptr<RpcInvocationState> rpc_state_ = std::make_shared<RpcInvocationState>();
RAII wrapper for an FFI handle (uintptr_t) coming from Rust.
Definition ffi_handle.h:29
Represents the local participant in a room.
Definition local_participant.h:55
PublicationMap trackPublications() const
Track publications for this participant, keyed by publication SID.
void publishDtmf(int code, const std::string &digit)
Publish a SIP DTMF (phone keypad) tone into the room.
std::shared_ptr< LocalVideoTrack > publishVideoTrack(const std::string &name, const std::shared_ptr< VideoSource > &source, TrackSource track_source)
Create a LocalVideoTrack backed by the given VideoSource, publish it, and return the track.
void unregisterRpcMethod(const std::string &method_name)
Unregister a previously registered RPC method handler.
std::shared_ptr< TrackPublication > findTrackPublication(const std::string &sid) const override
Called by Room events like kTrackMuted.
std::function< std::optional< std::string >(const RpcInvocationData &)> RpcHandler
Type of callback used to handle incoming RPC method invocations.
Definition local_participant.h:68
void publishTrack(const std::shared_ptr< Track > &track, const TrackPublishOptions &options)
Publish a local track to the room.
Result< std::shared_ptr< LocalDataTrack >, PublishDataTrackError > publishDataTrack(const std::string &name)
Publish a data track to the room.
void unpublishTrack(const std::string &track_sid)
Unpublish a track from the room by SID.
std::shared_ptr< LocalAudioTrack > publishAudioTrack(const std::string &name, const std::shared_ptr< AudioSource > &source, TrackSource track_source)
Create a LocalAudioTrack backed by the given AudioSource, publish it, and return the track.
void publishData(const std::vector< std::uint8_t > &payload, bool reliable=true, const std::vector< std::string > &destination_identities={}, const std::string &topic={})
Publish arbitrary data to the room.
void setName(const std::string &name)
Update this participant's display name on the server.
void unpublishDataTrack(const std::shared_ptr< LocalDataTrack > &track)
Unpublish a data track from the room.
void handleRpcMethodInvocation(std::uint64_t invocation_id, const std::string &method, const std::string &request_id, const std::string &caller_identity, const std::string &payload, double response_timeout)
Called by Room when an rpc_method_invocation event is received from the SFU.
void registerRpcMethod(const std::string &method_name, RpcHandler handler)
Register a handler for an incoming RPC method.
void shutdown()
Shutdown the local participant, cleaning up all resources.
void setMetadata(const std::string &metadata)
Update this participant's metadata on the server.
void setAttributes(const std::unordered_map< std::string, std::string > &attributes)
Update this participant's attributes on the server.
void setTrackSubscriptionPermissions(bool allow_all_participants, const std::vector< ParticipantTrackPermission > &participant_permissions={})
Set track subscription permissions for this participant.
std::string performRpc(const std::string &destination_identity, const std::string &method, const std::string &payload, const std::optional< double > &response_timeout=std::nullopt)
Initiate an RPC call to a remote participant.
Base class for local and remote room participants.
Definition participant.h:34
Lightweight success-or-error return type for non-exceptional API failures.
Definition result.h:40
Represents a LiveKit room session.
Definition room.h:98
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
TrackSource
Source category for a published track.
Definition track.h:43
ParticipantKind
Identifies the type of participant connected to a room.
Definition participant.h:31
DisconnectReason
Reason why a participant or room was disconnected.
Definition room_event_types.h:80
Error details returned when publishing a local data track fails.
Definition data_track_error.h:47
Data passed to a registered RPC method handler.
Definition local_participant.h:47
Options for publishing a track to the room.
Definition room_event_types.h:286