Skip to content

Commit

Permalink
Merge branch 'main' into encoded-audio-source
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-- authored Jun 6, 2024
2 parents 4a427ae + 01c81bb commit e7f2805
Show file tree
Hide file tree
Showing 20 changed files with 204 additions and 113 deletions.
Binary file modified .github/banner_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/banner_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<picture>
<source media="(prefers-color-scheme: dark)" srcset="/.github/banner_dark.png">
<source media="(prefers-color-scheme: light)" srcset="/.github/banner_light.png">
<img style="width:100%;" alt="The LiveKit icon, the name of the repository and some sample code in the background." src="https://raw.githubusercontent.com/livekit/client-sdk-rust/main/.github/banner_light.png">
<img style="width:100%;" alt="The LiveKit icon, the name of the repository and some sample code in the background." src="https://raw.githubusercontent.com/livekit/rust-sdks/main/.github/banner_light.png">
</picture>

<!--END_BANNER_IMAGE-->
Expand Down Expand Up @@ -188,8 +188,8 @@ We'll first use it as a basis for our Unity SDK (under development), but over ti
<br/><table>
<thead><tr><th colspan="2">LiveKit Ecosystem</th></tr></thead>
<tbody>
<tr><td>Real-time SDKs</td><td><a href="https://github.com/livekit/components-js">React Components</a> · <a href="https://github.com/livekit/client-sdk-js">JavaScript</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <a href="https://github.com/livekit/client-sdk-react-native">React Native</a> · <b>Rust</b> · <a href="https://github.com/livekit/client-sdk-python">Python</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (web)</a> · <a href="https://github.com/livekit/client-sdk-unity">Unity (beta)</a></td></tr><tr></tr>
<tr><td>Server APIs</td><td><a href="https://github.com/livekit/server-sdk-js">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <a href="https://github.com/livekit/client-sdk-python">Python</a> · <b>Rust</b> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a></td></tr><tr></tr>
<tr><td>Real-time SDKs</td><td><a href="https://github.com/livekit/components-js">React Components</a> · <a href="https://github.com/livekit/client-sdk-js">Browser</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <a href="https://github.com/livekit/client-sdk-react-native">React Native</a> · <b>Rust</b> · <a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/python-sdks">Python</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (web)</a> · <a href="https://github.com/livekit/client-sdk-unity">Unity (beta)</a></td></tr><tr></tr>
<tr><td>Server APIs</td><td><a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <a href="https://github.com/livekit/python-sdks">Python</a> · <b>Rust</b> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a></td></tr><tr></tr>
<tr><td>Agents Frameworks</td><td><a href="https://github.com/livekit/agents">Python</a> · <a href="https://github.com/livekit/agent-playground">Playground</a></td></tr><tr></tr>
<tr><td>Services</td><td><a href="https://github.com/livekit/livekit">Livekit server</a> · <a href="https://github.com/livekit/egress">Egress</a> · <a href="https://github.com/livekit/ingress">Ingress</a> · <a href="https://github.com/livekit/sip">SIP</a></td></tr><tr></tr>
<tr><td>Resources</td><td><a href="https://docs.livekit.io">Docs</a> · <a href="https://github.com/livekit-examples">Example apps</a> · <a href="https://livekit.io/cloud">Cloud</a> · <a href="https://docs.livekit.io/oss/deployment">Self-hosting</a> · <a href="https://github.com/livekit/livekit-cli">CLI</a></td></tr>
Expand Down
2 changes: 1 addition & 1 deletion libwebrtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description = "Livekit safe bindings to libwebrtc"
repository = "https://github.com/livekit/rust-sdks"

[dependencies]
livekit-protocol = { path = "../livekit-protocol", version = "0.3.2" }
livekit-protocol = { path = "../livekit-protocol", version = "0.3.3" }
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion livekit-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ rustls-tls-webpki-roots = [
__rustls-tls = ["tokio-tungstenite?/__rustls-tls", "reqwest?/__rustls"]

[dependencies]
livekit-protocol = { path = "../livekit-protocol", version = "0.3.2" }
livekit-protocol = { path = "../livekit-protocol", version = "0.3.3" }
thiserror = "1.0"
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10"
Expand Down
6 changes: 3 additions & 3 deletions livekit-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "livekit-ffi"
version = "0.5.0"
version = "0.6.0"
edition = "2021"
license = "Apache-2.0"
description = "FFI interface for bindings in other languages"
Expand All @@ -18,8 +18,8 @@ __rustls-tls = ["livekit/__rustls-tls"]
tracing = ["tokio/tracing", "console-subscriber"]

[dependencies]
livekit = { path = "../livekit", version = "0.3.2" }
livekit-protocol = { path = "../livekit-protocol", version = "0.3.2" }
livekit = { path = "../livekit", version = "0.4.0" }
livekit-protocol = { path = "../livekit-protocol", version = "0.3.3" }
tokio = { version = "1", features = ["full", "parking_lot"] }
futures-util = { version = "0.3", default-features = false, features = ["sink"] }
parking_lot = { version = "0.12", features = ["deadlock_detection"] }
Expand Down
17 changes: 11 additions & 6 deletions livekit-ffi/protocol/room.proto
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ message PublishDataRequest {
uint64 local_participant_handle = 1;
uint64 data_ptr = 2;
uint64 data_len = 3;
DataPacketKind kind = 4;
repeated string destination_sids = 5; // destination
bool reliable = 4;
repeated string destination_sids = 5 [deprecated=true];
optional string topic = 6;
repeated string destination_identities = 7;
}
message PublishDataResponse {
uint64 async_id = 1;
Expand Down Expand Up @@ -160,7 +161,6 @@ message GetSessionStatsCallback {
repeated RtcStats subscriber_stats = 4;
}


//
// Options
//
Expand Down Expand Up @@ -273,9 +273,10 @@ message RoomEvent {
TrackUnmuted track_unmuted = 12;
ActiveSpeakersChanged active_speakers_changed = 13;
RoomMetadataChanged room_metadata_changed = 14;
ParticipantMetadataChanged participant_metadata_changed = 15;
ParticipantNameChanged participant_name_changed = 16;
ConnectionQualityChanged connection_quality_changed = 17;
RoomSidChanged room_sid_changed = 15;
ParticipantMetadataChanged participant_metadata_changed = 16;
ParticipantNameChanged participant_name_changed = 17;
ConnectionQualityChanged connection_quality_changed = 18;
ConnectionStateChanged connection_state_changed = 19;
// Connected connected = 20;
Disconnected disconnected = 21;
Expand Down Expand Up @@ -364,6 +365,10 @@ message RoomMetadataChanged {
string metadata = 1;
}

message RoomSidChanged {
string sid = 1;
}

message ParticipantMetadataChanged {
string participant_sid = 1;
string metadata = 2;
Expand Down
6 changes: 5 additions & 1 deletion livekit-ffi/src/conversion/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ impl From<proto::AudioEncoding> for AudioEncoding {
impl From<&FfiRoom> for proto::RoomInfo {
fn from(value: &FfiRoom) -> Self {
let room = &value.inner.room;
Self { sid: room.sid().into(), name: room.name(), metadata: room.metadata() }
Self {
sid: room.maybe_sid().unwrap_or_default().into(),
name: room.name(),
metadata: room.metadata(),
}
}
}
51 changes: 30 additions & 21 deletions livekit-ffi/src/livekit.proto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @generated
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FrameCryptor {
Expand Down Expand Up @@ -2019,13 +2018,15 @@ pub struct PublishDataRequest {
pub data_ptr: u64,
#[prost(uint64, tag="3")]
pub data_len: u64,
#[prost(enumeration="DataPacketKind", tag="4")]
pub kind: i32,
/// destination
#[prost(bool, tag="4")]
pub reliable: bool,
#[deprecated]
#[prost(string, repeated, tag="5")]
pub destination_sids: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, optional, tag="6")]
pub topic: ::core::option::Option<::prost::alloc::string::String>,
#[prost(string, repeated, tag="7")]
pub destination_identities: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand All @@ -2044,20 +2045,6 @@ pub struct PublishDataCallback {
/// Publish transcription messages to room
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TranscriptionSegment {
#[prost(string, tag="1")]
pub id: ::prost::alloc::string::String,
#[prost(string, tag="2")]
pub text: ::prost::alloc::string::String,
#[prost(uint64, tag="3")]
pub start_time: u64,
#[prost(uint64, tag="4")]
pub end_time: u64,
#[prost(bool, tag="5")]
pub r#final: bool,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PublishTranscriptionRequest {
#[prost(uint64, tag="1")]
pub local_participant_handle: u64,
Expand Down Expand Up @@ -2240,6 +2227,20 @@ pub struct RoomOptions {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TranscriptionSegment {
#[prost(string, tag="1")]
pub id: ::prost::alloc::string::String,
#[prost(string, tag="2")]
pub text: ::prost::alloc::string::String,
#[prost(uint64, tag="3")]
pub start_time: u64,
#[prost(uint64, tag="4")]
pub end_time: u64,
#[prost(bool, tag="5")]
pub r#final: bool,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BufferInfo {
#[prost(uint64, tag="1")]
pub data_ptr: u64,
Expand All @@ -2259,7 +2260,7 @@ pub struct OwnedBuffer {
pub struct RoomEvent {
#[prost(uint64, tag="1")]
pub room_handle: u64,
#[prost(oneof="room_event::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 21, 22, 23, 24, 25, 26")]
#[prost(oneof="room_event::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26")]
pub message: ::core::option::Option<room_event::Message>,
}
/// Nested message and enum types in `RoomEvent`.
Expand Down Expand Up @@ -2294,10 +2295,12 @@ pub mod room_event {
#[prost(message, tag="14")]
RoomMetadataChanged(super::RoomMetadataChanged),
#[prost(message, tag="15")]
ParticipantMetadataChanged(super::ParticipantMetadataChanged),
RoomSidChanged(super::RoomSidChanged),
#[prost(message, tag="16")]
ParticipantNameChanged(super::ParticipantNameChanged),
ParticipantMetadataChanged(super::ParticipantMetadataChanged),
#[prost(message, tag="17")]
ParticipantNameChanged(super::ParticipantNameChanged),
#[prost(message, tag="18")]
ConnectionQualityChanged(super::ConnectionQualityChanged),
#[prost(message, tag="19")]
ConnectionStateChanged(super::ConnectionStateChanged),
Expand Down Expand Up @@ -2445,6 +2448,12 @@ pub struct RoomMetadataChanged {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RoomSidChanged {
#[prost(string, tag="1")]
pub sid: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ParticipantMetadataChanged {
#[prost(string, tag="1")]
pub participant_sid: ::prost::alloc::string::String,
Expand Down
27 changes: 21 additions & 6 deletions livekit-ffi/src/server/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ impl FfiRoom {
},
));

// Update Room SID on promise resolve
let room_handle = inner.handle_id.clone();
server.async_runtime.spawn(async move {
let _ = server.send_event(proto::ffi_event::Message::RoomEvent(
proto::RoomEvent {
room_handle,
message: Some(proto::room_event::Message::RoomSidChanged(
proto::RoomSidChanged {
sid: ffi_room.inner.room.sid().await.into(),
},
)),
},
));
});

// Forward events
let event_handle = server.watch_panic({
let close_rx = close_rx.resubscribe();
Expand Down Expand Up @@ -237,20 +252,20 @@ impl RoomInner {
}
.to_vec();

let kind = publish.kind();
let destination_sids = publish.destination_sids;
let reliable = publish.reliable;
let topic = publish.topic;
let destination_identities = publish.destination_identities;
let async_id = server.next_id();

if let Err(err) = self.data_tx.send(FfiDataPacket {
payload: DataPacket {
payload: data.to_vec(), // Avoid copy?
kind: kind.into(),
topic: publish.topic,
destination_sids: destination_sids
reliable,
topic,
destination_identities: destination_identities
.into_iter()
.map(|str| str.try_into().unwrap())
.collect(),
destination_identities: Vec::new(), // TODO
},
async_id,
}) {
Expand Down
4 changes: 2 additions & 2 deletions livekit-protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "livekit-protocol"
version = "0.3.2"
version = "0.3.3"
edition = "2021"
license = "Apache-2.0"
description = "Livekit protocol and utilities for the Rust SDK"
repository = "https://github.com/livekit/rust-sdks"

[dependencies]
livekit-runtime = { path = "../livekit-runtime", version = "0.3.0", features = [ "tokio" ] }
tokio = { version = "1", default-features = false, features = [ "sync", "macros", "time", "net" ] }
tokio = { version = "1", default-features = false, features = [ "sync", "macros", "time", "net", "rt" ] }
futures-util = { version = "0.3", features = ["sink"] }
parking_lot = "0.12"
prost = "0.12"
Expand Down
1 change: 1 addition & 0 deletions livekit-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
pub mod debouncer;
pub mod enum_dispatch;
pub mod observer;
pub mod promise;

include!("livekit.rs");

Expand Down
50 changes: 50 additions & 0 deletions livekit-protocol/src/promise.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 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 tokio::sync::{oneshot, Mutex};

pub struct Promise<T> {
tx: Mutex<Option<oneshot::Sender<T>>>,
rx: Mutex<Option<oneshot::Receiver<T>>>,
result: Mutex<Option<T>>,
}

impl<T: Clone> Promise<T> {
pub fn new() -> Self {
let (tx, rx) = oneshot::channel();
Self { tx: Mutex::new(Some(tx)), rx: Mutex::new(Some(rx)), result: Default::default() }
}

pub fn resolve(&self, result: T) -> Result<(), &'static str> {
let mut tx = self.tx.try_lock().unwrap();
if tx.is_some() {
let _ = tx.take().unwrap().send(result);
Ok(())
} else {
Err("promise already used")
}
}

pub async fn result(&self) -> T {
let mut rx = self.rx.lock().await;
if rx.is_some() {
self.result.lock().await.replace(rx.take().unwrap().await.unwrap());
}
self.result.lock().await.clone().unwrap()
}

pub fn try_result(&self) -> Option<T> {
self.result.try_lock().unwrap().clone()
}
}
4 changes: 2 additions & 2 deletions livekit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "livekit"
version = "0.3.2"
version = "0.4.0"
edition = "2021"
license = "Apache-2.0"
description = "Rust Client SDK for LiveKit"
Expand Down Expand Up @@ -30,7 +30,7 @@ __lk-internal = []
livekit-runtime = { path = "../livekit-runtime", version = "0.3.0", default-features = false }
livekit-api = { path = "../livekit-api", version = "0.3.2", default-features = false }
libwebrtc = { path = "../libwebrtc", version = "0.3.2" }
livekit-protocol = { path = "../livekit-protocol", version = "0.3.2" }
livekit-protocol = { path = "../livekit-protocol", version = "0.3.3" }
prost = "0.12"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion livekit/src/room/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct ParticipantIdentity(pub String);
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct TrackSid(String);

#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct RoomSid(String);

impl From<String> for ParticipantIdentity {
Expand Down
Loading

0 comments on commit e7f2805

Please sign in to comment.