LiveKit C++ SDK
Real-time audio/video SDK for C++
Loading...
Searching...
No Matches
livekit::LocalParticipant Class Reference

#include <local_participant.h>

Inheritance diagram for livekit::LocalParticipant:
Collaboration diagram for livekit::LocalParticipant:

Public Types

using PublicationMap = std::unordered_map< std::string, std::shared_ptr< LocalTrackPublication > >
 
using RpcHandler = std::function< std::optional< std::string >(const RpcInvocationData &)>
 

Public Member Functions

 LocalParticipant (FfiHandle handle, std::string sid, std::string name, std::string identity, std::string metadata, std::unordered_map< std::string, std::string > attributes, ParticipantKind kind, DisconnectReason reason)
 
const PublicationMap & trackPublications () const noexcept
 Track publications associated with this participant, keyed by track SID.
 
void publishData (const std::vector< std::uint8_t > &payload, bool reliable=true, const std::vector< std::string > &destination_identities={}, const std::string &topic={})
 
void publishDtmf (int code, const std::string &digit)
 
void setMetadata (const std::string &metadata)
 
void setName (const std::string &name)
 
void setAttributes (const std::unordered_map< std::string, std::string > &attributes)
 
void setTrackSubscriptionPermissions (bool allow_all_participants, const std::vector< ParticipantTrackPermission > &participant_permissions={})
 
std::shared_ptr< LocalTrackPublicationpublishTrack (const std::shared_ptr< Track > &track, const TrackPublishOptions &options)
 
void unpublishTrack (const std::string &track_sid)
 
std::string performRpc (const std::string &destination_identity, const std::string &method, const std::string &payload, std::optional< double > response_timeout=std::nullopt)
 
void registerRpcMethod (const std::string &method_name, RpcHandler handler)
 
void unregisterRpcMethod (const std::string &method_name)
 
- Public Member Functions inherited from livekit::Participant
 Participant (FfiHandle handle, std::string sid, std::string name, std::string identity, std::string metadata, std::unordered_map< std::string, std::string > attributes, ParticipantKind kind, DisconnectReason reason)
 
const std::string & sid () const noexcept
 
const std::string & name () const noexcept
 
const std::string & identity () const noexcept
 
const std::string & metadata () const noexcept
 
const std::unordered_map< std::string, std::string > & attributes () const noexcept
 
ParticipantKind kind () const noexcept
 
DisconnectReason disconnectReason () const noexcept
 
uintptr_t ffiHandleId () const noexcept
 
void set_name (std::string name) noexcept
 
void set_metadata (std::string metadata) noexcept
 
void set_attributes (std::unordered_map< std::string, std::string > attrs) noexcept
 
void set_attribute (const std::string &key, const std::string &value)
 
void remove_attribute (const std::string &key)
 
void set_kind (ParticipantKind kind) noexcept
 
void set_disconnect_reason (DisconnectReason reason) noexcept
 

Protected Member Functions

void shutdown ()
 
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)
 
std::shared_ptr< TrackPublicationfindTrackPublication (const std::string &sid) const override
 

Friends

class Room
 

Detailed Description

Represents the local participant in a room.

LocalParticipant, built on top of the participant.h base class.

Member Typedef Documentation

◆ RpcHandler

using livekit::LocalParticipant::RpcHandler = std::function<std::optional<std::string>(const RpcInvocationData &)>

Type of callback used to handle incoming RPC method invocations.

The handler receives an RpcInvocationData describing the incoming call and may return an optional response payload. To signal an error to the remote caller, throw an RpcError; it will be serialized and forwarded.

Returning std::nullopt means "no payload" and results in an empty response body being sent back to the caller.

Member Function Documentation

◆ findTrackPublication()

std::shared_ptr< TrackPublication > livekit::LocalParticipant::findTrackPublication ( const std::string &  sid) const
overrideprotectedvirtual

Implements livekit::Participant.

◆ performRpc()

std::string livekit::LocalParticipant::performRpc ( const std::string &  destination_identity,
const std::string &  method,
const std::string &  payload,
std::optional< double >  response_timeout = std::nullopt 
)

Initiate an RPC call to a remote participant.

Parameters
destination_identityIdentity of the destination participant.
methodName of the RPC method to invoke.
payloadRequest payload to send to the remote handler.
response_timeoutOptional timeout in seconds for receiving a response. If not set, the server default timeout (15 seconds) is used.
Returns
The response payload returned by the remote handler.
Exceptions
RpcErrorIf the remote side returns an RPC error, times out, or rejects the request.
std::runtime_errorIf the underlying FFI handle is invalid or the FFI call fails unexpectedly.

◆ publishData()

void livekit::LocalParticipant::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.

Parameters
payloadRaw bytes to send.
reliableWhether to send reliably or not.
destination_identitiesOptional list of participant identities.
topicOptional topic string.

Throws std::runtime_error if FFI reports an error (if you wire that up).

◆ publishDtmf()

void livekit::LocalParticipant::publishDtmf ( int  code,
const std::string &  digit 
)

Publish SIP DTMF message.

◆ publishTrack()

std::shared_ptr< LocalTrackPublication > livekit::LocalParticipant::publishTrack ( const std::shared_ptr< Track > &  track,
const TrackPublishOptions options 
)

Publish a local track to the room.

Throws std::runtime_error on error (e.g. publish failure).

◆ registerRpcMethod()

void livekit::LocalParticipant::registerRpcMethod ( const std::string &  method_name,
RpcHandler  handler 
)

Register a handler for an incoming RPC method.

Once registered, the provided handler will be invoked whenever a remote participant calls the given method name on this LocalParticipant.

Parameters
method_nameName of the RPC method to handle. This must match the method name used by remote callers.
handlerCallback to execute when an invocation is received. The handler may return an optional response payload or throw an RpcError to signal failure.

If a handler is already registered for the same method_name, it will be replaced by the new handler.

◆ setTrackSubscriptionPermissions()

void livekit::LocalParticipant::setTrackSubscriptionPermissions ( bool  allow_all_participants,
const std::vector< ParticipantTrackPermission > &  participant_permissions = {} 
)

Set track subscription permissions for this participant.

Parameters
allow_all_participantsIf true, all participants may subscribe.
participant_permissionsOptional participant-specific permissions.

◆ shutdown()

void livekit::LocalParticipant::shutdown ( )
protected

Shutdown the local participant, cleaning up all resources.

This unregisters all RPC handlers and prepares the participant for destruction. Called by Room during its destruction sequence.

◆ unpublishTrack()

void livekit::LocalParticipant::unpublishTrack ( const std::string &  track_sid)

Unpublish a track from the room by SID.

If the publication exists in the local map, it is removed.

◆ unregisterRpcMethod()

void livekit::LocalParticipant::unregisterRpcMethod ( const std::string &  method_name)

Unregister a previously registered RPC method handler.

After this call, invocations for the given method_name will no longer be dispatched to a local handler and will instead result in an "unsupported method" error being returned to the caller.

Parameters
method_nameName of the RPC method to unregister. If no handler is registered for this name, the call is a no-op.

The documentation for this class was generated from the following file: