-
Notifications
You must be signed in to change notification settings - Fork 175
Data tracks UniFFI #1034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Data tracks UniFFI #1034
Changes from all commits
04c4db0
95bf51c
18cacdd
0635e4b
16791dd
9b39329
0c621f9
5943438
895b034
9b275de
d254497
e275186
2e91900
af84b22
22d3a35
00a6e99
40b8cc3
5ba3dc5
78f27cb
26b61c7
e1aba7d
ca653fb
cc742da
0911f3f
25446d3
807305a
c06705c
f2815ea
91d251c
66d365e
bd81965
eea0ac7
d428f66
7a35faf
8c39c41
bea2560
1db92e3
bf80cf4
4079e77
69b5b03
def2f97
0533a38
9f89c44
90cf95a
cdc2a7e
b449306
6451ece
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| livekit-datatrack: patch | ||
| livekit: patch | ||
| --- | ||
|
|
||
| # Make some fields public for data track types |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| livekit: patch | ||
| livekit-datatrack: patch | ||
| --- | ||
|
|
||
| # Make data track E2EE errors enums |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| livekit-uniffi: minor | ||
| --- | ||
|
|
||
| # Expose data tracks core functionality |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| livekit-datatrack: patch | ||
| livekit: patch | ||
| livekit-ffi: patch | ||
| --- | ||
|
|
||
| # Use concrete type for data track manager output events |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,8 +32,8 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; | |
| /// | ||
| #[derive(Clone, Default)] | ||
| pub struct DataTrackFrame { | ||
| pub(crate) payload: Bytes, | ||
| pub(crate) user_timestamp: Option<u64>, | ||
| pub payload: Bytes, | ||
| pub user_timestamp: Option<u64>, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: shall we expose |
||
| } | ||
|
|
||
| impl DataTrackFrame { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright 2026 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; | ||
|
|
||
| uniffi::custom_type!(Bytes, Vec<u8>, { remote }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. General: do we plan to introduce some helpers for encoding/decoding into that or leaving that to experienced users?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This macro handles the conversion from
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I just mean "something higher-level than |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Copyright 2026 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 livekit_datatrack::api::{DataTrackFrame, DataTrackSid}; | ||
| use livekit_protocol as proto; | ||
| use prost::Message; | ||
|
|
||
| uniffi::custom_type!(DataTrackSid, String, { | ||
| remote, | ||
| lower: |s| String::from(s), | ||
| try_lift: |s| DataTrackSid::try_from(s).map_err(|e| uniffi::deps::anyhow::anyhow!("{e}")), | ||
| }); | ||
|
|
||
| #[uniffi::remote(Record)] | ||
| pub struct DataTrackFrame { | ||
| pub payload: Bytes, | ||
| pub user_timestamp: Option<u64>, | ||
| } | ||
|
|
||
| /// Information about a published data track. | ||
| #[derive(uniffi::Record)] | ||
| pub struct DataTrackInfo { | ||
| pub sid: DataTrackSid, | ||
| pub name: String, | ||
| pub uses_e2ee: bool, | ||
| } | ||
|
|
||
| impl From<&livekit_datatrack::api::DataTrackInfo> for DataTrackInfo { | ||
| fn from(info: &livekit_datatrack::api::DataTrackInfo) -> Self { | ||
| Self { sid: info.sid(), name: info.name().to_string(), uses_e2ee: info.uses_e2ee() } | ||
| } | ||
| } | ||
|
|
||
| /// Signal response crossing the FFI boundary could not be processed. | ||
| #[derive(uniffi::Error, thiserror::Error, Debug)] | ||
| #[uniffi(flat_error)] | ||
| pub enum HandleSignalResponseError { | ||
| #[error("Response decoding failed: {0}")] | ||
| Decode(prost::DecodeError), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: It is worth making a unique error type here rather than using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this uses the |
||
| #[error("Response container has no message")] | ||
| EmptyMessage, | ||
| #[error("Unsupported response type in this context")] | ||
| UnsupportedType, | ||
| #[error(transparent)] | ||
| Internal(livekit_datatrack::api::InternalError), | ||
| } | ||
|
|
||
| /// Deserializes a signal response crossing the FFI boundary, returning the message variant. | ||
| pub(crate) fn deserialize_signal_response( | ||
| res: &[u8], | ||
| ) -> Result<proto::signal_response::Message, HandleSignalResponseError> { | ||
| let res = | ||
| proto::SignalResponse::decode(res).map_err(|err| HandleSignalResponseError::Decode(err))?; | ||
| res.message.ok_or(HandleSignalResponseError::EmptyMessage) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is not an
uniffi::Objectwe won't getwithTimestampNowetc. for free, right? As it basically maps to raw struct:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applies to other "DTOs" as well, so good to discuss that now.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this type of "DTO" is more naturally modeled as a value type on the Swift side. I don't think you can currently have associated functions on a
uniffi::Record(even though this makes sense in a Swift context), so I see two options:uniffi::Objectfn with_user_timestamp(frame: DataTrackFrame) → DataTrackFrame) and define anextension DataTrackFrameon the Swift side to make it an associated functionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good news: UniFFI v0.31.0 added support for methods on records and enums!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup let's avoid handwritten extensions and just try bumping UniFFI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: tried that locally, and it does not work for
#[uniffi::remote(Record)]e.g.DataTrackFrame