|
LiveKit C++ Client SDK v1.10.1
Real-time audio/video/data SDK for C++
|
Represents a locally published data track. More...
#include <local_data_track.h>
Public Member Functions | |
| LocalDataTrack (const LocalDataTrack &)=delete | |
| LocalDataTrack & | operator= (const LocalDataTrack &)=delete |
| const DataTrackInfo & | info () const noexcept |
| Metadata about this data track. | |
| Result< void, LocalDataTrackTryPushError > | tryPush (const DataTrackFrame &frame) |
| Try to push a frame to all subscribers of this track. | |
| Result< void, LocalDataTrackTryPushError > | 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. | |
| Result< void, LocalDataTrackTryPushError > | 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. | |
| bool | isPublished () const |
| Whether the track is still published in the room. | |
| void | unpublishDataTrack () |
| Unpublish this data track from the room. | |
Friends | |
| class | LocalParticipant |
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(); }
| 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.
| frame | The frame to push. |
| 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.
| data | Pointer to size payload bytes. Must be non-null when size is non-zero. |
| size | Number of bytes at data. A value of zero is a successful no-op. |
| user_timestamp | Optional application-defined timestamp. The unit is caller-defined. |
| 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.
| payload | The payload to push. |
| user_timestamp | Optional application-defined timestamp. The unit is caller-defined. |
| void livekit::LocalDataTrack::unpublishDataTrack | ( | ) |
Unpublish this data track from the room.
After this call, tryPush() fails and the track cannot be re-published.