19#include <condition_variable>
30#include "livekit/visibility.h"
34class LocalParticipant;
56 std::optional<std::size_t>
size;
103 void onChunkUpdate(
const std::string& text);
107 void onStreamClose(
const std::map<std::string, std::string>& trailer_attrs);
112 std::deque<std::string> queue_;
113 bool closed_ =
false;
116 std::condition_variable cv_;
139 void onChunkUpdate(
const std::vector<std::uint8_t>& bytes);
143 void onStreamClose(
const std::map<std::string, std::string>& trailer_attrs);
147 std::deque<std::vector<std::uint8_t>> queue_;
148 bool closed_ =
false;
151 std::condition_variable cv_;
161 const std::string&
streamId() const noexcept {
return stream_id_; }
164 const std::string&
topic() const noexcept {
return topic_; }
167 const std::string&
mimeType() const noexcept {
return mime_type_; }
170 std::int64_t
timestampMs() const noexcept {
return timestamp_ms_; }
177 void close(
const std::string& reason =
"",
const std::map<std::string, std::string>& attributes = {});
181 std::map<std::string, std::string> attributes = {}, std::string stream_id =
"",
182 std::optional<std::size_t> total_size = std::nullopt, std::string mime_type =
"",
183 std::vector<std::string> destination_identities = {}, std::string sender_identity =
"");
185 enum class StreamKind { kUnknown, kText, kByte };
187 LocalParticipant& local_participant_;
190 std::string stream_id_;
191 std::string mime_type_;
193 std::int64_t timestamp_ms_ = 0;
194 std::optional<std::size_t> total_size_;
195 std::map<std::string, std::string> attributes_;
196 std::vector<std::string> destination_identities_;
197 std::string sender_identity_;
199 bool closed_ =
false;
200 bool header_sent_ =
false;
201 std::uint64_t next_chunk_index_ = 0;
202 StreamKind kind_ = StreamKind::kUnknown;
203 std::string reply_to_id_;
204 std::string byte_name_;
212 void sendChunk(
const std::vector<std::uint8_t>& content);
216 void sendTrailer(
const std::string& reason,
const std::map<std::string, std::string>& attributes);
223 const std::map<std::string, std::string>& attributes = {},
const std::string& stream_id =
"",
224 std::optional<std::size_t> total_size = std::nullopt,
const std::string& reply_to_id =
"",
225 const std::vector<std::string>& destination_identities = {},
226 const std::string& sender_identity =
"");
231 void write(
const std::string& text);
238 std::mutex write_mutex_;
245 const std::map<std::string, std::string>& attributes = {},
const std::string& stream_id =
"",
246 std::optional<std::size_t> total_size = std::nullopt,
247 const std::string& mime_type =
"application/octet-stream",
248 const std::vector<std::string>& destination_identities = {},
249 const std::string& sender_identity =
"");
254 void write(
const std::vector<std::uint8_t>& data);
261 std::mutex write_mutex_;
270 std::function<void(std::shared_ptr<TextStreamReader>,
const std::string& participant_identity)>;
278 std::function<void(std::shared_ptr<ByteStreamReader>,
const std::string& participant_identity)>;
Base class for sending data streams.
Definition data_stream.h:156
void close(const std::string &reason="", const std::map< std::string, std::string > &attributes={})
Close the stream with optional reason and attributes.
void ensureHeaderSent()
Ensure the header has been sent once.
void sendChunk(const std::vector< std::uint8_t > &content)
Send a raw chunk of bytes.
std::int64_t timestampMs() const noexcept
Timestamp (ms) when the stream was created.
Definition data_stream.h:170
const std::string & streamId() const noexcept
Stream id assigned to this writer.
Definition data_stream.h:161
const std::string & topic() const noexcept
Topic of this stream.
Definition data_stream.h:164
const std::string & mimeType() const noexcept
MIME type for this stream.
Definition data_stream.h:167
bool isClosed() const noexcept
Whether the stream has been closed.
Definition data_stream.h:173
void sendTrailer(const std::string &reason, const std::map< std::string, std::string > &attributes)
Send the trailer with given reason and attributes.
Reader for incoming byte streams.
Definition data_stream.h:120
ByteStreamReader(ByteStreamInfo info)
Construct a reader from initial stream metadata.
bool readNext(std::vector< std::uint8_t > &out)
Blocking read of next byte chunk.
const ByteStreamInfo & info() const noexcept
Metadata associated with this stream.
Definition data_stream.h:133
Writer for outgoing byte streams.
Definition data_stream.h:242
void write(const std::vector< std::uint8_t > &data)
Write binary data to the stream.
const ByteStreamInfo & info() const noexcept
Metadata associated with this stream.
Definition data_stream.h:257
Represents the local participant in a room.
Definition local_participant.h:55
Represents a LiveKit room session.
Definition room.h:98
Reader for incoming text streams.
Definition data_stream.h:80
bool readNext(std::string &out)
Blocking read of next text chunk.
const TextStreamInfo & info() const noexcept
Metadata associated with this stream.
Definition data_stream.h:97
TextStreamReader(TextStreamInfo info)
Construct a reader from initial stream metadata.
std::string readAll()
Convenience: read entire stream into a single string.
Writer for outgoing text streams.
Definition data_stream.h:220
const TextStreamInfo & info() const noexcept
Metadata associated with this stream.
Definition data_stream.h:234
void write(const std::string &text)
Write a UTF-8 string to the stream.
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
constexpr std::size_t kStreamChunkSize
Chunk size for data streams (matches Python STREAM_CHUNK_SIZE).
Definition data_stream.h:39
std::function< void(std::shared_ptr< ByteStreamReader >, const std::string &participant_identity)> ByteStreamHandler
Callback invoked when a new incoming byte stream is opened.
Definition data_stream.h:278
std::function< void(std::shared_ptr< TextStreamReader >, const std::string &participant_identity)> TextStreamHandler
Callback invoked when a new incoming text stream is opened.
Definition data_stream.h:270
Base metadata for any stream (text or bytes).
Definition data_stream.h:42
std::string topic
Application-defined topic name.
Definition data_stream.h:50
std::string mime_type
MIME type of the stream (e.g. "text/plain", "application/octet-stream").
Definition data_stream.h:47
std::map< std::string, std::string > attributes
Arbitrary key–value attributes attached to the stream.
Definition data_stream.h:59
std::int64_t timestamp
Timestamp in milliseconds when the stream was created.
Definition data_stream.h:53
std::optional< std::size_t > size
Total size of the stream in bytes, if known.
Definition data_stream.h:56
std::string stream_id
Unique identifier for this stream.
Definition data_stream.h:44
Metadata for a byte stream.
Definition data_stream.h:69
std::string name
Optional name of the binary object (e.g. filename).
Definition data_stream.h:71
Metadata for a text stream.
Definition data_stream.h:63
std::vector< std::string > attachments
IDs of any attached streams (for replies / threads).
Definition data_stream.h:65