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

Represents the local participant in a room. More...

#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 TrackMap = std::unordered_map< std::string, std::weak_ptr< Track > >
 
using RpcHandler = std::function< std::optional< std::string >(const RpcInvocationData &)>
 Type of callback used to handle incoming RPC method invocations.
 

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)
 
PublicationMap trackPublications () const
 Track publications for this participant, keyed by publication SID.
 
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 publishDtmf (int code, const std::string &digit)
 Publish a SIP DTMF (phone keypad) tone into the room.
 
void setMetadata (const std::string &metadata)
 Update this participant's metadata on the server.
 
void setName (const std::string &name)
 Update this participant's display name 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.
 
void publishTrack (const std::shared_ptr< Track > &track, const TrackPublishOptions &options)
 Publish a local track to the room.
 
std::shared_ptr< LocalVideoTrackpublishVideoTrack (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.
 
std::shared_ptr< LocalAudioTrackpublishAudioTrack (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 unpublishTrack (const std::string &track_sid)
 Unpublish a track from the room by SID.
 
Result< std::shared_ptr< LocalDataTrack >, PublishDataTrackErrorpublishDataTrack (const std::string &name)
 Publish a data track to the room.
 
void unpublishDataTrack (const std::shared_ptr< LocalDataTrack > &track)
 Unpublish a data track from the room.
 
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.
 
void registerRpcMethod (const std::string &method_name, RpcHandler handler)
 Register a handler for an incoming RPC method.
 
void unregisterRpcMethod (const std::string &method_name)
 Unregister a previously registered RPC method handler.
 
- 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
 

Protected Member Functions

void shutdown ()
 Shutdown the local participant, cleaning up all resources.
 
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.
 
std::shared_ptr< TrackPublicationfindTrackPublication (const std::string &sid) const override
 Called by Room events like kTrackMuted.
 

Friends

class Room
 

Detailed Description

Represents the local participant in a room.

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

Called by Room events like kTrackMuted.

Implements livekit::Participant.

◆ handleRpcMethodInvocation()

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

Called by Room when an rpc_method_invocation event is received from the SFU.

This is internal plumbing and not intended to be called directly by SDK users.

◆ performRpc()

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

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.

◆ publishAudioTrack()

std::shared_ptr< LocalAudioTrack > livekit::LocalParticipant::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.

The caller retains ownership of source and should use it directly for frame capture on the audio thread.

◆ 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.
Exceptions
std::runtime_errorif FFI reports an error (if you wire that up).

◆ publishDataTrack()

Result< std::shared_ptr< LocalDataTrack >, PublishDataTrackError > livekit::LocalParticipant::publishDataTrack ( const std::string &  name)

Publish a data track to the room.

Data tracks carry arbitrary binary frames and are independent of the audio/video track hierarchy. The returned LocalDataTrack can push frames via tryPush() and be unpublished via LocalDataTrack::unpublishDataTrack() or LocalParticipant::unpublishDataTrack().

Parameters
nameUnique track name visible to other participants.
Returns
The published track on success, or a typed error describing why publication failed.

◆ publishDtmf()

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

Publish a SIP DTMF (phone keypad) tone into the room.

Only meaningful when a SIP trunk is bridging a phone call into the room. See SipDtmfData for background on SIP and DTMF.

Parameters
codeDTMF code (0-15).
digitHuman-readable digit string (e.g. "5", "#").

◆ publishTrack()

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

Publish a local track to the room.

Exceptions
std::runtime_erroron error (e.g. publish failure).

◆ publishVideoTrack()

std::shared_ptr< LocalVideoTrack > livekit::LocalParticipant::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.

The caller retains ownership of source and should use it directly for frame capture on the video thread.

◆ 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.

◆ setAttributes()

void livekit::LocalParticipant::setAttributes ( const std::unordered_map< std::string, std::string > &  attributes)

Update this participant's attributes on the server.

Sends an FFI request to the LiveKit server to replace the attribute map for the local participant. Other participants will be notified via onParticipantAttributesChanged.

Note
this requires canUpdateOwnMetadata permission.

◆ setMetadata()

void livekit::LocalParticipant::setMetadata ( const std::string &  metadata)

Update this participant's metadata on the server.

Sends an FFI request to the LiveKit server to change the metadata associated with the local participant. Other participants will be notified via onParticipantMetadataChanged.

Note
this requires canUpdateOwnMetadata permission.

◆ setName()

void livekit::LocalParticipant::setName ( const std::string &  name)

Update this participant's display name on the server.

Sends an FFI request to the LiveKit server to change the name associated with the local participant. Other participants will be notified via onParticipantNameChanged.

Note
this requires canUpdateOwnMetadata permission.

◆ 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.

◆ trackPublications()

PublicationMap livekit::LocalParticipant::trackPublications ( ) const

Track publications for this participant, keyed by publication SID.

Built on each call from published local tracks (see publishTrack). Expired track handles are removed from the internal map while building.

◆ unpublishDataTrack()

void livekit::LocalParticipant::unpublishDataTrack ( const std::shared_ptr< LocalDataTrack > &  track)

Unpublish a data track from the room.

Delegates to LocalDataTrack::unpublishDataTrack(). After this call, tryPush() on the track will fail and the track cannot be re-published.

Parameters
trackThe data track to unpublish. Null is ignored.

◆ 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: