chorus/tests/gateway.rs

302 lines
11 KiB
Rust
Raw Permalink Normal View History

2024-01-30 17:19:34 +01:00
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
2023-06-08 19:51:32 +02:00
mod common;
Primitive voice implementation (feature/voice) (#457) * Add Webrtc Identify & Ready * Add more webrtc typings * Attempt an untested voice gateway implementation * fmt * Merge with main * Same allow as for voice as normal gateway * Test error observer * Minor updates * More derives * Even more derives * Small types update * e * Minor doc fixes * Modernise voice gateway * Add default impl for voicegatewayerror * Make voice event fields pub * Event updates via the scientific method * ?? * Fix bad request in voice gateway init * Voice gateway updates * Fix error failing to 'deserialize' properly * Update voice identify * Clarify FIXME related to #430 * Update to v7 * Create seperate voice_gateway.rs and voice_udp.rs * Restructure voice to new module * fix: deserialization error in speaking bitflags * feat: kinda janky ip discovery impl * feat: return ip discovery data + minor update * feat: packet parsing! * fix: voice works again * feat: add voice_media_sink_wants (comitting uncommited changes to merge) * chore: rename events/webrtc to events/voice_gateway * Add UdpHandle * chore: clippy + other misc updates * fix: attempt to fix failing wasm build * chore: yes clippy, that is indeed an unneeded return statement * feat: add VoiceData struct * feat: add VoiceData reference to UdpHandler * feat: decryption? * chore: formatting * feat: add ssrc definition (op 12) * feat: add untested sending & asbtract nonce generation * feat: Public api! (sorta) * small updates * feat: add sequence number * chore: yes * feat: merge VoiceHandler into official development * chore: yes clippy, you are special * fix: duplicated gateway events * feat: first try at vgw wasm compat * fix: blunder * fix: gateway connect using wrong url * fix: properly using encrypted data, bad practice for buffer creation * chore: split voice udp * feat: udp error handling, create udp/backends * fix: its the same * chore: clarify UDP on WASM * api: split voice gateway and udp features, test for voice gateway in WASM * feat: new encryption modes, minor code quality * docs: document voice encryption modes * chore: unused imports * chore: update getrandom version to match wasm version * chore: update on packet size FIXME * drop buf asap * Okay can't do that actually * tests: add nonce test * normal tests work? * docs: fix doc warning, fix incorrect refrences to 'webrtc' * chore: json isn't a doc test * tests: better gateway auth test * testing tests * update voice heartbeat, fix the new test issue * committed too much * fix: unused import * fix: use ip discovery address as string, not as Vec<u8> * chore: less obnoxious logging * chore: better unimplemented voice modes handling * chore: remove unused variable * chore: use matches macro * add voice examples, make gateway ones clearer * rename voice example * chore: remove unused VoiceHandler * fix: implement gateway Reconnect and InvalidSession * Typo Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * Fix a bunch of typos Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * fix: error handling while loading native certs * fix: guh * use be for nonce bytes * fix: refactor gw and vgw closures * remove outdated docs --------- Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
use std::sync::Arc;
use std::time::Duration;
use async_trait::async_trait;
use chorus::errors::GatewayError;
2023-11-19 19:12:29 +01:00
use chorus::gateway::*;
2024-01-24 23:01:38 +01:00
use chorus::types::{
Primitive voice implementation (feature/voice) (#457) * Add Webrtc Identify & Ready * Add more webrtc typings * Attempt an untested voice gateway implementation * fmt * Merge with main * Same allow as for voice as normal gateway * Test error observer * Minor updates * More derives * Even more derives * Small types update * e * Minor doc fixes * Modernise voice gateway * Add default impl for voicegatewayerror * Make voice event fields pub * Event updates via the scientific method * ?? * Fix bad request in voice gateway init * Voice gateway updates * Fix error failing to 'deserialize' properly * Update voice identify * Clarify FIXME related to #430 * Update to v7 * Create seperate voice_gateway.rs and voice_udp.rs * Restructure voice to new module * fix: deserialization error in speaking bitflags * feat: kinda janky ip discovery impl * feat: return ip discovery data + minor update * feat: packet parsing! * fix: voice works again * feat: add voice_media_sink_wants (comitting uncommited changes to merge) * chore: rename events/webrtc to events/voice_gateway * Add UdpHandle * chore: clippy + other misc updates * fix: attempt to fix failing wasm build * chore: yes clippy, that is indeed an unneeded return statement * feat: add VoiceData struct * feat: add VoiceData reference to UdpHandler * feat: decryption? * chore: formatting * feat: add ssrc definition (op 12) * feat: add untested sending & asbtract nonce generation * feat: Public api! (sorta) * small updates * feat: add sequence number * chore: yes * feat: merge VoiceHandler into official development * chore: yes clippy, you are special * fix: duplicated gateway events * feat: first try at vgw wasm compat * fix: blunder * fix: gateway connect using wrong url * fix: properly using encrypted data, bad practice for buffer creation * chore: split voice udp * feat: udp error handling, create udp/backends * fix: its the same * chore: clarify UDP on WASM * api: split voice gateway and udp features, test for voice gateway in WASM * feat: new encryption modes, minor code quality * docs: document voice encryption modes * chore: unused imports * chore: update getrandom version to match wasm version * chore: update on packet size FIXME * drop buf asap * Okay can't do that actually * tests: add nonce test * normal tests work? * docs: fix doc warning, fix incorrect refrences to 'webrtc' * chore: json isn't a doc test * tests: better gateway auth test * testing tests * update voice heartbeat, fix the new test issue * committed too much * fix: unused import * fix: use ip discovery address as string, not as Vec<u8> * chore: less obnoxious logging * chore: better unimplemented voice modes handling * chore: remove unused variable * chore: use matches macro * add voice examples, make gateway ones clearer * rename voice example * chore: remove unused VoiceHandler * fix: implement gateway Reconnect and InvalidSession * Typo Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * Fix a bunch of typos Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * fix: error handling while loading native certs * fix: guh * use be for nonce bytes * fix: refactor gw and vgw closures * remove outdated docs --------- Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
self, Channel, ChannelCreateSchema, ChannelModifySchema, GatewayReady, IntoShared,
RoleCreateModifySchema, RoleObject,
2024-01-24 23:01:38 +01:00
};
use pubserve::Subscriber;
2023-11-20 14:03:06 +01:00
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test_configure!(run_in_browser);
Primitive voice implementation (feature/voice) (#457) * Add Webrtc Identify & Ready * Add more webrtc typings * Attempt an untested voice gateway implementation * fmt * Merge with main * Same allow as for voice as normal gateway * Test error observer * Minor updates * More derives * Even more derives * Small types update * e * Minor doc fixes * Modernise voice gateway * Add default impl for voicegatewayerror * Make voice event fields pub * Event updates via the scientific method * ?? * Fix bad request in voice gateway init * Voice gateway updates * Fix error failing to 'deserialize' properly * Update voice identify * Clarify FIXME related to #430 * Update to v7 * Create seperate voice_gateway.rs and voice_udp.rs * Restructure voice to new module * fix: deserialization error in speaking bitflags * feat: kinda janky ip discovery impl * feat: return ip discovery data + minor update * feat: packet parsing! * fix: voice works again * feat: add voice_media_sink_wants (comitting uncommited changes to merge) * chore: rename events/webrtc to events/voice_gateway * Add UdpHandle * chore: clippy + other misc updates * fix: attempt to fix failing wasm build * chore: yes clippy, that is indeed an unneeded return statement * feat: add VoiceData struct * feat: add VoiceData reference to UdpHandler * feat: decryption? * chore: formatting * feat: add ssrc definition (op 12) * feat: add untested sending & asbtract nonce generation * feat: Public api! (sorta) * small updates * feat: add sequence number * chore: yes * feat: merge VoiceHandler into official development * chore: yes clippy, you are special * fix: duplicated gateway events * feat: first try at vgw wasm compat * fix: blunder * fix: gateway connect using wrong url * fix: properly using encrypted data, bad practice for buffer creation * chore: split voice udp * feat: udp error handling, create udp/backends * fix: its the same * chore: clarify UDP on WASM * api: split voice gateway and udp features, test for voice gateway in WASM * feat: new encryption modes, minor code quality * docs: document voice encryption modes * chore: unused imports * chore: update getrandom version to match wasm version * chore: update on packet size FIXME * drop buf asap * Okay can't do that actually * tests: add nonce test * normal tests work? * docs: fix doc warning, fix incorrect refrences to 'webrtc' * chore: json isn't a doc test * tests: better gateway auth test * testing tests * update voice heartbeat, fix the new test issue * committed too much * fix: unused import * fix: use ip discovery address as string, not as Vec<u8> * chore: less obnoxious logging * chore: better unimplemented voice modes handling * chore: remove unused variable * chore: use matches macro * add voice examples, make gateway ones clearer * rename voice example * chore: remove unused VoiceHandler * fix: implement gateway Reconnect and InvalidSession * Typo Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * Fix a bunch of typos Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * fix: error handling while loading native certs * fix: guh * use be for nonce bytes * fix: refactor gw and vgw closures * remove outdated docs --------- Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
#[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)]
2023-06-08 19:51:32 +02:00
/// Tests establishing a connection (hello and heartbeats) on the local gateway;
async fn test_gateway_establish() {
let bundle = common::setup().await;
let _: GatewayHandle = Gateway::spawn(bundle.urls.wss.clone(), GatewayOptions::default())
.await
.unwrap();
2023-07-22 14:38:55 +02:00
common::teardown(bundle).await
2023-06-08 19:51:32 +02:00
}
Primitive voice implementation (feature/voice) (#457) * Add Webrtc Identify & Ready * Add more webrtc typings * Attempt an untested voice gateway implementation * fmt * Merge with main * Same allow as for voice as normal gateway * Test error observer * Minor updates * More derives * Even more derives * Small types update * e * Minor doc fixes * Modernise voice gateway * Add default impl for voicegatewayerror * Make voice event fields pub * Event updates via the scientific method * ?? * Fix bad request in voice gateway init * Voice gateway updates * Fix error failing to 'deserialize' properly * Update voice identify * Clarify FIXME related to #430 * Update to v7 * Create seperate voice_gateway.rs and voice_udp.rs * Restructure voice to new module * fix: deserialization error in speaking bitflags * feat: kinda janky ip discovery impl * feat: return ip discovery data + minor update * feat: packet parsing! * fix: voice works again * feat: add voice_media_sink_wants (comitting uncommited changes to merge) * chore: rename events/webrtc to events/voice_gateway * Add UdpHandle * chore: clippy + other misc updates * fix: attempt to fix failing wasm build * chore: yes clippy, that is indeed an unneeded return statement * feat: add VoiceData struct * feat: add VoiceData reference to UdpHandler * feat: decryption? * chore: formatting * feat: add ssrc definition (op 12) * feat: add untested sending & asbtract nonce generation * feat: Public api! (sorta) * small updates * feat: add sequence number * chore: yes * feat: merge VoiceHandler into official development * chore: yes clippy, you are special * fix: duplicated gateway events * feat: first try at vgw wasm compat * fix: blunder * fix: gateway connect using wrong url * fix: properly using encrypted data, bad practice for buffer creation * chore: split voice udp * feat: udp error handling, create udp/backends * fix: its the same * chore: clarify UDP on WASM * api: split voice gateway and udp features, test for voice gateway in WASM * feat: new encryption modes, minor code quality * docs: document voice encryption modes * chore: unused imports * chore: update getrandom version to match wasm version * chore: update on packet size FIXME * drop buf asap * Okay can't do that actually * tests: add nonce test * normal tests work? * docs: fix doc warning, fix incorrect refrences to 'webrtc' * chore: json isn't a doc test * tests: better gateway auth test * testing tests * update voice heartbeat, fix the new test issue * committed too much * fix: unused import * fix: use ip discovery address as string, not as Vec<u8> * chore: less obnoxious logging * chore: better unimplemented voice modes handling * chore: remove unused variable * chore: use matches macro * add voice examples, make gateway ones clearer * rename voice example * chore: remove unused VoiceHandler * fix: implement gateway Reconnect and InvalidSession * Typo Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * Fix a bunch of typos Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * fix: error handling while loading native certs * fix: guh * use be for nonce bytes * fix: refactor gw and vgw closures * remove outdated docs --------- Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
#[derive(Debug)]
struct GatewayReadyObserver {
channel: tokio::sync::mpsc::Sender<()>,
}
#[async_trait]
impl Subscriber<GatewayReady> for GatewayReadyObserver {
Primitive voice implementation (feature/voice) (#457) * Add Webrtc Identify & Ready * Add more webrtc typings * Attempt an untested voice gateway implementation * fmt * Merge with main * Same allow as for voice as normal gateway * Test error observer * Minor updates * More derives * Even more derives * Small types update * e * Minor doc fixes * Modernise voice gateway * Add default impl for voicegatewayerror * Make voice event fields pub * Event updates via the scientific method * ?? * Fix bad request in voice gateway init * Voice gateway updates * Fix error failing to 'deserialize' properly * Update voice identify * Clarify FIXME related to #430 * Update to v7 * Create seperate voice_gateway.rs and voice_udp.rs * Restructure voice to new module * fix: deserialization error in speaking bitflags * feat: kinda janky ip discovery impl * feat: return ip discovery data + minor update * feat: packet parsing! * fix: voice works again * feat: add voice_media_sink_wants (comitting uncommited changes to merge) * chore: rename events/webrtc to events/voice_gateway * Add UdpHandle * chore: clippy + other misc updates * fix: attempt to fix failing wasm build * chore: yes clippy, that is indeed an unneeded return statement * feat: add VoiceData struct * feat: add VoiceData reference to UdpHandler * feat: decryption? * chore: formatting * feat: add ssrc definition (op 12) * feat: add untested sending & asbtract nonce generation * feat: Public api! (sorta) * small updates * feat: add sequence number * chore: yes * feat: merge VoiceHandler into official development * chore: yes clippy, you are special * fix: duplicated gateway events * feat: first try at vgw wasm compat * fix: blunder * fix: gateway connect using wrong url * fix: properly using encrypted data, bad practice for buffer creation * chore: split voice udp * feat: udp error handling, create udp/backends * fix: its the same * chore: clarify UDP on WASM * api: split voice gateway and udp features, test for voice gateway in WASM * feat: new encryption modes, minor code quality * docs: document voice encryption modes * chore: unused imports * chore: update getrandom version to match wasm version * chore: update on packet size FIXME * drop buf asap * Okay can't do that actually * tests: add nonce test * normal tests work? * docs: fix doc warning, fix incorrect refrences to 'webrtc' * chore: json isn't a doc test * tests: better gateway auth test * testing tests * update voice heartbeat, fix the new test issue * committed too much * fix: unused import * fix: use ip discovery address as string, not as Vec<u8> * chore: less obnoxious logging * chore: better unimplemented voice modes handling * chore: remove unused variable * chore: use matches macro * add voice examples, make gateway ones clearer * rename voice example * chore: remove unused VoiceHandler * fix: implement gateway Reconnect and InvalidSession * Typo Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * Fix a bunch of typos Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * fix: error handling while loading native certs * fix: guh * use be for nonce bytes * fix: refactor gw and vgw closures * remove outdated docs --------- Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
async fn update(&self, _data: &GatewayReady) {
self.channel.send(()).await.unwrap();
}
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
2023-06-08 19:51:32 +02:00
/// Tests establishing a connection and authenticating
async fn test_gateway_authenticate() {
let bundle = common::setup().await;
let gateway: GatewayHandle = Gateway::spawn(bundle.urls.wss.clone(), GatewayOptions::default())
.await
.unwrap();
2023-06-08 19:51:32 +02:00
Primitive voice implementation (feature/voice) (#457) * Add Webrtc Identify & Ready * Add more webrtc typings * Attempt an untested voice gateway implementation * fmt * Merge with main * Same allow as for voice as normal gateway * Test error observer * Minor updates * More derives * Even more derives * Small types update * e * Minor doc fixes * Modernise voice gateway * Add default impl for voicegatewayerror * Make voice event fields pub * Event updates via the scientific method * ?? * Fix bad request in voice gateway init * Voice gateway updates * Fix error failing to 'deserialize' properly * Update voice identify * Clarify FIXME related to #430 * Update to v7 * Create seperate voice_gateway.rs and voice_udp.rs * Restructure voice to new module * fix: deserialization error in speaking bitflags * feat: kinda janky ip discovery impl * feat: return ip discovery data + minor update * feat: packet parsing! * fix: voice works again * feat: add voice_media_sink_wants (comitting uncommited changes to merge) * chore: rename events/webrtc to events/voice_gateway * Add UdpHandle * chore: clippy + other misc updates * fix: attempt to fix failing wasm build * chore: yes clippy, that is indeed an unneeded return statement * feat: add VoiceData struct * feat: add VoiceData reference to UdpHandler * feat: decryption? * chore: formatting * feat: add ssrc definition (op 12) * feat: add untested sending & asbtract nonce generation * feat: Public api! (sorta) * small updates * feat: add sequence number * chore: yes * feat: merge VoiceHandler into official development * chore: yes clippy, you are special * fix: duplicated gateway events * feat: first try at vgw wasm compat * fix: blunder * fix: gateway connect using wrong url * fix: properly using encrypted data, bad practice for buffer creation * chore: split voice udp * feat: udp error handling, create udp/backends * fix: its the same * chore: clarify UDP on WASM * api: split voice gateway and udp features, test for voice gateway in WASM * feat: new encryption modes, minor code quality * docs: document voice encryption modes * chore: unused imports * chore: update getrandom version to match wasm version * chore: update on packet size FIXME * drop buf asap * Okay can't do that actually * tests: add nonce test * normal tests work? * docs: fix doc warning, fix incorrect refrences to 'webrtc' * chore: json isn't a doc test * tests: better gateway auth test * testing tests * update voice heartbeat, fix the new test issue * committed too much * fix: unused import * fix: use ip discovery address as string, not as Vec<u8> * chore: less obnoxious logging * chore: better unimplemented voice modes handling * chore: remove unused variable * chore: use matches macro * add voice examples, make gateway ones clearer * rename voice example * chore: remove unused VoiceHandler * fix: implement gateway Reconnect and InvalidSession * Typo Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * Fix a bunch of typos Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * fix: error handling while loading native certs * fix: guh * use be for nonce bytes * fix: refactor gw and vgw closures * remove outdated docs --------- Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
let (ready_send, mut ready_receive) = tokio::sync::mpsc::channel(1);
let observer = Arc::new(GatewayReadyObserver {
channel: ready_send,
});
gateway
.events
.lock()
.await
.session
.ready
.subscribe(observer);
2023-06-08 19:51:32 +02:00
let mut identify = types::GatewayIdentifyPayload::common();
2023-07-22 14:38:55 +02:00
identify.token = bundle.user.token.clone();
2023-06-08 19:51:32 +02:00
gateway.send_identify(identify).await;
Primitive voice implementation (feature/voice) (#457) * Add Webrtc Identify & Ready * Add more webrtc typings * Attempt an untested voice gateway implementation * fmt * Merge with main * Same allow as for voice as normal gateway * Test error observer * Minor updates * More derives * Even more derives * Small types update * e * Minor doc fixes * Modernise voice gateway * Add default impl for voicegatewayerror * Make voice event fields pub * Event updates via the scientific method * ?? * Fix bad request in voice gateway init * Voice gateway updates * Fix error failing to 'deserialize' properly * Update voice identify * Clarify FIXME related to #430 * Update to v7 * Create seperate voice_gateway.rs and voice_udp.rs * Restructure voice to new module * fix: deserialization error in speaking bitflags * feat: kinda janky ip discovery impl * feat: return ip discovery data + minor update * feat: packet parsing! * fix: voice works again * feat: add voice_media_sink_wants (comitting uncommited changes to merge) * chore: rename events/webrtc to events/voice_gateway * Add UdpHandle * chore: clippy + other misc updates * fix: attempt to fix failing wasm build * chore: yes clippy, that is indeed an unneeded return statement * feat: add VoiceData struct * feat: add VoiceData reference to UdpHandler * feat: decryption? * chore: formatting * feat: add ssrc definition (op 12) * feat: add untested sending & asbtract nonce generation * feat: Public api! (sorta) * small updates * feat: add sequence number * chore: yes * feat: merge VoiceHandler into official development * chore: yes clippy, you are special * fix: duplicated gateway events * feat: first try at vgw wasm compat * fix: blunder * fix: gateway connect using wrong url * fix: properly using encrypted data, bad practice for buffer creation * chore: split voice udp * feat: udp error handling, create udp/backends * fix: its the same * chore: clarify UDP on WASM * api: split voice gateway and udp features, test for voice gateway in WASM * feat: new encryption modes, minor code quality * docs: document voice encryption modes * chore: unused imports * chore: update getrandom version to match wasm version * chore: update on packet size FIXME * drop buf asap * Okay can't do that actually * tests: add nonce test * normal tests work? * docs: fix doc warning, fix incorrect refrences to 'webrtc' * chore: json isn't a doc test * tests: better gateway auth test * testing tests * update voice heartbeat, fix the new test issue * committed too much * fix: unused import * fix: use ip discovery address as string, not as Vec<u8> * chore: less obnoxious logging * chore: better unimplemented voice modes handling * chore: remove unused variable * chore: use matches macro * add voice examples, make gateway ones clearer * rename voice example * chore: remove unused VoiceHandler * fix: implement gateway Reconnect and InvalidSession * Typo Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * Fix a bunch of typos Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * fix: error handling while loading native certs * fix: guh * use be for nonce bytes * fix: refactor gw and vgw closures * remove outdated docs --------- Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
tokio::select! {
// Fail, we timed out waiting for it
() = sleep(Duration::from_secs(20)) => {
println!("Timed out waiting for event, failing..");
assert!(false);
}
// Success, we have received it
Primitive voice implementation (feature/voice) (#457) * Add Webrtc Identify & Ready * Add more webrtc typings * Attempt an untested voice gateway implementation * fmt * Merge with main * Same allow as for voice as normal gateway * Test error observer * Minor updates * More derives * Even more derives * Small types update * e * Minor doc fixes * Modernise voice gateway * Add default impl for voicegatewayerror * Make voice event fields pub * Event updates via the scientific method * ?? * Fix bad request in voice gateway init * Voice gateway updates * Fix error failing to 'deserialize' properly * Update voice identify * Clarify FIXME related to #430 * Update to v7 * Create seperate voice_gateway.rs and voice_udp.rs * Restructure voice to new module * fix: deserialization error in speaking bitflags * feat: kinda janky ip discovery impl * feat: return ip discovery data + minor update * feat: packet parsing! * fix: voice works again * feat: add voice_media_sink_wants (comitting uncommited changes to merge) * chore: rename events/webrtc to events/voice_gateway * Add UdpHandle * chore: clippy + other misc updates * fix: attempt to fix failing wasm build * chore: yes clippy, that is indeed an unneeded return statement * feat: add VoiceData struct * feat: add VoiceData reference to UdpHandler * feat: decryption? * chore: formatting * feat: add ssrc definition (op 12) * feat: add untested sending & asbtract nonce generation * feat: Public api! (sorta) * small updates * feat: add sequence number * chore: yes * feat: merge VoiceHandler into official development * chore: yes clippy, you are special * fix: duplicated gateway events * feat: first try at vgw wasm compat * fix: blunder * fix: gateway connect using wrong url * fix: properly using encrypted data, bad practice for buffer creation * chore: split voice udp * feat: udp error handling, create udp/backends * fix: its the same * chore: clarify UDP on WASM * api: split voice gateway and udp features, test for voice gateway in WASM * feat: new encryption modes, minor code quality * docs: document voice encryption modes * chore: unused imports * chore: update getrandom version to match wasm version * chore: update on packet size FIXME * drop buf asap * Okay can't do that actually * tests: add nonce test * normal tests work? * docs: fix doc warning, fix incorrect refrences to 'webrtc' * chore: json isn't a doc test * tests: better gateway auth test * testing tests * update voice heartbeat, fix the new test issue * committed too much * fix: unused import * fix: use ip discovery address as string, not as Vec<u8> * chore: less obnoxious logging * chore: better unimplemented voice modes handling * chore: remove unused variable * chore: use matches macro * add voice examples, make gateway ones clearer * rename voice example * chore: remove unused VoiceHandler * fix: implement gateway Reconnect and InvalidSession * Typo Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * Fix a bunch of typos Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * fix: error handling while loading native certs * fix: guh * use be for nonce bytes * fix: refactor gw and vgw closures * remove outdated docs --------- Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
Some(_) = ready_receive.recv() => {}
}
Primitive voice implementation (feature/voice) (#457) * Add Webrtc Identify & Ready * Add more webrtc typings * Attempt an untested voice gateway implementation * fmt * Merge with main * Same allow as for voice as normal gateway * Test error observer * Minor updates * More derives * Even more derives * Small types update * e * Minor doc fixes * Modernise voice gateway * Add default impl for voicegatewayerror * Make voice event fields pub * Event updates via the scientific method * ?? * Fix bad request in voice gateway init * Voice gateway updates * Fix error failing to 'deserialize' properly * Update voice identify * Clarify FIXME related to #430 * Update to v7 * Create seperate voice_gateway.rs and voice_udp.rs * Restructure voice to new module * fix: deserialization error in speaking bitflags * feat: kinda janky ip discovery impl * feat: return ip discovery data + minor update * feat: packet parsing! * fix: voice works again * feat: add voice_media_sink_wants (comitting uncommited changes to merge) * chore: rename events/webrtc to events/voice_gateway * Add UdpHandle * chore: clippy + other misc updates * fix: attempt to fix failing wasm build * chore: yes clippy, that is indeed an unneeded return statement * feat: add VoiceData struct * feat: add VoiceData reference to UdpHandler * feat: decryption? * chore: formatting * feat: add ssrc definition (op 12) * feat: add untested sending & asbtract nonce generation * feat: Public api! (sorta) * small updates * feat: add sequence number * chore: yes * feat: merge VoiceHandler into official development * chore: yes clippy, you are special * fix: duplicated gateway events * feat: first try at vgw wasm compat * fix: blunder * fix: gateway connect using wrong url * fix: properly using encrypted data, bad practice for buffer creation * chore: split voice udp * feat: udp error handling, create udp/backends * fix: its the same * chore: clarify UDP on WASM * api: split voice gateway and udp features, test for voice gateway in WASM * feat: new encryption modes, minor code quality * docs: document voice encryption modes * chore: unused imports * chore: update getrandom version to match wasm version * chore: update on packet size FIXME * drop buf asap * Okay can't do that actually * tests: add nonce test * normal tests work? * docs: fix doc warning, fix incorrect refrences to 'webrtc' * chore: json isn't a doc test * tests: better gateway auth test * testing tests * update voice heartbeat, fix the new test issue * committed too much * fix: unused import * fix: use ip discovery address as string, not as Vec<u8> * chore: less obnoxious logging * chore: better unimplemented voice modes handling * chore: remove unused variable * chore: use matches macro * add voice examples, make gateway ones clearer * rename voice example * chore: remove unused VoiceHandler * fix: implement gateway Reconnect and InvalidSession * Typo Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * Fix a bunch of typos Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com> * fix: error handling while loading native certs * fix: guh * use be for nonce bytes * fix: refactor gw and vgw closures * remove outdated docs --------- Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
2023-07-22 14:38:55 +02:00
common::teardown(bundle).await
2023-06-08 19:51:32 +02:00
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_self_updating_structs() {
// PRETTYFYME: This test is a bit of a mess, but it works. Ideally, each self-updating struct
// would have its own test.
let mut bundle = common::setup().await;
2024-01-24 23:01:38 +01:00
2023-08-16 01:11:32 +02:00
let received_channel = bundle
.user
.gateway
.observe_and_into_inner(bundle.channel.clone())
.await;
2023-08-15 20:20:58 +02:00
assert_eq!(received_channel, bundle.channel.read().unwrap().clone());
let modify_schema = ChannelModifySchema {
name: Some("selfupdating".to_string()),
..Default::default()
};
2023-08-16 01:11:32 +02:00
received_channel
.modify(modify_schema, None, &mut bundle.user)
.await
.unwrap();
2023-08-12 22:40:40 +02:00
assert_eq!(
2023-08-16 01:11:32 +02:00
bundle
.user
.gateway
.observe_and_into_inner(bundle.channel.clone())
.await
.name
.unwrap(),
"selfupdating".to_string()
2023-08-12 22:40:40 +02:00
);
2024-01-24 23:01:38 +01:00
let guild = bundle
.user
.gateway
.observe_and_into_inner(bundle.guild.clone())
.await;
assert!(guild.channels.is_empty());
2024-01-24 23:01:38 +01:00
Channel::create(
&mut bundle.user,
guild.id,
None,
ChannelCreateSchema {
name: "selfupdating2".to_string(),
channel_type: Some(types::ChannelType::GuildText),
..Default::default()
},
)
.await
.unwrap();
let guild = bundle
.user
.gateway
.observe_and_into_inner(guild.into_shared())
.await;
assert!(!guild.channels.is_empty());
assert_eq!(guild.channels.len(), 1);
2024-01-24 23:01:38 +01:00
2023-07-22 14:38:55 +02:00
common::teardown(bundle).await
}
2023-08-16 14:06:04 +02:00
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
2023-08-16 14:06:04 +02:00
async fn test_recursive_self_updating_structs() {
2023-08-16 21:26:19 +02:00
// Setup
let mut bundle = common::setup().await;
let guild = bundle.guild.clone();
// Observe Guild, make sure it has no channels
let guild = bundle.user.gateway.observe(guild.clone()).await;
let inner_guild = guild.read().unwrap().clone();
assert!(inner_guild.roles.is_empty());
// Create Role
let permissions = types::PermissionFlags::CONNECT | types::PermissionFlags::MANAGE_EVENTS;
let mut role_create_schema: types::RoleCreateModifySchema = RoleCreateModifySchema {
name: Some("cool person".to_string()),
permissions: Some(permissions),
hoist: Some(true),
icon: None,
unicode_emoji: Some("".to_string()),
mentionable: Some(true),
position: None,
color: None,
};
let guild_id = inner_guild.id;
let role = RoleObject::create(&mut bundle.user, guild_id, role_create_schema.clone())
.await
.unwrap();
// Watch role;
bundle
.user
.gateway
.observe(role.clone().into_shared())
.await;
// Update Guild and check for Guild
let inner_guild = guild.read().unwrap().clone();
assert!(!inner_guild.roles.is_empty());
// Update the Role
role_create_schema.name = Some("yippieee".to_string());
RoleObject::modify(&mut bundle.user, guild_id, role.id, role_create_schema)
.await
.unwrap();
2023-08-17 18:23:57 +02:00
let role_inner = bundle
.user
.gateway
.observe_and_into_inner(role.clone().into_shared())
2023-08-17 18:23:57 +02:00
.await;
assert_eq!(role_inner.name, "yippieee");
// Check if the change propagated
2023-08-17 18:23:57 +02:00
let guild = bundle.user.gateway.observe(bundle.guild.clone()).await;
let inner_guild = guild.read().unwrap().clone();
let guild_roles = inner_guild.roles;
2024-07-18 23:04:35 +02:00
let guild_role_inner = guild_roles.first().unwrap().read().unwrap().clone();
assert_eq!(guild_role_inner.name, "yippieee".to_string());
2023-08-16 14:06:04 +02:00
common::teardown(bundle).await;
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_error() {
let error = GatewayMessage("4000".to_string()).error().unwrap();
assert_eq!(error, GatewayError::Unknown);
let error = GatewayMessage("4001".to_string()).error().unwrap();
assert_eq!(error, GatewayError::UnknownOpcode);
let error = GatewayMessage("4002".to_string()).error().unwrap();
assert_eq!(error, GatewayError::Decode);
let error = GatewayMessage("4003".to_string()).error().unwrap();
assert_eq!(error, GatewayError::NotAuthenticated);
let error = GatewayMessage("4004".to_string()).error().unwrap();
assert_eq!(error, GatewayError::AuthenticationFailed);
let error = GatewayMessage("4005".to_string()).error().unwrap();
assert_eq!(error, GatewayError::AlreadyAuthenticated);
let error = GatewayMessage("4007".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidSequenceNumber);
let error = GatewayMessage("4008".to_string()).error().unwrap();
assert_eq!(error, GatewayError::RateLimited);
let error = GatewayMessage("4009".to_string()).error().unwrap();
assert_eq!(error, GatewayError::SessionTimedOut);
let error = GatewayMessage("4010".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidShard);
let error = GatewayMessage("4011".to_string()).error().unwrap();
assert_eq!(error, GatewayError::ShardingRequired);
let error = GatewayMessage("4012".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidAPIVersion);
let error = GatewayMessage("4013".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidIntents);
let error = GatewayMessage("4014".to_string()).error().unwrap();
assert_eq!(error, GatewayError::DisallowedIntents);
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_error_message() {
let error = GatewayMessage("Unknown Error".to_string()).error().unwrap();
assert_eq!(error, GatewayError::Unknown);
let error = GatewayMessage("Unknown Opcode".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::UnknownOpcode);
let error = GatewayMessage("Decode Error".to_string()).error().unwrap();
assert_eq!(error, GatewayError::Decode);
let error = GatewayMessage("Not Authenticated".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::NotAuthenticated);
let error = GatewayMessage("Authentication Failed".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::AuthenticationFailed);
let error = GatewayMessage("Already Authenticated".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::AlreadyAuthenticated);
let error = GatewayMessage("Invalid Seq".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidSequenceNumber);
let error = GatewayMessage("Rate Limited".to_string()).error().unwrap();
assert_eq!(error, GatewayError::RateLimited);
let error = GatewayMessage("Session Timed Out".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::SessionTimedOut);
let error = GatewayMessage("Invalid Shard".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidShard);
let error = GatewayMessage("Sharding Required".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::ShardingRequired);
let error = GatewayMessage("Invalid API Version".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::InvalidAPIVersion);
let error = GatewayMessage("Invalid Intent(s)".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::InvalidIntents);
let error = GatewayMessage("Disallowed Intent(s)".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::DisallowedIntents);
// Also test the dot thing
let error = GatewayMessage("Invalid Intent(s).".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::InvalidIntents);
}