1717#pragma once
1818
1919#include " livekit/data_frame.h"
20+ #include " livekit/data_track_error.h"
2021#include " livekit/data_track_info.h"
2122#include " livekit/ffi_handle.h"
23+ #include " livekit/result.h"
2224
2325#include < cstddef>
2426#include < memory>
@@ -44,11 +46,14 @@ class OwnedLocalDataTrack;
4446 * Typical usage:
4547 *
4648 * auto lp = room->localParticipant();
47- * auto dt = lp->publishDataTrack("sensor-data");
48- * DataFrame frame;
49- * frame.payload = {0x01, 0x02, 0x03};
50- * dt->tryPush(frame);
51- * dt->unpublishDataTrack();
49+ * auto result = lp->publishDataTrack("sensor-data");
50+ * if (result) {
51+ * auto dt = result.value();
52+ * DataFrame frame;
53+ * frame.payload = {0x01, 0x02, 0x03};
54+ * (void)dt->tryPush(frame);
55+ * dt->unpublishDataTrack();
56+ * }
5257 */
5358class LocalDataTrack {
5459public:
@@ -63,29 +68,32 @@ class LocalDataTrack {
6368 /* *
6469 * Try to push a frame to all subscribers of this track.
6570 *
66- * @return true on success, false if the push failed (e.g. back-pressure
67- * or the track has been unpublished) .
71+ * @return success on delivery acceptance, or a typed error describing why
72+ * the frame could not be queued .
6873 */
69- bool tryPush (const DataFrame &frame);
74+ Result< void , DataTrackError> tryPush (const DataFrame &frame);
7075
7176 /* *
7277 * Try to push a frame to all subscribers of this track.
7378 *
74- * @return true on success, false if the push failed (e.g. back-pressure
75- * or the track has been unpublished) .
79+ * @return success on delivery acceptance, or a typed error describing why
80+ * the frame could not be queued .
7681 */
77- bool tryPush (const std::vector<std::uint8_t > &payload,
78- std::optional<std::uint64_t > user_timestamp = std::nullopt );
79- bool tryPush (std::vector<std::uint8_t > &&payload,
80- std::optional<std::uint64_t > user_timestamp = std::nullopt );
82+ Result<void , DataTrackError>
83+ tryPush (const std::vector<std::uint8_t > &payload,
84+ std::optional<std::uint64_t > user_timestamp = std::nullopt );
85+ Result<void , DataTrackError>
86+ tryPush (std::vector<std::uint8_t > &&payload,
87+ std::optional<std::uint64_t > user_timestamp = std::nullopt );
8188 /* *
8289 * Try to push a frame to all subscribers of this track.
8390 *
84- * @return true on success, false if the push failed (e.g. back-pressure
85- * or the track has been unpublished) .
91+ * @return success on delivery acceptance, or a typed error describing why
92+ * the frame could not be queued .
8693 */
87- bool tryPush (const std::uint8_t *data, std::size_t size,
88- std::optional<std::uint64_t > user_timestamp = std::nullopt );
94+ Result<void , DataTrackError>
95+ tryPush (const std::uint8_t *data, std::size_t size,
96+ std::optional<std::uint64_t > user_timestamp = std::nullopt );
8997
9098 // / Whether the track is still published in the room.
9199 bool isPublished () const ;
0 commit comments