Skip to content

Data streams v2 (3/5): add sendText / sendBytes / sendFile - #331

Draft
1egoman wants to merge 3 commits into
ds/2-receive-fixfrom
ds/3-oneshot-sends
Draft

1egoman wants to merge 3 commits into
ds/2-receive-fixfrom
ds/3-oneshot-sends

Conversation

@1egoman

@1egoman 1egoman commented Nov 30, 2026 •

Copy link
Copy Markdown

Part 3 of 5 of the data streams v2 stack. Merge in order; each part is mergeable on its own.

  1. Data streams v2 (1/5): conformance test harness #329: Conformance test harness
  2. Data streams v2 (2/5): read incoming data streams through FFI readers #330: Read incoming data streams through FFI readers (fixes receiving from other SDKs)
  3. Data streams v2 (3/5): add sendText / sendBytes / sendFile #331: Add sendText / sendBytes / sendFile 👈 this PR
  4. Data streams v2 (4/5): add ByteStreamReader::writeToFile and a receive size limit #332: Add ByteStreamReader::writeToFile and a receive size limit
  5. Data streams v2 (5/5): move writers to FFI writer handles; add streamText / streamBytes #333: Move writers to FFI writer handles; add streamText / streamBytes

This stack replaces #321, #322 and #325 (same code, reordered so each step stands on its own).

Adds one-shot sends, the Python-style API the other SDKs have:

StreamTextOptions options;
options.topic = "chat";
TextStreamInfo info = room.localParticipant().lock()->sendText("hello", options);

API

  • LocalParticipant::sendText / sendBytes / sendFile go through the FFI's send_text / send_bytes / send_file.
    • The Rust core frames, chunks and compresses, so when every recipient supports it they send v2 streams (one packet when small; deflate when that is smaller), like the other SDKs.
    • They block until the send completes, return the stream's info, and throw DataStreamError on failure.
  • StreamTextOptions / StreamByteOptions carry:
    • topic, attributes, destinations and stream id;
    • reply-to and attachments (text);
    • name, MIME type and total length (bytes);
    • compress (default true) and sender_identity.
    • total_length and the "incremental writers ignore compress" notes apply to streamText / streamBytes, which arrive in part 5.
  • TextStreamOperationType, plus operation_type / version / generated on StreamTextOptions and TextStreamInfo.
    • Agents mark transcriptions as generated; chat apps use the operation type for edits and reactions.
    • Only non-default values go on the wire.
  • The FFI panics if a stream is sent after the room session is gone, so sends throw DataStreamError once the room has disconnected instead of reaching it.

TextStreamInfo gains members, so code built against older headers must be recompiled.

Nothing gets more broken: the v2 packets these send are what part 2 taught the C++ receive path to read.

Tests

File Added here
test_data_stream_conformance_send.cpp 20 one-shot send tests that check the raw packets: inline vs multi-packet, compressed vs not, compress = false, attachments, empty text, sendFile splitting at the 15000-byte MTU, empty and missing files, oversized attributes, broadcast to an empty room
test_data_stream_conformance_text_header.cpp operation type / version / generated in both directions, and the defaults
test_data_streams.cpp round trips for small, large/compressed, uncompressed and Unicode text, bytes, files; sending after disconnect throws
test_data_stream.cpp (unit) option conversion and sends without an initialized SDK
Rust outgoing/manager.rs tests covered here
Rust test C++ test (DataStreamSendConformanceTest.*)
v2_short_compressible_text_inlines_compressed SendTextShortCompressibleInlines (partial: compression flag not visible)
v2_short_incompressible_text_inlines_raw SendTextShortIncompressibleInlines
v2_large_highly_compressible_text_still_inlines SendTextLargeHighlyCompressibleStillInlines
v2_somewhat_compressible_text_is_compressed_multipacket SendTextSomewhatCompressibleIsCompressedMultipacket
v2_compress_false_short_inlines_raw SendTextCompressFalseShortInlines (partial)
v2_compress_false_large_is_uncompressed_multipacket SendTextCompressFalseLargeIsUncompressedMultipacket
v2_send_text_with_attachments_never_inlines SendTextWithAttachmentsNeverInlines
v2_empty_text_sends_single_inline_packet SendTextEmptyIsSingleInlinePacket
oversized_attributes_on_chunked_path_errors SendTextOversizedAttributesThrows
enforce_header_size_rejects_large_header SendTextOversizedAttributesThrows
v2_send_bytes_short_incompressible_inlines_raw SendBytesShortIncompressibleInlines
v2_send_bytes_short_compressible_inlines_compressed SendBytesShortCompressibleInlinesAndReturnsInfo
v2_send_bytes_large_highly_compressible_inlines SendBytesLargeHighlyCompressibleInlines
v2_send_bytes_somewhat_compressible_is_compressed_multipacket SendBytesSomewhatCompressibleIsCompressedMultipacket
v2_send_bytes_compress_false_large_is_uncompressed_multipacket SendBytesCompressFalseLargeIsUncompressedMultipacket
send_file_never_inlines_and_compresses_when_eligible SendFileNeverInlinesAndCompresses
send_file_uncompressed_splits_at_mtu SendFileUncompressedSplitsAtMtu
send_file_incompressible_compressed_expands SendFileIncompressibleCompressedExpands
send_file_empty_file SendFileEmptyFile
v2_broadcast_all_capable_inlines_compressed SendTextShortCompressibleInlines (broadcast; partial)
empty_room_broadcast_is_v2_eligible BroadcastToEmptyRoomSucceeds (partial: nobody to inspect)

Not portable end to end:

  • Pre-v2 recipients and recipients without compression: every FFI client advertises both.
  • Progress: there is no FFI progress API.
  • Transport batching: internal to Rust.

Targeting, sender_identity and the writer tests come in part 5.

Follow-ups from the #325 review

  • sendFile doesn't infer a MIME type from the file name. The Rust core sends application/octet-stream. That should be fixed once in Rust's send_file, so every SDK gets it. For now the docs here say what is sent. Earlier report: Data streams v2 client-sdk-flutter#1166.
  • A send racing disconnect() can still reach Rust after the room session is gone, and Rust panics. The C++ check narrows the window but can't close it. The fix is for the Rust data stream entry points to return a "not connected" error.

Verification (local, macOS arm64, livekit-server --dev)

  • Unit tests: 381/381.
  • Full integration suite: 137 pass, 3 fail (see below), 1 skip. All 70 data stream tests pass.
  • Python livekit 1.3.0, both directions, 3/3 runs intact:
    • Python send_text → C++;
    • C++ sendText (short and 50 KB) and sendBytes (100 KB) → Python.
  • clang-tidy: no warnings beyond part 2's.
  • Every commit builds and passes the unit tests.
  • Formatting: clang-format is clean on all changed files. Docs build OK. The release symbol leak check is OK.
  • The 3 failing integration tests are the DataTrackE2ETest schema tests (DefineAndGetSchema, DefineAndGetCustomSchemaEncoding, DefineDuplicateSchemaFails). They fail on main on this machine too, and the 1 skip is the token-server test.
  • Windows and Linux are covered only by CI.

🤖 Generated with Claude Code

1egoman and others added 3 commits November 30, 2026 20:44
One-shot sends through the FFI's send_text / send_bytes / send_file. The
SDK core frames, chunks and compresses them, so they use data streams v2
(single-packet delivery and deflate compression) when every recipient
supports it, like the other LiveKit SDKs. They block until the send
completes, return the sent stream's info, and throw DataStreamError on
failure.

- StreamTextOptions / StreamByteOptions carry topic, attributes,
  destinations, stream id, reply-to and attachments (text), name, MIME
  type and total length (bytes), compress (default true) and
  sender_identity.
- sendFile names the stream after the file's basename unless a name is
  given. The SDK core does not infer a MIME type from the file name, so
  the docs say it sends application/octet-stream unless one is set.
- The FFI panics if a stream is sent after the room session is gone, so
  sends throw DataStreamError once the room has disconnected instead of
  reaching it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Text stream headers carry an operation type (create, update, delete,
reaction), an optional message version and a generated flag; agents, for
example, mark transcriptions as generated. The C++ SDK dropped them.

- TextStreamOperationType, plus operation_type / version / generated on
  StreamTextOptions and TextStreamInfo.
- Only non-default values are put on the wire, matching the other SDKs.
- Tests: remote header fields surface on TextStreamInfo, sendText puts
  them on the wire, and the defaults are create, unversioned, not
  generated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ports the Rust outgoing-manager tests that sendText / sendBytes / sendFile
can reproduce, checking the raw packets the receiving room gets:

- Inline (single packet) vs multi-packet, and compressed vs not, for
  short, large-but-compressible, somewhat compressible and incompressible
  payloads, with and without compress.
- Text with attachments never inlines; empty text is one inline packet.
- sendFile never inlines, compresses when eligible, splits uncompressed
  files at the 15000-byte MTU, and handles empty and missing files.
- Oversized attributes throw, and a broadcast to an empty room succeeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@1egoman

1egoman commented Nov 30, 2026

Copy link
Copy Markdown
Author

CI for this branch (manually dispatched, since ci.yml only runs on PRs into main): https://github.com/livekit/client-sdk-cpp/actions/runs/46380673255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant