20#include <condition_variable>
27#include <unordered_map>
30#include "livekit/data_track_error.h"
31#include "livekit/data_track_options.h"
32#include "livekit/data_track_schema.h"
33#include "livekit/ffi_handle.h"
34#include "livekit/local_audio_track.h"
35#include "livekit/local_data_track.h"
36#include "livekit/local_video_track.h"
37#include "livekit/participant.h"
38#include "livekit/result.h"
39#include "livekit/room_event_types.h"
40#include "livekit/rpc_error.h"
41#include "livekit/visibility.h"
45struct ParticipantTrackPermission;
49class LocalTrackPublication;
53 std::string request_id;
54 std::string caller_identity;
56 double response_timeout_sec;
62 using PublicationMap = std::unordered_map<std::string, std::shared_ptr<LocalTrackPublication>>;
63 using TrackMap = std::unordered_map<std::string, std::weak_ptr<Track>>;
76 std::unordered_map<std::string, std::string> attributes,
ParticipantKind kind,
93 void publishData(
const std::vector<std::uint8_t>& payload,
bool reliable =
true,
94 const std::vector<std::string>& destination_identities = {},
const std::string& topic = {});
130 void setAttributes(
const std::unordered_map<std::string, std::string>& attributes);
137 const std::vector<ParticipantTrackPermission>& participant_permissions = {});
150 const std::shared_ptr<VideoSource>& source,
159 const std::shared_ptr<AudioSource>& source,
246 std::string
performRpc(
const std::string& destination_identity,
const std::string& method,
const std::string& payload,
247 const std::optional<double>& response_timeout = std::nullopt);
285 const std::string& caller_identity,
const std::string& payload,
286 double response_timeout);
295 mutable TrackMap published_tracks_by_sid_;
297 std::unordered_map<std::string, RpcHandler> rpc_handlers_;
302 struct RpcInvocationState {
304 std::condition_variable cv;
305 int active_invocations = 0;
306 bool shutting_down =
false;
308 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:60
bool defineSchema(const DataTrackSchemaId &id, const std::string &definition)
Store the definition of a data track schema.
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::optional< std::string > getSchema(const DataTrackSchemaId &id, const std::string &participant_identity)
Retrieve the definition for a data track schema.
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:73
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.
Result< std::shared_ptr< LocalDataTrack >, PublishDataTrackError > publishDataTrack(const DataTrackPublishOptions &options)
Publish a data track to the room with explicit options.
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:142
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
TrackSource
Source category for a published track.
Definition track.h:42
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
Options for publishing a data track.
Definition data_track_options.h:30
Uniquely identifies a data track schema.
Definition data_track_schema.h:197
Error details returned when publishing a local data track fails.
Definition data_track_error.h:48
Data passed to a registered RPC method handler.
Definition local_participant.h:52
Options for publishing a track to the room.
Definition room_event_types.h:324