diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 0cf6fd9..3732402 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -100,7 +100,7 @@ jobs: rustup target add wasm32-unknown-unknown curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force - GECKODRIVER=$(which geckodriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + GECKODRIVER=$(which geckodriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt, voice_gateway" wasm-chrome: runs-on: macos-latest steps: @@ -128,4 +128,4 @@ jobs: rustup target add wasm32-unknown-unknown curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force - CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file + CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt, voice_gateway" diff --git a/Cargo.toml b/Cargo.toml index ae57d07..0c88387 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,9 @@ backend = ["dep:poem", "dep:sqlx"] rt-multi-thread = ["tokio/rt-multi-thread"] rt = ["tokio/rt"] client = [] -voice = ["dep:discortp", "dep:crypto_secretbox"] +voice = ["voice_udp", "voice_gateway"] +voice_udp = ["dep:discortp", "dep:crypto_secretbox"] +voice_gateway = [] [dependencies] tokio = { version = "1.34.0", features = ["macros", "sync"] } diff --git a/README.md b/README.md index c02da77..af2ab6e 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ like "proxy connection checking" are already disabled on this version, which oth ### wasm To test for wasm, you will need to `cargo install wasm-pack`. You can then run -`wasm-pack test -- --headless -- --target wasm32-unknown-unknown --features="rt, client" --no-default-features` +`wasm-pack test -- --headless -- --target wasm32-unknown-unknown --features="rt, client, voice_gateway" --no-default-features` to run the tests for wasm. ## Versioning diff --git a/src/lib.rs b/src/lib.rs index 1fd125c..abe8101 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -128,7 +128,7 @@ pub mod instance; #[cfg(feature = "client")] pub mod ratelimiter; pub mod types; -#[cfg(all(feature = "client", feature = "voice"))] +#[cfg(all(feature = "client", any(feature = "voice_udp", feature = "voice_gateway")))] pub mod voice; #[derive(Clone, Default, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/src/voice/gateway/backends/mod.rs b/src/voice/gateway/backends/mod.rs index edb5dc9..dfd00b5 100644 --- a/src/voice/gateway/backends/mod.rs +++ b/src/voice/gateway/backends/mod.rs @@ -1,23 +1,23 @@ -#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "voice_gateway"))] pub mod tungstenite; -#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "voice_gateway"))] pub use tungstenite::*; -#[cfg(all(target_arch = "wasm32", feature = "client"))] +#[cfg(all(target_arch = "wasm32", feature = "voice_gateway"))] pub mod wasm; -#[cfg(all(target_arch = "wasm32", feature = "client"))] +#[cfg(all(target_arch = "wasm32", feature = "voice_gateway"))] pub use wasm::*; -#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "voice_gateway"))] pub type Sink = tungstenite::TungsteniteSink; -#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "voice_gateway"))] pub type Stream = tungstenite::TungsteniteStream; -#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "voice_gateway"))] pub type WebSocketBackend = tungstenite::TungsteniteBackend; -#[cfg(all(target_arch = "wasm32", feature = "client"))] +#[cfg(all(target_arch = "wasm32", feature = "voice_gateway"))] pub type Sink = wasm::WasmSink; -#[cfg(all(target_arch = "wasm32", feature = "client"))] +#[cfg(all(target_arch = "wasm32", feature = "voice_gateway"))] pub type Stream = wasm::WasmStream; -#[cfg(all(target_arch = "wasm32", feature = "client"))] +#[cfg(all(target_arch = "wasm32", feature = "voice_gateway"))] pub type WebSocketBackend = wasm::WasmBackend; diff --git a/src/voice/mod.rs b/src/voice/mod.rs index 621d3c0..660f806 100644 --- a/src/voice/mod.rs +++ b/src/voice/mod.rs @@ -1,10 +1,15 @@ //! Module for all voice functionality within chorus. -mod crypto; +#[cfg(feature = "voice_gateway")] pub mod gateway; +mod crypto; +#[cfg(all(feature = "voice_udp", feature = "voice_gateway"))] pub mod handler; +#[cfg(feature = "voice_udp")] pub mod udp; +#[cfg(feature = "voice_udp")] pub mod voice_data; // Pub use this so users can interact with packet types if they want +#[cfg(feature = "voice_udp")] pub use discortp; diff --git a/src/voice/udp/backends/mod.rs b/src/voice/udp/backends/mod.rs index bbf8d9a..4059fbe 100644 --- a/src/voice/udp/backends/mod.rs +++ b/src/voice/udp/backends/mod.rs @@ -1,12 +1,12 @@ -#[cfg(all(not(target_arch = "wasm32"), feature = "voice"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "voice_udp"))] pub mod tokio; -#[cfg(all(not(target_arch = "wasm32"), feature = "voice"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "voice_udp"))] pub use tokio::*; -#[cfg(all(not(target_arch = "wasm32"), feature = "voice"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "voice_udp"))] pub type UdpSocket = tokio::TokioSocket; -#[cfg(all(not(target_arch = "wasm32"), feature = "voice"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "voice_udp"))] pub type UdpBackend = tokio::TokioBackend; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", feature = "voice_udp"))] compile_error!("UDP Voice support is not (and will likely never be) supported for WASM. This is because UDP cannot be used in the browser. We are however looking into Webrtc for WASM voice support."); diff --git a/src/voice/voice_data.rs b/src/voice/voice_data.rs index 5d37d9c..064ebda 100644 --- a/src/voice/voice_data.rs +++ b/src/voice/voice_data.rs @@ -3,7 +3,9 @@ use discortp::discord::IpDiscovery; use crate::types::{SessionDescription, Snowflake, VoiceReady, VoiceServerUpdate}; #[derive(Debug, Default)] -/// Saves data shared between parts of the voice architecture +/// Saves data shared between parts of the voice architecture; +/// +/// Struct used to give the Udp connection data received from the gateway. pub struct VoiceData { pub server_data: Option, pub ready_data: Option,