Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
233 commits
Select commit Hold shift + click to select a range
83783a4
Use WIP protocol for data tracks
ladvoc Oct 11, 2025
4c632d5
Wip
ladvoc Oct 17, 2025
e11b8d0
Wip
ladvoc Oct 18, 2025
b8af013
Migrate data track packet implementation
ladvoc Oct 19, 2025
dd09ea7
Wip
ladvoc Oct 19, 2025
f180a43
Upgrade DTP
ladvoc Oct 29, 2025
478ceca
Update protocol
ladvoc Oct 29, 2025
483dff3
Expose DTP types
ladvoc Oct 29, 2025
d28aa19
Update protocol
ladvoc Nov 15, 2025
12a7ee3
Track handle assignment & conversion
ladvoc Nov 15, 2025
c70a606
Remove mime
ladvoc Nov 15, 2025
0975b24
Publish implementation
ladvoc Nov 15, 2025
2028c91
Revert older changes
ladvoc Nov 15, 2025
525ec96
Generate lockfile
ladvoc Nov 15, 2025
c32bbcf
Remove older changes
ladvoc Nov 15, 2025
971c72b
Fix protocol integration
ladvoc Nov 15, 2025
b962e5b
Make modules public
ladvoc Nov 15, 2025
737539c
Rename struct
ladvoc Nov 15, 2025
8016280
Create data track example
ladvoc Nov 15, 2025
2f0c0cc
Add publish method
ladvoc Nov 15, 2025
e345b6c
Integrate publisher
ladvoc Nov 15, 2025
1d7bc2d
Bug fixes
ladvoc Nov 15, 2025
64d84aa
Add TODO
ladvoc Nov 15, 2025
2ee7725
Add error reason
ladvoc Nov 15, 2025
9118fe5
Create packetizer
ladvoc Nov 15, 2025
ff60baa
Protocol updates
ladvoc Dec 16, 2025
377b314
Apply lint suggestions
ladvoc Dec 16, 2025
bea719f
TODO for sync state
ladvoc Dec 19, 2025
80a614b
Implement packetizer
ladvoc Dec 20, 2025
b195d5c
Hide version field
ladvoc Dec 20, 2025
32de621
Rename
ladvoc Dec 20, 2025
e80218b
Reorganize modules
ladvoc Dec 20, 2025
45faf39
Include type aliases
ladvoc Dec 20, 2025
965a65f
Renaming
ladvoc Dec 20, 2025
2c60863
Documentation
ladvoc Dec 20, 2025
5637b28
Do not expose internal type
ladvoc Dec 20, 2025
65a81c6
Docs
ladvoc Dec 23, 2025
ffcd696
Relocate type
ladvoc Dec 23, 2025
98dd429
Track inner for remote track
ladvoc Dec 23, 2025
3654b94
Separate impl blocks
ladvoc Dec 23, 2025
6898fb4
Remote skeleton
ladvoc Dec 23, 2025
82eb90c
Define signal I/O
ladvoc Dec 23, 2025
fc380e2
Format
ladvoc Dec 23, 2025
9c6d133
Define channels, new for remote manager
ladvoc Dec 23, 2025
00ece41
Docs
ladvoc Dec 23, 2025
ab1432b
Allow cloning data track frame
ladvoc Dec 23, 2025
5fbbe84
Handle packet input
ladvoc Dec 23, 2025
e15c61c
Handle sync state
ladvoc Dec 23, 2025
54f7075
Protocol abstraction layer
ladvoc Dec 24, 2025
a29cf2f
Module organization
ladvoc Dec 24, 2025
669a7f3
Rename types
ladvoc Dec 24, 2025
27288fb
Remove unused imports
ladvoc Dec 24, 2025
c466871
Module organization
ladvoc Dec 24, 2025
fc13086
Move track inner into parent module
ladvoc Dec 24, 2025
180854a
Wrap inner track in arc
ladvoc Dec 24, 2025
2a5cdf2
Module visibility
ladvoc Dec 24, 2025
1fc7635
Rename module to pipeline
ladvoc Dec 24, 2025
a2b021d
Relocate task inner
ladvoc Dec 24, 2025
9c57a92
Use type alias
ladvoc Dec 24, 2025
6a6a06d
Format
ladvoc Dec 24, 2025
a466425
Separate buffer sizes
ladvoc Dec 30, 2025
aa46af3
Decouple proto for local manager
ladvoc Dec 30, 2025
267db6b
Protocol conversion unit tests
ladvoc Dec 30, 2025
bf98cc5
Shutdown event for local manager
ladvoc Dec 30, 2025
ae7dc67
Rename
ladvoc Dec 30, 2025
80654cd
Shutdown event for remote manager
ladvoc Dec 30, 2025
5ce512c
Unified descriptor map
ladvoc Dec 30, 2025
6e35c86
Use is_published
ladvoc Dec 30, 2025
016da09
Biased select
ladvoc Dec 31, 2025
6adaa57
Wip
ladvoc Dec 31, 2025
37bb285
Remote track implementation
ladvoc Jan 1, 2026
f3c1251
Cleaner error handling
ladvoc Jan 1, 2026
50ca3da
Detect publication changes
ladvoc Jan 1, 2026
ad779b1
Efficient handle mapping
ladvoc Jan 1, 2026
527bb03
Remove result
ladvoc Jan 1, 2026
58312a5
Is published method
ladvoc Jan 1, 2026
306a0a2
Group public exports into API/internal
ladvoc Jan 1, 2026
8e2094c
E2ee provider implementations
ladvoc Jan 1, 2026
da53bbe
Fix import paths
ladvoc Jan 1, 2026
724cd87
Update integration
ladvoc Jan 1, 2026
9d39d32
Remote data track published event
ladvoc Jan 1, 2026
5e060c8
Forward signal messages
ladvoc Jan 1, 2026
f9b64d0
Forward published packets on data channel
ladvoc Jan 1, 2026
44ccd2a
Forward input events
ladvoc Jan 6, 2026
51ee198
Simplify imports
ladvoc Jan 6, 2026
0af0cb8
Rename
ladvoc Jan 6, 2026
37aa225
Remove unused type
ladvoc Jan 6, 2026
a9d1923
Forward incoming packets to manager
ladvoc Jan 6, 2026
18b9e93
Use future core trait, pin stream
ladvoc Jan 6, 2026
5cb900c
Expose data tracks types in prelude
ladvoc Jan 6, 2026
2a83de4
Update examples
ladvoc Jan 6, 2026
adcb23c
Simplify frame construction
ladvoc Jan 6, 2026
1fb9174
Relocate packetizer
ladvoc Jan 6, 2026
7716912
Skelton for depacketizer
ladvoc Jan 6, 2026
64eb934
Basic manager tests
ladvoc Jan 6, 2026
42a4b4b
Remote track task spawn and join
ladvoc Jan 6, 2026
1f11d14
Local join track task
ladvoc Jan 6, 2026
4e77261
Address todos, unit test
ladvoc Jan 7, 2026
141da9f
Type alias
ladvoc Jan 7, 2026
6d78cc8
Clean up imports
ladvoc Jan 7, 2026
93a9d57
Simplify naming
ladvoc Jan 7, 2026
3b0508a
Doc
ladvoc Jan 7, 2026
4012fd3
Sid wrapper type
ladvoc Jan 7, 2026
4654ccb
Log instead of result
ladvoc Jan 7, 2026
63f943d
Module organization
ladvoc Jan 8, 2026
b35ce0c
Dtp frame marker
ladvoc Jan 9, 2026
d08aa08
Remove unused function
ladvoc Jan 9, 2026
f3c4545
Simplify docs
ladvoc Jan 9, 2026
0cb44f3
Extensions struct
ladvoc Jan 9, 2026
59d80ee
Rename
ladvoc Jan 9, 2026
ea193a2
Remove comment
ladvoc Jan 9, 2026
cffb27b
Separate extension module
ladvoc Jan 9, 2026
ffb84e2
Dtp revisions
ladvoc Jan 10, 2026
547e94c
Prototype depacketizer
ladvoc Jan 10, 2026
851d077
Doc
ladvoc Jan 10, 2026
5ef58e0
Update data track e2e test
ladvoc Jan 10, 2026
5c15a3a
Update data channel label
ladvoc Jan 10, 2026
b4e662f
Share options
ladvoc Jan 10, 2026
2b586b2
Store reference to data track dc
ladvoc Jan 10, 2026
90d1455
Ensure publisher transport connected
ladvoc Jan 10, 2026
bbff399
Log
ladvoc Jan 10, 2026
72d68d9
Do not process as standard data packet
ladvoc Jan 10, 2026
e1cd4d3
Debug logging
ladvoc Jan 13, 2026
2af0714
Disable auto subscribe in example
ladvoc Jan 13, 2026
caf8919
Don't expose local participant's tracks to remote manager
ladvoc Jan 13, 2026
2e6e7d2
Doc
ladvoc Jan 13, 2026
6776e45
Rename for clarity
ladvoc Jan 13, 2026
f76aeff
Forward incoming packets to remote manager
ladvoc Jan 13, 2026
5a64a47
Fix send packet to track task
ladvoc Jan 14, 2026
55aa33e
Properly handle ctrl+c
ladvoc Jan 14, 2026
f3070e0
Custom debug impl for frame
ladvoc Jan 14, 2026
6ec5d57
Update E2E test
ladvoc Jan 14, 2026
28ad0b0
Test dev dependencies
ladvoc Jan 14, 2026
a5aec19
Log send error reason
ladvoc Jan 14, 2026
1795c93
Rename example
ladvoc Jan 14, 2026
6b06691
Parameterize E2E test
ladvoc Jan 14, 2026
f4f14a4
Update example name in workspace
ladvoc Jan 14, 2026
b65ab4d
Use faker
ladvoc Jan 14, 2026
bea6d0f
Format
ladvoc Jan 14, 2026
d90b289
Rename for explicitness
ladvoc Jan 14, 2026
aa8c555
Doc
ladvoc Jan 14, 2026
6e5bed4
Depacketize multi-packet frames
ladvoc Jan 15, 2026
88231a0
Improve tests
ladvoc Jan 15, 2026
c517dfa
Batch outgoing packets per frame
ladvoc Jan 15, 2026
050bd97
Log level
ladvoc Jan 15, 2026
89983e1
Add test cases
ladvoc Jan 15, 2026
5aab722
Add missing dev dependency
ladvoc Jan 15, 2026
fd38b53
Allow overriding video grants for e2e tests
ladvoc Jan 15, 2026
12463dc
Remove explicit setting of auto subscribe to false
ladvoc Jan 15, 2026
679eefb
Doc
ladvoc Jan 15, 2026
67da84a
Clarify type intention (local)
ladvoc Jan 16, 2026
aabe13f
Clarify type intention (remote)
ladvoc Jan 16, 2026
6b849df
Consistency
ladvoc Jan 16, 2026
25c3262
Doc
ladvoc Jan 16, 2026
e0298bc
Fix handle allocator
ladvoc Jan 17, 2026
d072840
Test publish many tracks
ladvoc Jan 17, 2026
b4135b4
Test publish unauthorized
ladvoc Jan 17, 2026
8f50b26
Test publish duplicate name
ladvoc Jan 17, 2026
3fa6217
More idiomatic track publish API
ladvoc Jan 17, 2026
d342cc9
Doc
ladvoc Jan 17, 2026
3dc8f59
Remove duplication implementation
ladvoc Jan 17, 2026
aa64188
Doc
ladvoc Jan 17, 2026
83c032c
Fix
ladvoc Jan 17, 2026
b1565d4
Make crate internal
ladvoc Jan 17, 2026
07a5966
End to end encryption
ladvoc Jan 17, 2026
276bbf6
Format
ladvoc Jan 17, 2026
736cc60
Doc
ladvoc Jan 17, 2026
b29c7c0
Fix deadlock
ladvoc Jan 17, 2026
54cf8b4
Remove log
ladvoc Jan 17, 2026
63f17e2
Test end-to-end encryption
ladvoc Jan 17, 2026
af12b55
Fix disable e2ee per track, rename
ladvoc Jan 17, 2026
0cc9c22
Rename to pipeline
ladvoc Jan 17, 2026
7b09bc6
Use weak sender
ladvoc Jan 17, 2026
27c57ba
Move to separate function
ladvoc Jan 17, 2026
e71c698
Private fields in pipeline
ladvoc Jan 17, 2026
b270f2b
Local pipeline unit testing
ladvoc Jan 17, 2026
e7d0982
Remove unused
ladvoc Jan 17, 2026
2d53aa7
Rename dtp to packet
ladvoc Jan 17, 2026
ea91663
Apply clippy suggestions
ladvoc Jan 17, 2026
0126d93
Format
ladvoc Jan 17, 2026
b8d537d
Fix spelling error
ladvoc Jan 20, 2026
d003f6e
Decouple pipeline from task
ladvoc Jan 20, 2026
5b5df26
Fix header length calculation
ladvoc Jan 21, 2026
6f6d840
Doc
ladvoc Jan 21, 2026
02c22d6
Remove debug logs
ladvoc Jan 21, 2026
c4e53cd
Decouple pipeline from task
ladvoc Jan 21, 2026
41e80a5
Simplify track state handling for remote manager
ladvoc Jan 21, 2026
d550047
Check publish status for any data track
ladvoc Jan 21, 2026
c1c56ea
Wait for unpublish method
ladvoc Jan 21, 2026
a3a1f06
Unsubscribe when no longer required
ladvoc Jan 21, 2026
22a61fe
Rename
ladvoc Jan 21, 2026
7ce883c
Unit test remote pipeline
ladvoc Jan 21, 2026
05c143a
User timestamp now method
ladvoc Jan 21, 2026
6f705bb
Rename publish frame to push
ladvoc Jan 21, 2026
6442de1
Remove per-track E2EE disable option
ladvoc Jan 21, 2026
0adda39
Add README
ladvoc Jan 21, 2026
52d8542
Update test for E2EE
ladvoc Jan 22, 2026
272c89a
Fix manager logic to allow resubscribe
ladvoc Jan 22, 2026
6b065c9
No deref impl
ladvoc Jan 22, 2026
380ea01
Rename
ladvoc Jan 22, 2026
8349456
Add roundtrip test
ladvoc Jan 22, 2026
31d7cc8
Doc
ladvoc Jan 23, 2026
02114d8
Start extension word count at zero
ladvoc Jan 23, 2026
7c3e688
Style
ladvoc Jan 23, 2026
29f232e
Test user timestamp, add convenience method
ladvoc Jan 23, 2026
eb59747
Doc
ladvoc Jan 23, 2026
d0779c1
Style
ladvoc Jan 23, 2026
6880a28
Drop reporting in depacketizer
ladvoc Jan 23, 2026
6b4f4e4
Add note
ladvoc Jan 23, 2026
2c6e149
Latency in basic example
ladvoc Jan 23, 2026
6bbf620
Improve timeout handling (local)
ladvoc Jan 24, 2026
09416eb
Events in separate module (local)
ladvoc Jan 24, 2026
21898f4
Rename events for clarity (local)
ladvoc Jan 24, 2026
cc5042e
Rename handlers (local)
ladvoc Jan 24, 2026
d543309
Organize
ladvoc Jan 24, 2026
0582e23
Events in separate module (remote)
ladvoc Jan 24, 2026
ba3dec4
Rename events for clarity (remote)
ladvoc Jan 24, 2026
f080024
Rename handlers (remote)
ladvoc Jan 24, 2026
28a650c
Make separate event
ladvoc Jan 24, 2026
7abbf0b
Move data track managers to room
ladvoc Jan 27, 2026
843b3c9
Ensure data channel transport is open
ladvoc Jan 29, 2026
2079662
Additional unit tests for depacketizer
ladvoc Jan 29, 2026
61fab99
Include published tracks in sync state
ladvoc Jan 30, 2026
9219dec
Reduce E2E test boilerplate
ladvoc Jan 30, 2026
f81791a
Docs
ladvoc Jan 31, 2026
67d56e1
Test subscriber side fault, fix full reconnect
ladvoc Jan 31, 2026
3f77ce9
Test publisher side fault
ladvoc Jan 31, 2026
7f2724c
Improve internal docs & organization
ladvoc Jan 31, 2026
16d0294
Upgrade protocol to v1.44.0
ladvoc Jan 31, 2026
cb8f8a8
Integrate
ladvoc Jan 31, 2026
ca66c69
generated protobuf
github-actions[bot] Jan 31, 2026
c8bf08e
Merge remote-tracking branch 'origin/ladvoc/proto-v1.44.0' into ladvo…
ladvoc Jan 31, 2026
eef2550
generated protobuf
github-actions[bot] Jan 31, 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
593 changes: 545 additions & 48 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"livekit-uniffi",
"livekit-ffi-node-bindings",
"livekit-runtime",
"livekit-datatrack",
"libwebrtc",
"soxr-sys",
"yuv-sys",
Expand All @@ -19,6 +20,7 @@ members = [
"examples/api",
"examples/basic_room",
"examples/basic_text_stream",
"examples/basic_data_track",
"examples/encrypted_text_stream",
"examples/local_audio",
"examples/local_video",
Expand All @@ -40,6 +42,7 @@ livekit-api = { version = "0.4.12", path = "livekit-api" }
livekit-ffi = { version = "0.12.44", path = "livekit-ffi" }
livekit-protocol = { version = "0.6.0", path = "livekit-protocol" }
livekit-runtime = { version = "0.4.0", path = "livekit-runtime" }
livekit-datatrack = { version = "0.1.0", path = "livekit-datatrack" }
soxr-sys = { version = "0.1.1", path = "soxr-sys" }
webrtc-sys = { version = "0.3.21", path = "webrtc-sys" }
webrtc-sys-build = { version = "0.3.12", path = "webrtc-sys/build" }
Expand Down
21 changes: 21 additions & 0 deletions examples/basic_data_track/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "basic_data_track"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
tokio = { version = "1", features = ["full"] }
livekit = { workspace = true, features = ["rustls-tls-native-roots"] }
futures-util = { version = "0.3", default-features = false, features = ["sink"] }
anyhow = "1.0.100"
log = "0.4.26"
env_logger = "0.11.7"

[[bin]]
name = "publisher"
path = "src/publisher.rs"

[[bin]]
name = "subscriber"
path = "src/subscriber.rs"
21 changes: 21 additions & 0 deletions examples/basic_data_track/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Basic Data Track

Simple example of publishing and subscribing to a data track.

## Usage

1. Run the publisher:

```sh
export LIVEKIT_URL="..."
export LIVEKIT_TOKEN="<first participant token>"
cargo run --bin publisher
```

2. In a second terminal, run the subscriber:

```sh
export LIVEKIT_URL="..."
export LIVEKIT_TOKEN="<second participant token>"
cargo run --bin subscriber
```
39 changes: 39 additions & 0 deletions examples/basic_data_track/src/publisher.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use anyhow::Result;
use livekit::prelude::*;
use std::{env, time::Duration};
use tokio::{signal, time};

#[tokio::main]
async fn main() -> Result<()> {
env_logger::init();

let url = env::var("LIVEKIT_URL").expect("LIVEKIT_URL is not set");
let token = env::var("LIVEKIT_TOKEN").expect("LIVEKIT_TOKEN is not set");

let (room, _) = Room::connect(&url, &token, RoomOptions::default()).await?;

let track = room.local_participant().publish_data_track("my_sensor_data").await?;

tokio::select! {
_ = push_frames(track) => {}
_ = signal::ctrl_c() => {}
}
Ok(())
}

async fn read_sensor() -> Vec<u8> {
// Dynamically read some sensor data...
vec![0xFA; 256]
}

async fn push_frames(track: LocalDataTrack) {
loop {
log::info!("Pushing frame");

let frame = DataTrackFrame::new(read_sensor().await)
.with_user_timestamp_now();

track.try_push(frame).inspect_err(|err| println!("Failed to push frame: {}", err)).ok();
time::sleep(Duration::from_millis(500)).await
}
}
52 changes: 52 additions & 0 deletions examples/basic_data_track/src/subscriber.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use anyhow::Result;
use futures_util::StreamExt;
use livekit::prelude::*;
use std::env;
use tokio::{signal, sync::mpsc::UnboundedReceiver};

#[tokio::main]
async fn main() -> Result<()> {
env_logger::init();

let url = env::var("LIVEKIT_URL").expect("LIVEKIT_URL is not set");
let token = env::var("LIVEKIT_TOKEN").expect("LIVEKIT_TOKEN is not set");

let (_, rx) = Room::connect(&url, &token, RoomOptions::default()).await?;

tokio::select! {
_ = handle_first_publication(rx) => {}
_ = signal::ctrl_c() => {}
}
Ok(())
}

/// Subscribe to the first data track published.
async fn handle_first_publication(mut rx: UnboundedReceiver<RoomEvent>) -> Result<()> {
log::info!("Waiting for publication…");
while let Some(event) = rx.recv().await {
let RoomEvent::RemoteDataTrackPublished(track) = event else {
continue;
};
subscribe(track).await?
}
Ok(())
}

/// Subscribes to the given data track and logs received frames.
async fn subscribe(track: RemoteDataTrack) -> Result<()> {
log::info!(
"Subscribing to '{}' published by '{}'",
track.info().name(),
track.publisher_identity()
);
let mut stream = track.subscribe().await?;
while let Some(frame) = stream.next().await {
log::info!("Received frame ({} bytes)", frame.payload().len());

if let Some(duration) = frame.duration_since_timestamp() {
log::info!("Latency: {:?}", duration);
}
}
log::info!("Unsubscribed");
Ok(())
}
1 change: 1 addition & 0 deletions livekit-api/src/services/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl ConnectorClient {
proto::DisconnectWhatsAppCallRequest {
whatsapp_call_id: call_id.into(),
whatsapp_api_key: api_key.into(),
..Default::default()
},
self.base
.auth_header(VideoGrants { room_create: true, ..Default::default() }, None)?,
Expand Down
25 changes: 25 additions & 0 deletions livekit-datatrack/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "livekit-datatrack"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/livekit/rust-sdks"
readme = "README.md"

[dependencies]
livekit-protocol = { workspace = true }
livekit-runtime = { workspace = true }
log = { version = "0.4.28" }
thiserror = "2.0.17"
tokio = { version = "1.48.0", default-features = false, features = ["sync"] }
futures-util = { version = "0.3", default-features = false, features = ["sink"] }
futures-core = "0.3.31"
bytes = "1.10.1"
from_variants = "1.0.2"
tokio-stream = { version = "0.1.17", features = ["sync"] }
anyhow = "1.0.100" # For internal error handling only
rand = "0.9.2"

[dev-dependencies]
test-case = "3.3"
fake = { version = "4.4", features = ["derive"] }
6 changes: 6 additions & 0 deletions livekit-datatrack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# LiveKit Data Track

**Important**:
This is an internal crate that powers the data tracks feature in LiveKit client SDKs (including [Rust](https://crates.io/crates/livekit) and others) and is not usable directly.

To use data tracks in your application, please use the public APIs provided by the client SDKs.
57 changes: 57 additions & 0 deletions livekit-datatrack/src/e2ee.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2025 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use bytes::Bytes;
use core::fmt::Debug;
use thiserror::Error;

// TODO: If a core module for end-to-end encryption is created in the future
// (livekit-e2ee), these traits should be moved to there.

/// Encrypted payload and metadata required for decryption.
pub struct EncryptedPayload {
pub payload: Bytes,
pub iv: [u8; 12],
pub key_index: u8,
}

/// An error indicating a payload could not be encrypted.
#[derive(Debug, Error)]
#[error("Encryption failed")]
pub struct EncryptionError;

/// An error indicating a payload could not be decrypted.
#[derive(Debug, Error)]
#[error("Decryption failed")]
pub struct DecryptionError;

/// Provider for encrypting payloads for E2EE.
pub trait EncryptionProvider: Send + Sync + Debug {
/// Encrypts the given payload being sent by the local participant.
fn encrypt(&self, payload: Bytes) -> Result<EncryptedPayload, EncryptionError>;
}

/// Provider for decrypting payloads for E2EE.
pub trait DecryptionProvider: Send + Sync + Debug {
/// Decrypts the given payload received from a remote participant.
///
/// Sender identity is required in order for the proper key to be used
/// for decryption.
///
fn decrypt(
&self,
payload: EncryptedPayload,
sender_identity: &str,
) -> Result<Bytes, DecryptionError>;
}
24 changes: 24 additions & 0 deletions livekit-datatrack/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2025 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use thiserror::Error;

/// Internal data track error.
///
/// Occurrences of this error type are unexpected and likely indicate
/// a bug. If encountered, please report on GitHub and include the full error description.
///
#[derive(Debug, Error)]
#[error(transparent)]
pub struct InternalError(#[from] anyhow::Error);
Loading