Skip to content

Commit

Permalink
Avoid tokio-stream dependency when using a runtime other than tokio (#…
Browse files Browse the repository at this point in the history
…349)

* Fix peer connection factory test - use tokio test macro

* Avoid tokio-stream dependency when not using tokio runtime
  • Loading branch information
maxbrunsfeld committed Jun 20, 2024
1 parent 82b12a8 commit 9c2a467
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion libwebrtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ livekit-runtime = { path = "../livekit-runtime", version = "0.3.0" }
lazy_static = "1.4"
parking_lot = { version = "0.12" }
tokio = { version = "1", default-features = false, features = ["sync", "macros"] }
tokio-stream = "0.1.14"
cxx = "1.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion libwebrtc/src/audio_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod native {
task::{Context, Poll},
};

use tokio_stream::Stream;
use livekit_runtime::Stream;

use super::stream_imp;
use crate::{audio_frame::AudioFrame, audio_track::RtcAudioTrack};
Expand Down
2 changes: 1 addition & 1 deletion libwebrtc/src/native/audio_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use std::{
};

use cxx::SharedPtr;
use livekit_runtime::Stream;
use tokio::sync::mpsc;
use tokio_stream::Stream;
use webrtc_sys::audio_track as sys_at;

use crate::{audio_frame::AudioFrame, audio_track::RtcAudioTrack};
Expand Down
4 changes: 2 additions & 2 deletions libwebrtc/src/native/peer_connection_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl PeerConnectionFactory {
mod tests {
use super::*;

#[test]
fn test_peer_connection_factory() {
#[tokio::test]
async fn test_peer_connection_factory() {
let _ = env_logger::builder().is_test(true).try_init();

let factory = PeerConnectionFactory::default();
Expand Down
2 changes: 1 addition & 1 deletion libwebrtc/src/native/video_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use std::{
};

use cxx::{SharedPtr, UniquePtr};
use livekit_runtime::Stream;
use tokio::sync::mpsc;
use tokio_stream::Stream;
use webrtc_sys::video_track as sys_vt;

use super::video_frame::new_video_frame_buffer;
Expand Down
3 changes: 1 addition & 2 deletions libwebrtc/src/video_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ pub mod native {
task::{Context, Poll},
};

use tokio_stream::Stream;

use super::stream_imp;
use crate::{video_frame::BoxVideoFrame, video_track::RtcVideoTrack};
use livekit_runtime::Stream;

pub struct NativeVideoStream {
pub(crate) handle: stream_imp::NativeVideoStream,
Expand Down
5 changes: 3 additions & 2 deletions livekit-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
repository = "https://github.com/livekit/rust-sdks"

[features]
tokio = ["dep:tokio"]
tokio = ["dep:tokio", "dep:tokio-stream"]
async = [
"dep:async-std",
"dep:futures",
Expand All @@ -21,11 +21,12 @@ tokio = { version = "1", default-features = false, optional = true, features = [
"rt",
"rt-multi-thread",
] }
tokio-stream = { version = "0.1.14", optional = true }

# dispatcher and async-std
async-std = { version = "1", optional = true }
futures = { version = "0.3.30", optional = true }
async-io = { version = "2.3.1", optional = true }

# dispatcher
async-task = {version = "4.7.0", optional = true }
async-task = {version = "4.7.0", optional = true }
7 changes: 4 additions & 3 deletions livekit-runtime/src/async_std.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use futures::{Future, FutureExt, StreamExt};
use std::time::Duration;
pub type JoinHandle<T> = async_std::task::JoinHandle<T>;
// async_std::future::timeout uses async_io under the hood

pub use async_std::future::timeout;
pub use async_std::net::TcpStream;
pub use async_std::task::spawn;
use futures::{Future, FutureExt, StreamExt};
pub use async_std::task::JoinHandle;
pub use futures::Stream;
pub use std::time::Instant;

/// This is semantically equivalent to Tokio's MissedTickBehavior:
Expand Down
1 change: 1 addition & 0 deletions livekit-runtime/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{sync::OnceLock, task::Poll, time::Duration};

pub use async_std::net::TcpStream;
pub use async_task::Runnable;
pub use futures::Stream;
pub use std::time::Instant;

/// This is semantically equivalent to Tokio's MissedTickBehavior:
Expand Down
1 change: 1 addition & 0 deletions livekit-runtime/src/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub use tokio::time::sleep;
pub use tokio::time::timeout;
pub use tokio::time::Instant;
pub use tokio::time::MissedTickBehavior;
pub use tokio_stream::Stream;

pub type JoinHandle<T> = TokioJoinHandle<T>;
pub type Interval = tokio::time::Interval;
Expand Down

0 comments on commit 9c2a467

Please sign in to comment.