Add Webrtc Identify & Ready

This commit is contained in:
kozabrada123 2023-06-20 19:12:21 +02:00
parent b4ccca8c8b
commit 1431aba363
6 changed files with 59 additions and 3 deletions

View File

@ -2,7 +2,7 @@ use crate::types::events::{PresenceUpdate, WebSocketEvent};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::serde_as; use serde_with::serde_as;
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize, Clone)]
pub struct GatewayIdentifyPayload { pub struct GatewayIdentifyPayload {
pub token: String, pub token: String,
pub properties: GatewayIdentifyConnectionProps, pub properties: GatewayIdentifyConnectionProps,

View File

@ -26,6 +26,8 @@ pub use user::*;
pub use voice::*; pub use voice::*;
pub use webhooks::*; pub use webhooks::*;
pub use webrtc::*;
mod application; mod application;
mod auto_moderation; mod auto_moderation;
mod call; mod call;
@ -52,6 +54,8 @@ mod user;
mod voice; mod voice;
mod webhooks; mod webhooks;
mod webrtc;
pub trait WebSocketEvent {} pub trait WebSocketEvent {}
#[derive(Debug, Default, Serialize, Clone)] #[derive(Debug, Default, Serialize, Clone)]

View File

@ -1,4 +1,4 @@
use crate::types::{events::WebSocketEvent, VoiceState}; use crate::types::{events::WebSocketEvent, Snowflake, VoiceState};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default)] #[derive(Debug, Deserialize, Serialize, Default)]
@ -34,7 +34,7 @@ impl WebSocketEvent for VoiceStateUpdate {}
/// Received to indicate which voice endpoint, token and guild_id to use; /// Received to indicate which voice endpoint, token and guild_id to use;
pub struct VoiceServerUpdate { pub struct VoiceServerUpdate {
pub token: String, pub token: String,
pub guild_id: String, pub guild_id: Snowflake,
pub endpoint: Option<String>, pub endpoint: Option<String>,
} }

View File

@ -0,0 +1,18 @@
use crate::types::{Snowflake, WebSocketEvent};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// The identify payload for the webrtc stream;
/// Contains info to begin a webrtc connection;
/// See https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection-example-voice-identify-payload;
pub struct VoiceIdentify {
server_id: Snowflake,
user_id: Snowflake,
session_id: String,
token: String,
#[serde(skip_serializing_if = "Option::is_none")]
/// Undocumented field, but is also in discord client comms
video: Option<bool>,
}
impl WebSocketEvent for VoiceIdentify {}

View File

@ -0,0 +1,5 @@
pub use identify::*;
pub use ready::*;
mod identify;
mod ready;

View File

@ -0,0 +1,29 @@
use std::net::Ipv4Addr;
use crate::types::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[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,
ip: Ipv4Addr,
port: u8,
modes: Vec<String>,
// Heartbeat interval is also sent, but is "an erroneous field and should be ignored. The correct heartbeat_interval value comes from the Hello payload."
}
impl Default for VoiceReady {
fn default() -> Self {
VoiceReady {
ssrc: 1,
ip: Ipv4Addr::UNSPECIFIED,
port: 0,
modes: Vec::new(),
}
}
}
impl WebSocketEvent for VoiceReady {}