api: split voice gateway and udp features, test for voice gateway in WASM

This commit is contained in:
kozabrada123 2023-12-30 13:17:12 +01:00
parent 2b729dc8fd
commit cdba76bcf9
8 changed files with 31 additions and 22 deletions

View File

@ -100,7 +100,7 @@ jobs:
rustup target add wasm32-unknown-unknown 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 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 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: wasm-chrome:
runs-on: macos-latest runs-on: macos-latest
steps: steps:
@ -128,4 +128,4 @@ jobs:
rustup target add wasm32-unknown-unknown 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 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 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" CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt, voice_gateway"

View File

@ -16,7 +16,9 @@ backend = ["dep:poem", "dep:sqlx"]
rt-multi-thread = ["tokio/rt-multi-thread"] rt-multi-thread = ["tokio/rt-multi-thread"]
rt = ["tokio/rt"] rt = ["tokio/rt"]
client = [] client = []
voice = ["dep:discortp", "dep:crypto_secretbox"] voice = ["voice_udp", "voice_gateway"]
voice_udp = ["dep:discortp", "dep:crypto_secretbox"]
voice_gateway = []
[dependencies] [dependencies]
tokio = { version = "1.34.0", features = ["macros", "sync"] } tokio = { version = "1.34.0", features = ["macros", "sync"] }

View File

@ -125,7 +125,7 @@ like "proxy connection checking" are already disabled on this version, which oth
### wasm ### wasm
To test for wasm, you will need to `cargo install wasm-pack`. You can then run To test for wasm, you will need to `cargo install wasm-pack`. You can then run
`wasm-pack test --<chrome/firefox/safari> --headless -- --target wasm32-unknown-unknown --features="rt, client" --no-default-features` `wasm-pack test --<chrome/firefox/safari> --headless -- --target wasm32-unknown-unknown --features="rt, client, voice_gateway" --no-default-features`
to run the tests for wasm. to run the tests for wasm.
## Versioning ## Versioning

View File

@ -128,7 +128,7 @@ pub mod instance;
#[cfg(feature = "client")] #[cfg(feature = "client")]
pub mod ratelimiter; pub mod ratelimiter;
pub mod types; pub mod types;
#[cfg(all(feature = "client", feature = "voice"))] #[cfg(all(feature = "client", any(feature = "voice_udp", feature = "voice_gateway")))]
pub mod voice; pub mod voice;
#[derive(Clone, Default, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Clone, Default, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]

View File

@ -1,23 +1,23 @@
#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] #[cfg(all(not(target_arch = "wasm32"), feature = "voice_gateway"))]
pub mod tungstenite; pub mod tungstenite;
#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] #[cfg(all(not(target_arch = "wasm32"), feature = "voice_gateway"))]
pub use tungstenite::*; pub use tungstenite::*;
#[cfg(all(target_arch = "wasm32", feature = "client"))] #[cfg(all(target_arch = "wasm32", feature = "voice_gateway"))]
pub mod wasm; pub mod wasm;
#[cfg(all(target_arch = "wasm32", feature = "client"))] #[cfg(all(target_arch = "wasm32", feature = "voice_gateway"))]
pub use wasm::*; 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; 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; 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; 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; 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; 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; pub type WebSocketBackend = wasm::WasmBackend;

View File

@ -1,10 +1,15 @@
//! Module for all voice functionality within chorus. //! Module for all voice functionality within chorus.
mod crypto; #[cfg(feature = "voice_gateway")]
pub mod gateway; pub mod gateway;
mod crypto;
#[cfg(all(feature = "voice_udp", feature = "voice_gateway"))]
pub mod handler; pub mod handler;
#[cfg(feature = "voice_udp")]
pub mod udp; pub mod udp;
#[cfg(feature = "voice_udp")]
pub mod voice_data; pub mod voice_data;
// Pub use this so users can interact with packet types if they want // Pub use this so users can interact with packet types if they want
#[cfg(feature = "voice_udp")]
pub use discortp; pub use discortp;

View File

@ -1,12 +1,12 @@
#[cfg(all(not(target_arch = "wasm32"), feature = "voice"))] #[cfg(all(not(target_arch = "wasm32"), feature = "voice_udp"))]
pub mod tokio; pub mod tokio;
#[cfg(all(not(target_arch = "wasm32"), feature = "voice"))] #[cfg(all(not(target_arch = "wasm32"), feature = "voice_udp"))]
pub use tokio::*; 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; 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; 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."); 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.");

View File

@ -3,7 +3,9 @@ use discortp::discord::IpDiscovery;
use crate::types::{SessionDescription, Snowflake, VoiceReady, VoiceServerUpdate}; use crate::types::{SessionDescription, Snowflake, VoiceReady, VoiceServerUpdate};
#[derive(Debug, Default)] #[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 struct VoiceData {
pub server_data: Option<VoiceServerUpdate>, pub server_data: Option<VoiceServerUpdate>,
pub ready_data: Option<VoiceReady>, pub ready_data: Option<VoiceReady>,