diff --git a/Cargo.lock b/Cargo.lock index be8192a..e41d159 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,7 +233,6 @@ dependencies = [ "reqwest", "rustls", "rustls-native-certs", - "safina-timer", "serde", "serde-aux", "serde_json", @@ -1801,15 +1800,6 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" -[[package]] -name = "safina-timer" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1081a264d1a3e81b75c4bcd5696094fb6ce470c2ded14cbd47bcb5229079b9df" -dependencies = [ - "once_cell", -] - [[package]] name = "salsa20" version = "0.10.2" diff --git a/Cargo.toml b/Cargo.toml index 9c6fe21..71134de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ website = ["https://discord.com/invite/m3FpcapGDD"] [features] -default = ["client", "rt-multi-thread"] +default = ["client", "rt-multi-thread", "voice"] backend = ["dep:poem", "dep:sqlx"] rt-multi-thread = ["tokio/rt-multi-thread"] rt = ["tokio/rt"] @@ -57,7 +57,6 @@ sqlx = { version = "0.7.3", features = [ ], optional = true } discortp = { version = "0.5.0", optional = true, features = ["rtp", "discord", "demux"] } crypto_secretbox = {version = "0.1.1", optional = true} -safina-timer = "0.1.11" rand = "0.8.5" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/src/voice/gateway/heartbeat.rs b/src/voice/gateway/heartbeat.rs index 566a778..50f30c2 100644 --- a/src/voice/gateway/heartbeat.rs +++ b/src/voice/gateway/heartbeat.rs @@ -1,12 +1,25 @@ -use std::{ - sync::Arc, - time::{Duration, Instant}, -}; - use futures_util::SinkExt; use log::*; -use safina_timer::sleep_until; -use tokio::sync::{mpsc::Sender, Mutex}; + +#[cfg(not(target_arch = "wasm32"))] +use tokio::time::Instant; +#[cfg(target_arch = "wasm32")] +use wasmtimer::std::Instant; + +#[cfg(not(target_arch = "wasm32"))] +use tokio::time::sleep_until; +#[cfg(target_arch = "wasm32")] +use wasmtimer::tokio::sleep_until; + +use std::{sync::Arc, time::Duration}; + +use tokio::sync::{ + mpsc::{Receiver, Sender}, + Mutex, +}; + +#[cfg(not(target_arch = "wasm32"))] +use tokio::task; use crate::{ gateway::heartbeat::HEARTBEAT_ACK_TIMEOUT, @@ -37,7 +50,7 @@ impl VoiceHeartbeatHandler { let kill_receive = kill_rc.resubscribe(); #[cfg(not(target_arch = "wasm32"))] - tokio::task::spawn(async move { + task::spawn(async move { Self::heartbeat_task( websocket_tx, heartbeat_interval, @@ -73,15 +86,13 @@ impl VoiceHeartbeatHandler { websocket_tx: Arc>, heartbeat_interval: Duration, starting_nonce: u64, - mut receive: tokio::sync::mpsc::Receiver, + mut receive: Receiver, mut kill_receive: tokio::sync::broadcast::Receiver<()>, ) { let mut last_heartbeat_timestamp: Instant = Instant::now(); let mut last_heartbeat_acknowledged = true; let mut nonce: u64 = starting_nonce; - safina_timer::start_timer_thread(); - loop { if kill_receive.try_recv().is_ok() { trace!("VGW: Closing heartbeat task"); diff --git a/tests/gateway.rs b/tests/gateway.rs index de78eb2..8146243 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -12,6 +12,16 @@ use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); +#[cfg(not(target_arch = "wasm32"))] +use tokio::time::Instant; +#[cfg(target_arch = "wasm32")] +use wasmtimer::std::Instant; + +#[cfg(not(target_arch = "wasm32"))] +use tokio::time::sleep; +#[cfg(target_arch = "wasm32")] +use wasmtimer::tokio::sleep; + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] /// Tests establishing a connection (hello and heartbeats) on the local gateway; @@ -61,11 +71,9 @@ async fn test_gateway_authenticate() { gateway.send_identify(identify).await; - let current_time = std::time::Instant::now(); - tokio::select! { // Fail, we timed out waiting for it - () = safina_timer::sleep_until(current_time + Duration::from_secs(20)) => { + () = sleep(Duration::from_secs(20)) => { println!("Timed out waiting for event, failing.."); assert!(false); }