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

#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)
 
Result< void, LocalDataTrackTryPushErrortryPush (std::vector< std::uint8_t > &&payload, std::optional< std::uint64_t > user_timestamp=std::nullopt)
 
bool isPublished () const
 Whether the track is still published in the room.
 
void unpublishDataTrack ()
 

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(); 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/2]

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

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

Returns
success on delivery acceptance, or a typed error describing why the frame could not be queued.

◆ tryPush() [2/2]

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.

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: