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
|
|
|
// 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/.
|
|
|
|
|
|
|
|
// This example showcases how to use the voice udp channel.
|
|
|
|
//
|
|
|
|
// To use this to properly communicate with voice, you will need to bring your own opus bindings
|
|
|
|
// along with potentially sending some other events, like Speaking
|
|
|
|
//
|
|
|
|
// To properly run this example, you will need to change some values below,
|
|
|
|
// like the token, guild and channel ids.
|
|
|
|
|
|
|
|
const TOKEN: &str = "";
|
|
|
|
|
|
|
|
const VOICE_GUILD_ID: Option<Snowflake> = None;
|
|
|
|
const VOICE_CHANNEL_ID: Option<Snowflake> = Some(Snowflake(0_u64));
|
|
|
|
|
|
|
|
const GATEWAY_URL: &str = "wss://gateway.discord.gg";
|
|
|
|
|
|
|
|
use async_trait::async_trait;
|
|
|
|
use simplelog::{TermLogger, Config, WriteLogger};
|
|
|
|
use std::{net::SocketAddrV4, sync::Arc, fs::File, time::Duration};
|
|
|
|
|
|
|
|
use chorus::{
|
2024-07-25 11:27:30 +02:00
|
|
|
gateway::{Gateway, GatewayOptions, Observer},
|
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
|
|
|
types::{
|
2024-07-25 11:27:30 +02:00
|
|
|
GatewayIdentifyPayload, GatewayReady, SelectProtocol, SelectProtocolData, SessionDescription, Snowflake, Speaking, SpeakingBitflags, SsrcDefinition, UpdateVoiceState, VoiceEncryptionMode, VoiceIdentify, VoiceProtocol, VoiceReady, VoiceServerUpdate
|
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
|
|
|
},
|
|
|
|
voice::{
|
|
|
|
gateway::{VoiceGateway, VoiceGatewayHandle},
|
|
|
|
udp::{UdpHandle, UdpHandler},
|
|
|
|
voice_data::VoiceData,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
use log::{info, LevelFilter};
|
|
|
|
use tokio::sync::{Mutex, RwLock};
|
|
|
|
|
|
|
|
extern crate chorus;
|
|
|
|
extern crate tokio;
|
|
|
|
|
|
|
|
/// Handles in between connections between the gateway and UDP modules
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct VoiceHandler {
|
|
|
|
pub voice_gateway_connection: Arc<Mutex<Option<VoiceGatewayHandle>>>,
|
|
|
|
pub voice_udp_connection: Arc<Mutex<Option<UdpHandle>>>,
|
|
|
|
pub data: Arc<RwLock<VoiceData>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl VoiceHandler {
|
|
|
|
/// Creates a new [VoiceHandler], only initializing the data
|
|
|
|
pub fn new() -> VoiceHandler {
|
|
|
|
Self {
|
|
|
|
data: Arc::new(RwLock::new(VoiceData::default())),
|
|
|
|
voice_gateway_connection: Arc::new(Mutex::new(None)),
|
|
|
|
voice_udp_connection: Arc::new(Mutex::new(None)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for VoiceHandler {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
// On [VoiceServerUpdate] we get our starting data and URL for the voice gateway server.
|
|
|
|
impl Observer<VoiceServerUpdate> for VoiceHandler {
|
|
|
|
async fn update(&self, data: &VoiceServerUpdate) {
|
|
|
|
let mut data_lock = self.data.write().await;
|
|
|
|
|
|
|
|
data_lock.server_data = Some(data.clone());
|
|
|
|
let user_id = data_lock.user_id;
|
|
|
|
let session_id = data_lock.session_id.clone();
|
|
|
|
|
|
|
|
drop(data_lock);
|
|
|
|
|
|
|
|
// Create and connect to the voice gateway
|
|
|
|
let voice_gateway_handle = VoiceGateway::spawn(data.endpoint.clone().unwrap())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let server_id: Snowflake;
|
|
|
|
|
|
|
|
if data.guild_id.is_some() {
|
|
|
|
server_id = data.guild_id.unwrap();
|
|
|
|
} else {
|
|
|
|
server_id = data.channel_id.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
let voice_identify = VoiceIdentify {
|
|
|
|
server_id,
|
|
|
|
user_id,
|
|
|
|
session_id,
|
|
|
|
token: data.token.clone(),
|
|
|
|
video: Some(false),
|
|
|
|
};
|
|
|
|
|
|
|
|
voice_gateway_handle.send_identify(voice_identify).await;
|
|
|
|
|
|
|
|
let cloned_gateway_handle = voice_gateway_handle.clone();
|
|
|
|
|
|
|
|
let mut voice_events = cloned_gateway_handle.events.lock().await;
|
|
|
|
|
|
|
|
let self_reference = Arc::new(self.clone());
|
|
|
|
|
|
|
|
// Subscribe to voice gateway events
|
|
|
|
voice_events.voice_ready.subscribe(self_reference.clone());
|
|
|
|
voice_events
|
|
|
|
.session_description
|
|
|
|
.subscribe(self_reference.clone());
|
|
|
|
voice_events.speaking.subscribe(self_reference.clone());
|
|
|
|
voice_events
|
|
|
|
.ssrc_definition
|
|
|
|
.subscribe(self_reference.clone());
|
|
|
|
|
|
|
|
*self.voice_gateway_connection.lock().await = Some(voice_gateway_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
// On [VoiceReady] we get info for establishing a UDP connection, and we immediately need said UDP
|
|
|
|
// connection for ip discovery.
|
|
|
|
impl Observer<VoiceReady> for VoiceHandler {
|
|
|
|
async fn update(&self, data: &VoiceReady) {
|
|
|
|
let mut data_lock = self.data.write().await;
|
|
|
|
|
|
|
|
data_lock.ready_data = Some(data.clone());
|
|
|
|
|
|
|
|
drop(data_lock);
|
|
|
|
|
|
|
|
// Create a udp connection and perform ip discovery
|
|
|
|
let udp_handle = UdpHandler::spawn(
|
|
|
|
self.data.clone(),
|
|
|
|
std::net::SocketAddr::V4(SocketAddrV4::new(data.ip, data.port)),
|
|
|
|
data.ssrc,
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// Subscribe ourself to receiving rtp data
|
|
|
|
udp_handle
|
|
|
|
.events
|
|
|
|
.lock()
|
|
|
|
.await
|
|
|
|
.rtp
|
|
|
|
.subscribe(Arc::new(self.clone()));
|
|
|
|
|
|
|
|
let ip_discovery = self.data.read().await.ip_discovery.clone().unwrap();
|
|
|
|
|
|
|
|
*self.voice_udp_connection.lock().await = Some(udp_handle.clone());
|
|
|
|
|
|
|
|
let string_ip_address =
|
|
|
|
String::from_utf8(ip_discovery.address).expect("Ip discovery gave non string ip");
|
|
|
|
|
|
|
|
// Send a select protocol, which tells the server where we'll be receiving data and what
|
|
|
|
// mode to encrypt data in
|
|
|
|
self.voice_gateway_connection
|
|
|
|
.lock()
|
|
|
|
.await
|
|
|
|
.clone()
|
|
|
|
.unwrap()
|
|
|
|
.send_select_protocol(SelectProtocol {
|
|
|
|
protocol: VoiceProtocol::Udp,
|
|
|
|
data: SelectProtocolData {
|
|
|
|
address: string_ip_address,
|
|
|
|
port: ip_discovery.port,
|
|
|
|
// There are several other voice encryption modes available, though not all are
|
|
|
|
// implemented in chorus
|
|
|
|
mode: VoiceEncryptionMode::Xsalsa20Poly1305,
|
|
|
|
},
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
// Session descryption gives us final info regarding codecs and our encryption key
|
|
|
|
impl Observer<SessionDescription> for VoiceHandler {
|
|
|
|
async fn update(&self, data: &SessionDescription) {
|
|
|
|
let mut data_write = self.data.write().await;
|
|
|
|
|
|
|
|
data_write.session_description = Some(data.clone());
|
|
|
|
|
|
|
|
drop(data_write);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
// Ready is used just to obtain some info, like the user id and session id
|
|
|
|
impl Observer<GatewayReady> for VoiceHandler {
|
|
|
|
async fn update(&self, data: &GatewayReady) {
|
|
|
|
let mut lock = self.data.write().await;
|
|
|
|
lock.user_id = data.user.id;
|
|
|
|
lock.session_id = data.session_id.clone();
|
|
|
|
drop(lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
// This is the received voice data
|
|
|
|
impl Observer<chorus::voice::discortp::rtp::Rtp> for VoiceHandler {
|
|
|
|
async fn update(&self, data: &chorus::voice::discortp::rtp::Rtp) {
|
|
|
|
info!(
|
|
|
|
"Received decrypted voice data! {:?} (SSRC: {})",
|
|
|
|
data.payload.clone(),
|
|
|
|
data.ssrc,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
// This event gives extra info about who is speaking
|
|
|
|
impl Observer<Speaking> for VoiceHandler {
|
|
|
|
async fn update(&self, data: &Speaking) {
|
|
|
|
println!(
|
|
|
|
"Received Speaking! (SRRC: {}, flags: {:?})",
|
|
|
|
data.ssrc,
|
2024-07-25 11:27:30 +02:00
|
|
|
SpeakingBitflags::from_bits(data.speaking.into()).unwrap()
|
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_trait]
|
|
|
|
// This event gives some info about which user has which ssrc
|
|
|
|
impl Observer<SsrcDefinition> for VoiceHandler {
|
|
|
|
async fn update(&self, data: &SsrcDefinition) {
|
|
|
|
println!(
|
|
|
|
"Received SSRC Definition! (User {} has audio ssrc {})",
|
|
|
|
data.user_id.unwrap(),
|
|
|
|
data.audio_ssrc
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
simplelog::CombinedLogger::init(vec![
|
|
|
|
TermLogger::new(
|
|
|
|
LevelFilter::Debug,
|
|
|
|
Config::default(),
|
|
|
|
simplelog::TerminalMode::Mixed,
|
|
|
|
simplelog::ColorChoice::Auto,
|
|
|
|
),
|
|
|
|
WriteLogger::new(
|
|
|
|
LevelFilter::Trace,
|
|
|
|
Config::default(),
|
|
|
|
File::create("latest.log").unwrap(),
|
|
|
|
),
|
|
|
|
])
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-25 11:27:30 +02:00
|
|
|
let gateway = Gateway::spawn(GATEWAY_URL.to_string(), GatewayOptions::default())
|
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
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let mut identify = GatewayIdentifyPayload::common();
|
|
|
|
identify.token = TOKEN.to_string();
|
|
|
|
|
|
|
|
gateway.send_identify(identify).await;
|
|
|
|
|
|
|
|
let voice_handler = Arc::new(VoiceHandler::new());
|
|
|
|
|
|
|
|
// Voice handler needs voice server update
|
|
|
|
gateway
|
|
|
|
.events
|
|
|
|
.lock()
|
|
|
|
.await
|
|
|
|
.voice
|
|
|
|
.server_update
|
|
|
|
.subscribe(voice_handler.clone());
|
|
|
|
|
|
|
|
// It also needs a bit of the data in ready
|
|
|
|
gateway
|
|
|
|
.events
|
|
|
|
.lock()
|
|
|
|
.await
|
|
|
|
.session
|
|
|
|
.ready
|
|
|
|
.subscribe(voice_handler.clone());
|
2024-07-25 11:27:30 +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
|
|
|
// Data which channel to update the local user to be joined into.
|
|
|
|
//
|
|
|
|
// guild_id and channel_id can be some to join guild voice channels
|
|
|
|
//
|
|
|
|
// guild_id can be none and channel id some to join dm calls
|
|
|
|
//
|
|
|
|
// both can be none to leave all voice channels
|
|
|
|
let voice_state_update = UpdateVoiceState {
|
|
|
|
guild_id: VOICE_GUILD_ID,
|
|
|
|
channel_id: VOICE_CHANNEL_ID,
|
|
|
|
self_mute: false,
|
|
|
|
self_deaf: false,
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
|
|
|
gateway.send_update_voice_state(voice_state_update).await;
|
|
|
|
|
|
|
|
loop {
|
|
|
|
tokio::time::sleep(Duration::from_millis(1000)).await;
|
|
|
|
|
|
|
|
// Potentially send some data here
|
|
|
|
/*let voice_udp_option = voice_handler.voice_udp_connection.lock().await.clone();
|
|
|
|
if voice_udp_option.is_some() {
|
|
|
|
voice_udp_option.unwrap().send_opus_data(0, vec![1, 2, 3, 4, 5]).await.unwrap();
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|