Voice gateway updates
This commit is contained in:
parent
7c143c3b28
commit
97049dbd9d
|
@ -0,0 +1,13 @@
|
|||
use crate::types::WebSocketEvent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy)]
|
||||
/// Contains info on how often the client should send heartbeats to the server;
|
||||
///
|
||||
/// Differs from the normal hello data in that discord sends heartbeat interval as a float.
|
||||
pub struct VoiceHelloData {
|
||||
/// How often a client should send heartbeats, in milliseconds
|
||||
pub heartbeat_interval: f64,
|
||||
}
|
||||
|
||||
impl WebSocketEvent for VoiceHelloData {}
|
|
@ -2,12 +2,14 @@ use super::WebSocketEvent;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{value::RawValue, Value};
|
||||
|
||||
pub use hello::*;
|
||||
pub use identify::*;
|
||||
pub use ready::*;
|
||||
pub use select_protocol::*;
|
||||
pub use session_description::*;
|
||||
pub use speaking::*;
|
||||
|
||||
mod hello;
|
||||
mod identify;
|
||||
mod ready;
|
||||
mod select_protocol;
|
||||
|
@ -51,9 +53,15 @@ impl<'a> WebSocketEvent for VoiceGatewayReceivePayload<'a> {}
|
|||
#[serde(rename_all = "snake_case")]
|
||||
pub enum WebrtcEncryptionMode {
|
||||
#[default]
|
||||
XSalsa20Poly1305,
|
||||
XSalsa20Poly1305Suffix,
|
||||
XSalsa20Poly1305Lite,
|
||||
// Documented
|
||||
Xsalsa20Poly1305,
|
||||
Xsalsa20Poly1305Suffix,
|
||||
Xsalsa20Poly1305Lite,
|
||||
// Undocumented
|
||||
Xsalsa20Poly1305LiteRtpsize,
|
||||
AeadAes256Gcm,
|
||||
AeadAes256GcmRtpsize,
|
||||
AeadXchacha20Poly1305Rtpsize,
|
||||
}
|
||||
|
||||
// The various voice opcodes
|
||||
|
|
15
src/voice.rs
15
src/voice.rs
|
@ -200,7 +200,7 @@ impl VoiceGateway {
|
|||
pub async fn new(websocket_url: String) -> Result<VoiceGatewayHandle, VoiceGatewayError> {
|
||||
// Append the needed things to the websocket url
|
||||
let processed_url = format!("wss://{}/?v=4", websocket_url);
|
||||
debug!("Created voice socket url: {}", processed_url.clone());
|
||||
trace!("Created voice socket url: {}", processed_url.clone());
|
||||
|
||||
let (websocket_stream, _) = match connect_async_tls_with_config(
|
||||
&processed_url,
|
||||
|
@ -241,9 +241,10 @@ impl VoiceGateway {
|
|||
|
||||
info!("VGW: Received Hello");
|
||||
|
||||
// The hello data is the same on voice and normal gateway
|
||||
let gateway_hello: types::HelloData =
|
||||
// The hello data for voice gateways is in float milliseconds, so we convert it to f64 seconds
|
||||
let gateway_hello: types::VoiceHelloData =
|
||||
serde_json::from_str(gateway_payload.data.get()).unwrap();
|
||||
let heartbeat_interval_seconds: f64 = gateway_hello.heartbeat_interval / 1000.0;
|
||||
|
||||
let voice_events = VoiceEvents::default();
|
||||
let shared_events = Arc::new(Mutex::new(voice_events));
|
||||
|
@ -251,7 +252,7 @@ impl VoiceGateway {
|
|||
let mut gateway = VoiceGateway {
|
||||
events: shared_events.clone(),
|
||||
heartbeat_handler: VoiceHeartbeatHandler::new(
|
||||
Duration::from_millis(gateway_hello.heartbeat_interval),
|
||||
Duration::from_secs_f64(heartbeat_interval_seconds),
|
||||
1, // to:do actually compute nonce
|
||||
shared_websocket_send.clone(),
|
||||
kill_send.subscribe(),
|
||||
|
@ -347,6 +348,8 @@ impl VoiceGateway {
|
|||
// See <https://discord.com/developers/docs/topics/voice-connections>
|
||||
match gateway_payload.op_code {
|
||||
VOICE_READY => {
|
||||
trace!("VGW: Received READY!");
|
||||
|
||||
let event = &mut self.events.lock().await.voice_ready;
|
||||
let result = VoiceGateway::handle_event(gateway_payload.data.get(), event).await;
|
||||
if result.is_err() {
|
||||
|
@ -355,6 +358,8 @@ impl VoiceGateway {
|
|||
}
|
||||
}
|
||||
VOICE_SESSION_DESCRIPTION => {
|
||||
trace!("VGW: Received Session Description");
|
||||
|
||||
let event = &mut self.events.lock().await.session_description;
|
||||
let result = VoiceGateway::handle_event(gateway_payload.data.get(), event).await;
|
||||
if result.is_err() {
|
||||
|
@ -383,7 +388,7 @@ impl VoiceGateway {
|
|||
.unwrap();
|
||||
}
|
||||
VOICE_HEARTBEAT_ACK => {
|
||||
debug!("VGW: Received Heartbeat ACK");
|
||||
trace!("VGW: Received Heartbeat ACK");
|
||||
|
||||
// Tell the heartbeat handler we received an ack
|
||||
|
||||
|
|
Loading…
Reference in New Issue