Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9c4a51d
refactor: rename constant
1egoman Jun 4, 2026
7a13f50
fix: make rpc use datastream.sendText, NOT streamText
1egoman Jun 4, 2026
6820330
fix: convert rpc tests from streamText -> sendText
1egoman Jun 4, 2026
846173f
feat: add initial support for single packet data streams via hacky me…
1egoman Jun 4, 2026
db5547b
feat: add backwards compatibility back in for old multi packet v1 dat…
1egoman Jun 4, 2026
64042a0
feat: check all participants in room before broadcasting a v2 data st…
1egoman Jun 4, 2026
759b8e6
feat: add initial data stream benchmark app
1egoman Jun 5, 2026
42ae43f
feat: add missing constants file
1egoman Jun 5, 2026
9f8a983
feat: add initial data stream compression implementation
1egoman Jun 5, 2026
4ada1a1
feat: migrate compression to get rid of "pump" and compress per packe…
1egoman Jun 5, 2026
434c932
fix: swap else if -> switch/case
1egoman Jun 5, 2026
c9ed60a
feat: add initial take at streaming through CompressionStream for data
1egoman Jun 8, 2026
1ee48e8
feat: commit hand written data streams compression approach
1egoman Jun 9, 2026
ea65ece
feat: try out using fflate to share a single compression stream acros…
1egoman Jun 10, 2026
ba4a28e
refactor: move to deflate-raw for all compression, move to Compressio…
1egoman Jun 10, 2026
3c7b6a8
fix: get rid of singleWrite mode on streamText
1egoman Jun 10, 2026
a721255
fix: clean up code
1egoman Jun 11, 2026
d6da60d
feat: remove compression from streamText, in practice this doesn't re…
1egoman Jun 11, 2026
0f2831d
feat: add compression into bytestreams too
1egoman Jun 12, 2026
a3c60ad
refactor: move around outgoing data stream single packet / compressio…
1egoman Jun 12, 2026
837aacf
fix: reduce needless diff churn
1egoman Jun 12, 2026
21c2544
feat: add max header size breaking change
1egoman Jun 12, 2026
520c381
feat: advertise new CAP_COMPRESSION_DEFLATE_RAW capability to SFU
1egoman Jun 15, 2026
88adfa0
feat: add proper OutgoingDataStreamManager tests
1egoman Jun 15, 2026
5990dbb
feat: add initial IncomingDataStreamManager tests
1egoman Jun 16, 2026
d690e42
fix: ensure that compression only used when remote participants suppo…
1egoman Jun 16, 2026
ad14a39
fix: fiz zlib Z_SYNC_FLUSH test
1egoman Jun 16, 2026
ce342ec
feat: add a few more IncomingDataStreamManager tests
1egoman Jun 16, 2026
cb247a9
fix: reformat code
1egoman Jun 17, 2026
3d312d5
fix: remove unused import
1egoman Jun 17, 2026
4e43e86
fix: remove Z_SYNC_FLUSH test, it was not really testing the right thing
1egoman Jun 17, 2026
fe033cd
fix: add participant disconnect test
1egoman Jun 17, 2026
69084c9
fix: add sendFile v1 outgoing data stream manager tests
1egoman Jun 17, 2026
f4652e3
feat: port over data streams implementation to use newly added proto …
1egoman Jun 23, 2026
bd74e39
feat: commit initial data streams spec
1egoman Jun 23, 2026
b41875e
fix: remove unused tests
1egoman Jun 23, 2026
2fc2bbd
fix: remove earlier drafts mention
1egoman Jun 25, 2026
949a8b1
fix: remove more out of date E2EE stuff and note about utf-8 chunk bo…
1egoman Jun 25, 2026
a1780ac
fix: update misleading comments
1egoman Jun 25, 2026
f4eab35
fix: add sendBytes method as the main entrypoint for sending inline b…
1egoman Jun 25, 2026
deb8b57
fix: make sendFile optional in spec
1egoman Jun 25, 2026
0f13573
fix: run npm run format
1egoman Jun 25, 2026
42c7ee1
fix: address remaining lint errors
1egoman Jun 25, 2026
76f9866
fix: add missing changeset
1egoman Jun 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slick-geese-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Add support for data streams v2
761 changes: 761 additions & 0 deletions DATA_STREAMS_SPEC.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: here is the (mostly complete) spec for this feature.

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions examples/data-stream-benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Data Stream Benchmark

Measures the end-to-end latency of LiveKit **v2 data streams** across a grid of network conditions
(X axis) and payload sizes (Y axis).

Two participants (`bench-sender` and `bench-receiver`) join a shared room in the same browser tab.
For each box in the grid the sender sends a fixed number of data streams (default 10) of random,
realistic JSON data to the receiver. Each stream header carries a `checksum` (XOR of the payload
bytes) and a `sendTs` timestamp; the receiver verifies the checksum and computes the end-to-end
latency. Each cell shows the average latency over the checksum-matching streams, or `N/A`.

## Running

1. Create `.env.local` with `LIVEKIT_API_KEY`, `LIVEKIT_API_SECRET`, and `LIVEKIT_URL`.
2. Install dependencies: `pnpm install`
3. Start the server: `pnpm dev`
4. Open the local URL (typically http://localhost:5173).
5. Click **Connect**, then **Run Benchmark**. Click **Disconnect** when done.

## Network conditioning (macOS only)

The **X axis** (Edge / 3G / LTE / Wi-Fi / None) is driven by the macOS **Network Link Conditioner**.
The server (`api.ts`) toggles it via `osascript` through `POST /api/network-condition`.

Prerequisites:

- The **Network Link Conditioner** preference pane must be installed
(`/Library/PreferencePanes/Network Link Conditioner.prefPane`, from Apple's "Additional Tools for
Xcode").
- The process running `vite`/node needs macOS **Accessibility** permission (System Settings →
Privacy & Security → Accessibility) so it can drive System Settings.
- The preset names must match the conditioner's menu exactly: `Edge`, `3G`, `LTE`, `Wi-Fi`.

The benchmark always resets the conditioner to **off** when it finishes, errors, or you disconnect.

## Notes

- The v2 single-packet (inline) optimization only changes behavior for payloads under the ~15 KB
header budget (10 B–10 KB); 100 KB and 1 MB are multi-packet regardless.
- `Edge`/`3G` × `1 MB` can be slow; each send has a 60 s timeout (`SEND_TIMEOUT_MS` in
`benchmark.ts`) and slow boxes show `N/A`. Repeat count and timeout are constants at the top of
`benchmark.ts`.
121 changes: 121 additions & 0 deletions examples/data-stream-benchmark/api.ts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: The diff is quite large, and a big reason why it is is because I have both this example app AND the spec checked in. I'll remove these before an eventual merge which will make the diff a lot more reasonable.

Feel free to ignore this examples/data-stream-benchmark directory when reviewing.

Image

Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { exec } from 'child_process';
import dotenv from 'dotenv';
import express from 'express';
import { AccessToken } from 'livekit-server-sdk';
import { promisify } from 'util';
import type { Express } from 'express';

dotenv.config({ path: '.env.local' });

const execAsync = promisify(exec);

const LIVEKIT_API_KEY = process.env.LIVEKIT_API_KEY;
const LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET;
const LIVEKIT_URL = process.env.LIVEKIT_URL;

/** Network Link Conditioner presets we allow the client to request. */
const ALLOWED_PRESETS = ['Edge', '3G', 'LTE', 'Wi-Fi', 'Very Bad Network'];

const app = express();
app.use(express.json());

app.post('/api/get-token', async (req, res) => {
const { identity, roomName } = req.body;

if (!LIVEKIT_API_KEY || !LIVEKIT_API_SECRET) {
res.status(500).json({ error: 'Server misconfigured' });
return;
}

const token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, {
identity,
});
token.addGrant({
room: roomName,
roomJoin: true,
canPublish: true,
canSubscribe: true,
});

res.json({
token: await token.toJwt(),
url: LIVEKIT_URL,
});
});

/**
* Enables the macOS Network Link Conditioner at the given preset. The preset name is read from the
* `mode` environment variable via `system attribute "mode"`.
*/
const ENABLE_SCRIPT = `osascript <<'EOF'
set mode to system attribute "mode"
do shell script "open '/Library/PreferencePanes/Network Link Conditioner.prefPane'"
delay 2
tell application "System Settings" to activate
tell application "System Events"
tell process "System Settings"
tell window "Network Link Conditioner"
tell scroll area 1 of group 3 of splitter group 1 of group 1
tell group 1
click pop up button 1
delay 0.3
click menu item mode of menu 1 of pop up button 1
end tell
delay 0.3
click button "ON"
end tell
end tell
end tell
end tell
EOF`;

/** Disables the macOS Network Link Conditioner, returning to the host network speed. */
const DISABLE_SCRIPT = `osascript <<'EOF'
do shell script "open '/Library/PreferencePanes/Network Link Conditioner.prefPane'"
delay 2
tell application "System Settings" to activate
tell application "System Events"
tell process "System Settings"
tell window "Network Link Conditioner"
tell scroll area 1 of group 3 of splitter group 1 of group 1
click button "OFF"
end tell
end tell
end tell
end tell
EOF`;

app.post('/api/network-condition', async (req, res) => {
const { preset } = req.body as { preset?: string };

if (preset === 'off') {
try {
await execAsync(DISABLE_SCRIPT, { timeout: 30_000 });
res.json({ ok: true, preset: 'off' });
} catch (error) {
res.status(500).json({ error: `Failed to disable network conditioner: ${String(error)}` });
}
return;
}

if (!preset || !ALLOWED_PRESETS.includes(preset)) {
res
.status(400)
.json({ error: `Invalid preset "${preset}". Allowed: ${ALLOWED_PRESETS.join(', ')}, off` });
return;
}

try {
await execAsync(ENABLE_SCRIPT, {
timeout: 30_000,
env: { ...process.env, mode: preset },
});
res.json({ ok: true, preset });
} catch (error) {
res
.status(500)
.json({ error: `Failed to set network conditioner to ${preset}: ${String(error)}` });
}
});
Comment thread
1egoman marked this conversation as resolved.
Dismissed

export const handler: Express = app;
Loading
Loading