|
LiveKit C++ SDK
Real-time audio/video SDK for C++
|
#include <local_participant.h>


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< LocalTrackPublication > | publishTrack (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< TrackPublication > | findTrackPublication (const std::string &sid) const override |
Friends | |
| class | Room |
Represents the local participant in a room.
LocalParticipant, built on top of the participant.h base class.
| 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.
|
overrideprotectedvirtual |
Implements livekit::Participant.
| 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.
| destination_identity | Identity of the destination participant. |
| method | Name of the RPC method to invoke. |
| payload | Request payload to send to the remote handler. |
| response_timeout | Optional timeout in seconds for receiving a response. If not set, the server default timeout (15 seconds) is used. |
| RpcError | If the remote side returns an RPC error, times out, or rejects the request. |
| std::runtime_error | If the underlying FFI handle is invalid or the FFI call fails unexpectedly. |
| 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.
| payload | Raw bytes to send. |
| reliable | Whether to send reliably or not. |
| destination_identities | Optional list of participant identities. |
| topic | Optional topic string. |
Throws std::runtime_error if FFI reports an error (if you wire that up).
| void livekit::LocalParticipant::publishDtmf | ( | int | code, |
| const std::string & | digit | ||
| ) |
Publish SIP DTMF message.
| 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).
| 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.
| method_name | Name of the RPC method to handle. This must match the method name used by remote callers. |
| handler | Callback 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.
| void livekit::LocalParticipant::setTrackSubscriptionPermissions | ( | bool | allow_all_participants, |
| const std::vector< ParticipantTrackPermission > & | participant_permissions = {} |
||
| ) |
Set track subscription permissions for this participant.
| allow_all_participants | If true, all participants may subscribe. |
| participant_permissions | Optional participant-specific permissions. |
|
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.
| 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.
| 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.
| method_name | Name of the RPC method to unregister. If no handler is registered for this name, the call is a no-op. |