Repository navigation
Conversation
…Bytes TextStreamWriter / ByteStreamWriter now open an FFI writer (text/byte_stream_open) and send through text/byte_stream_write and *_stream_close instead of hand-built header/chunk/trailer packets. Rust does the chunking and UTF-8 splitting. - LocalParticipant::streamText / streamBytes return an already-open writer (blocking until the open callback, throwing DataStreamError on failure). The public writer constructors keep working but are deprecated; they open lazily on the first write or close, as the header did before. - write() and close() share one mutex and each waits for its FFI callback, so a close never overtakes an in-flight write (python-sdks#879); this also fixes close() not taking the write lock. - A LocalParticipant tracks its writers in a registry shared with them. On disconnect (or participant destruction) every writer is closed and its handle dropped, so later write/close throw DataStreamError instead of reaching an FFI session that would panic. - A writer destroyed without close() sends a non-waiting FFI close. Rust's writer only sends its drop-time trailer from a Tokio thread, so a plain handle drop from C++ left receivers waiting forever. - kStreamChunkSize and the protected ensureHeaderSent / sendChunk / sendTrailer helpers are deprecated and reimplemented on the new path. - Removed FfiClient::sendStream*Async, splitUtf8 and the now-unused header/chunk/trailer converters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1egoman
commented
Nov 20, 2026
| /// @param reply_to_id Id of the stream this one replies to, or empty. | ||
| /// @param destination_identities Recipients; empty for everyone. | ||
| /// @param sender_identity Identity to send as; defaults to the local participant. | ||
| [[deprecated("Constructing TextStreamWriter directly is deprecated; use LocalParticipant::streamText instead")]] |
Author
There was a problem hiding this comment.
Open question: this deprecates constructing TextStreamWriter / ByteStreamWriter directly in favour of LocalParticipant::streamText / streamBytes, to match the other SDKs. The constructors keep working. Is deprecating them the right call, or should both stay first-class?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #321; review that one first. This PR's base is #321's branch, so the diff shows only the writer port.
Second half of the data streams port.
TextStreamWriter/ByteStreamWriternow use FFI writer handles (text/byte_stream_open,*_stream_write,*_stream_close) instead of hand-built header, chunk and trailer packets. Rust does the chunking and UTF-8 splitting. After #321 the old writers still worked (FFI readers accept v1 framing), so this PR is cleanup and parity rather than a bug fix. It does fix the writer races and disconnect handling described below.What changes
LocalParticipant::streamText/streamBytes. They return an already-open writer, blocking until the open callback arrives, and throwDataStreamErroron failure. This matches the other SDKs'stream_text/stream_bytes.write()/close()as the header did before. Each carries both[[deprecated]]and/// @deprecated, per AGENTS.md.write()andclose()share one mutex, and each waits for its FFI callback, soclose()never overtakes an in-flight write (python-sdks#879). This also fixesclose()previously not taking the write lock.LocalParticipanttracks its writers in a registry it shares with them. On disconnect, or when the participant is destroyed, every writer is closed and its handle dropped. Laterwrite()/close()throwDataStreamErrorinstead of reaching an FFI session that would panic (the C++ SDK turns an FFI panic intoSIGTERM). Because the registry is shared, a writer that outlives its participant never touches the dead participant. Python still has this bug: a disposed writer there looks usable.close(). The writer sends a non-waiting FFI close. Rust'sRawStreamonly sends its drop-time trailer when dropped on a Tokio thread (Handle::try_current()). A handle drop from C++ runs on a C++ thread, so the trailer was silently skipped and receivers waited forever. I confirmed this by swapping the close for a plain drop:WriterDestroyedWithoutCloseEndsStreamthen hangs.kStreamChunkSizeand the protectedensureHeaderSent/sendChunk/sendTrailerhelpers are deprecated; it's source API for subclasses. The helpers are reimplemented on the new path (open, write, close). The protected data members stay.streamId()works before open. Texttotal_sizeis documented as local only, because the FFI can't transmit it.FfiClient::sendStream*Asyncand their unit tests,splitUtf8, and the now-unused header, chunk and trailer converters. The publicDataStream*event structs andRoomDelegatecallbacks are kept.API compatibility: source compatible. Existing code compiles unchanged, with deprecation warnings. ABI changes: writer class layout, and
closed_is nowstd::atomic<bool>.Testing
All runs were local on macOS arm64, against
livekit-server --devwith sourced tokens.FfiClientwriter helpers throw when the FFI isn't initializedDataStreamE2ETest: 24/24 pass. Existing tests moved to the factories. New tests:total_lengthclose()racing an in-flight 2 MB write (no data lost)close()mainon this machine (data track schema ×3, server-deleted room, platform audio device); see Data streams: receive via FFI readers; add sendText / sendBytes / sendFile #321.RoomStressTest/RoomServerStressTestpass 6/6.livekit1.3.0) got the C++streamText(two writes, 40,012 bytes),sendText(50 KB) andstreamBytes(100,000 bytes) intact.Not in this PR
cpp-example-collection/simple_data_streammove tostreamText/streamBytesis deferred and will be a follow-up.🤖 Generated with Claude Code