feat: add voice_media_sink_wants

(comitting uncommited changes to merge)
This commit is contained in:
kozabrada123 2023-11-22 19:27:46 +01:00
parent 170a4fb6d0
commit 42c77b695e
3 changed files with 39 additions and 3 deletions

View File

@ -0,0 +1,14 @@
use crate::types::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy)]
/// What does this do?
///
/// {"op":15,"d":{"any":100}}
///
/// Opcode from <https://discord-userdoccers.vercel.app/topics/opcodes-and-status-codes#voice-opcodes>
pub struct VoiceMediaSinkWants {
pub any: u16,
}
impl WebSocketEvent for VoiceMediaSinkWants {}

View File

@ -6,6 +6,7 @@ pub use client_connect::*;
pub use client_disconnect::*; pub use client_disconnect::*;
pub use hello::*; pub use hello::*;
pub use identify::*; pub use identify::*;
pub use media_sink_wants::*;
pub use ready::*; pub use ready::*;
pub use select_protocol::*; pub use select_protocol::*;
pub use session_description::*; pub use session_description::*;
@ -16,6 +17,7 @@ mod client_connect;
mod client_disconnect; mod client_disconnect;
mod hello; mod hello;
mod identify; mod identify;
mod media_sink_wants;
mod ready; mod ready;
mod select_protocol; mod select_protocol;
mod session_description; mod session_description;
@ -104,6 +106,13 @@ pub const VOICE_RESUMED: u8 = 9;
pub const VOICE_VIDEO: u8 = 12; pub const VOICE_VIDEO: u8 = 12;
pub const VOICE_CLIENT_DISCONNECT: u8 = 13; pub const VOICE_CLIENT_DISCONNECT: u8 = 13;
pub const VOICE_SESSION_UPDATE: u8 = 14; pub const VOICE_SESSION_UPDATE: u8 = 14;
/// What is this?
///
/// {"op":15,"d":{"any":100}}
///
/// Opcode from <https://discord-userdoccers.vercel.app/topics/opcodes-and-status-codes#voice-opcodes>
pub const VOICE_MEDIA_SINK_WANTS: u8 = 15;
/// See <https://discord-userdoccers.vercel.app/topics/opcodes-and-status-codes#voice-opcodes> /// See <https://discord-userdoccers.vercel.app/topics/opcodes-and-status-codes#voice-opcodes>
/// Sent with empty data from the client, the server responds with the voice backend version; /// Sent with empty data from the client, the server responds with the voice backend version;
pub const VOICE_BACKEND_VERSION: u8 = 16; pub const VOICE_BACKEND_VERSION: u8 = 16;

View File

@ -20,8 +20,8 @@ use crate::types::{
self, SelectProtocol, Speaking, VoiceGatewayReceivePayload, VoiceGatewaySendPayload, self, SelectProtocol, Speaking, VoiceGatewayReceivePayload, VoiceGatewaySendPayload,
VoiceIdentify, WebSocketEvent, VOICE_BACKEND_VERSION, VOICE_CLIENT_CONNECT_FLAGS, VoiceIdentify, WebSocketEvent, VOICE_BACKEND_VERSION, VOICE_CLIENT_CONNECT_FLAGS,
VOICE_CLIENT_CONNECT_PLATFORM, VOICE_CLIENT_DISCONNECT, VOICE_HEARTBEAT, VOICE_HEARTBEAT_ACK, VOICE_CLIENT_CONNECT_PLATFORM, VOICE_CLIENT_DISCONNECT, VOICE_HEARTBEAT, VOICE_HEARTBEAT_ACK,
VOICE_HELLO, VOICE_IDENTIFY, VOICE_READY, VOICE_RESUME, VOICE_SELECT_PROTOCOL, VOICE_HELLO, VOICE_IDENTIFY, VOICE_MEDIA_SINK_WANTS, VOICE_READY, VOICE_RESUME,
VOICE_SESSION_DESCRIPTION, VOICE_SESSION_UPDATE, VOICE_SPEAKING, VOICE_SELECT_PROTOCOL, VOICE_SESSION_DESCRIPTION, VOICE_SESSION_UPDATE, VOICE_SPEAKING,
}; };
use self::voice_events::VoiceEvents; use self::voice_events::VoiceEvents;
@ -454,7 +454,19 @@ impl VoiceGateway {
return; return;
} }
} }
VOICE_MEDIA_SINK_WANTS => {
trace!("VGW: Received Media Sink Wants");
let event = &mut self.events.lock().await.media_sink_wants;
let result = VoiceGateway::handle_event(gateway_payload.data.get(), event).await;
if result.is_err() {
warn!(
"Failed to parse VOICE_MEDIA_SINK_WANTS ({})",
result.err().unwrap()
);
return;
}
}
// We received a heartbeat from the server // We received a heartbeat from the server
// "Discord may send the app a Heartbeat (opcode 1) event, in which case the app should send a Heartbeat event immediately." // "Discord may send the app a Heartbeat (opcode 1) event, in which case the app should send a Heartbeat event immediately."
VOICE_HEARTBEAT => { VOICE_HEARTBEAT => {
@ -650,7 +662,7 @@ struct VoiceHeartbeatThreadCommunication {
pub mod voice_events { pub mod voice_events {
use crate::types::{ use crate::types::{
SessionDescription, SessionUpdate, VoiceBackendVersion, VoiceClientConnectFlags, SessionDescription, SessionUpdate, VoiceBackendVersion, VoiceClientConnectFlags,
VoiceClientConnectPlatform, VoiceClientDisconnection, VoiceReady, VoiceClientConnectPlatform, VoiceClientDisconnection, VoiceMediaSinkWants, VoiceReady,
}; };
use super::*; use super::*;
@ -665,6 +677,7 @@ pub mod voice_events {
pub client_disconnect: GatewayEvent<VoiceClientDisconnection>, pub client_disconnect: GatewayEvent<VoiceClientDisconnection>,
pub client_connect_flags: GatewayEvent<VoiceClientConnectFlags>, pub client_connect_flags: GatewayEvent<VoiceClientConnectFlags>,
pub client_connect_platform: GatewayEvent<VoiceClientConnectPlatform>, pub client_connect_platform: GatewayEvent<VoiceClientConnectPlatform>,
pub media_sink_wants: GatewayEvent<VoiceMediaSinkWants>,
pub error: GatewayEvent<VoiceGatewayError>, pub error: GatewayEvent<VoiceGatewayError>,
} }
} }