diff --git a/src/types/events/webrtc/mod.rs b/src/types/events/webrtc/mod.rs index ebaf7b2..69d8e32 100644 --- a/src/types/events/webrtc/mod.rs +++ b/src/types/events/webrtc/mod.rs @@ -1,5 +1,31 @@ pub use identify::*; pub use ready::*; +pub use select_protocol::*; +use serde::{Deserialize, Serialize}; mod identify; mod ready; +mod select_protocol; + +/// The modes of encryption available in webrtc connections; +/// See https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection-encryption-modes; +#[derive(Debug, Serialize, Deserialize, Clone, Copy)] +#[serde(rename_all = "snake_case")] +pub enum WebrtcEncryptionMode { + XSalsa20Poly1305, + XSalsa20Poly1305Suffix, + XSalsa20Poly1305Lite, +} + +// The various voice opcodes +pub const VOICE_IDENTIFY: u8 = 0; +pub const VOICE_SELECT_PROTOCOL: u8 = 1; +pub const VOICE_READY: u8 = 2; +pub const VOICE_HEARTBEAT: u8 = 3; +pub const VOICE_SESSION_DESCRIPTION: u8 = 4; +pub const VOICE_SPEAKING: u8 = 5; +pub const VOICE_HEARTBEAT_ACK: u8 = 6; +pub const VOICE_RESUME: u8 = 7; +pub const VOICE_HELLO: u8 = 8; +pub const VOICE_RESUMED: u8 = 9; +pub const VOICE_CLIENT_DISCONENCT: u8 = 13; diff --git a/src/types/events/webrtc/ready.rs b/src/types/events/webrtc/ready.rs index c805593..ff57eae 100644 --- a/src/types/events/webrtc/ready.rs +++ b/src/types/events/webrtc/ready.rs @@ -3,15 +3,19 @@ use std::net::Ipv4Addr; use crate::types::WebSocketEvent; use serde::{Deserialize, Serialize}; +use super::WebrtcEncryptionMode; + #[derive(Debug, Deserialize, Serialize, Clone)] /// The ready event for the webrtc stream; /// Used to give info after the identify event; /// See https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection-example-voice-ready-payload; pub struct VoiceReady { - ssrc: u8, + /// See https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpStreamStats/ssrc + ssrc: i32, ip: Ipv4Addr, - port: u8, - modes: Vec, + port: u32, + /// The available encryption modes for the webrtc connection + modes: Vec, // Heartbeat interval is also sent, but is "an erroneous field and should be ignored. The correct heartbeat_interval value comes from the Hello payload." } diff --git a/src/types/events/webrtc/select_protocol.rs b/src/types/events/webrtc/select_protocol.rs new file mode 100644 index 0000000..0966cd8 --- /dev/null +++ b/src/types/events/webrtc/select_protocol.rs @@ -0,0 +1,25 @@ +use std::net::Ipv4Addr; + +use serde::{Deserialize, Serialize}; + +use super::WebrtcEncryptionMode; + +#[derive(Debug, Deserialize, Serialize, Clone)] +/// An event sent by the client to the webrtc server, detailing what protocol, address and encryption to use; +/// See https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection-example-select-protocol-payload +pub struct SelectProtocol { + /// The protocol to use. The only option detailed in discord docs is "udp" + pub protocol: String, +} + +#[derive(Debug, Deserialize, Serialize, Clone)] +/// The data field of the SelectProtocol Event +/// See https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection-example-select-protocol-payload; +pub struct SelectProtocolData { + /// Our external ip + pub address: Ipv4Addr, + /// Our external udp port + pub port: u32, + /// The mode of encryption to use + pub mode: WebrtcEncryptionMode, +}