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

Represents a locally published data track. More...

#include <local_data_track.h>

Public Member Functions

 LocalDataTrack (const LocalDataTrack &)=delete
 
LocalDataTrackoperator= (const LocalDataTrack &)=delete
 
const DataTrackInfoinfo () const noexcept
 Metadata about this data track.
 
Result< void, LocalDataTrackTryPushErrortryPush (const DataTrackFrame &frame)
 Try to push a frame to all subscribers of this track.
 
Result< void, LocalDataTrackTryPushErrortryPush (std::vector< std::uint8_t > &&payload, std::optional< std::uint64_t > user_timestamp=std::nullopt)
 Try to push a frame to all subscribers of this track.
 
Result< void, LocalDataTrackTryPushErrortryPush (const std::uint8_t *data, std::size_t size, std::optional< std::uint64_t > user_timestamp=std::nullopt)
 Try to push a frame from a borrowed byte buffer.
 
bool isPublished () const
 Whether the track is still published in the room.
 
void unpublishDataTrack ()
 Unpublish this data track from the room.
 

Friends

class LocalParticipant
 

Detailed Description

Represents a locally published data track.

Unlike audio/video tracks, data tracks do not extend the Track base class. They use a separate publish/unpublish lifecycle and carry arbitrary binary frames instead of media.

Created via LocalParticipant::publishDataTrack().

Typical usage:

auto lp = room->localParticipant().lock(); if (!lp) return; // room not connected or already torn down auto result = lp->publishDataTrack("sensor-data"); if (result) { auto dt = result.value(); DataTrackFrame frame; frame.payload = {0x01, 0x02, 0x03}; (void)dt->tryPush(frame); dt->unpublishDataTrack(); }

Member Function Documentation

◆ tryPush() [1/3]

Result< void, LocalDataTrackTryPushError > livekit::LocalDataTrack::tryPush ( const DataTrackFrame frame)

Try to push a frame to all subscribers of this track.

An empty payload succeeds without sending a frame to subscribers.

Parameters
frameThe frame to push.
Returns
Success on delivery acceptance, or a typed error describing why the frame could not be queued.

◆ tryPush() [2/3]

Result< void, LocalDataTrackTryPushError > livekit::LocalDataTrack::tryPush ( const std::uint8_t *  data,
std::size_t  size,
std::optional< std::uint64_t >  user_timestamp = std::nullopt 
)

Try to push a frame from a borrowed byte buffer.

Copies size bytes from data into an FFI request before returning; the SDK does not retain the buffer. An empty payload succeeds without sending a frame to subscribers.

Note
This avoids an intermediate copy when the caller already owns a byte buffer, but it is not a zero-copy send.
Parameters
dataPointer to size payload bytes. Must be non-null when size is non-zero.
sizeNumber of bytes at data. A value of zero is a successful no-op.
user_timestampOptional application-defined timestamp. The unit is caller-defined.
Returns
Success on delivery acceptance, or a typed error describing why the frame could not be queued.

◆ tryPush() [3/3]

Result< void, LocalDataTrackTryPushError > livekit::LocalDataTrack::tryPush ( std::vector< std::uint8_t > &&  payload,
std::optional< std::uint64_t >  user_timestamp = std::nullopt 
)

Try to push a frame to all subscribers of this track.

An empty payload succeeds without sending a frame to subscribers.

Parameters
payloadThe payload to push.
user_timestampOptional application-defined timestamp. The unit is caller-defined.
Returns
Success on delivery acceptance, or a typed error describing why the frame could not be queued.

◆ unpublishDataTrack()

void livekit::LocalDataTrack::unpublishDataTrack ( )

Unpublish this data track from the room.

After this call, tryPush() fails and the track cannot be re-published.


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