feat: add VoiceData reference to UdpHandler

This commit is contained in:
kozabrada123 2023-12-16 12:20:02 +01:00
parent cc51c59476
commit d55988bb83
1 changed files with 10 additions and 2 deletions

View File

@ -3,7 +3,7 @@
use std::{net::SocketAddr, sync::Arc}; use std::{net::SocketAddr, sync::Arc};
use log::{info, warn}; use log::{info, warn};
use tokio::net::UdpSocket; use tokio::{net::UdpSocket, sync::Mutex};
use discortp::{ use discortp::{
demux::{demux, Demuxed}, demux::{demux, Demuxed},
@ -11,6 +11,8 @@ use discortp::{
Packet, Packet,
}; };
use super::voice_data::VoiceData;
/// Handle to a voice udp connection /// Handle to a voice udp connection
/// ///
/// Can be safely cloned and will still correspond to the same connection. /// Can be safely cloned and will still correspond to the same connection.
@ -23,11 +25,16 @@ pub struct UdpHandle {
#[derive(Debug)] #[derive(Debug)]
pub struct UdpHandler { pub struct UdpHandler {
data: Arc<Mutex<VoiceData>>,
socket: Arc<UdpSocket>, socket: Arc<UdpSocket>,
} }
impl UdpHandler { impl UdpHandler {
pub async fn spawn(url: SocketAddr, ssrc: u32) -> UdpHandle { pub async fn spawn(
data_reference: Arc<Mutex<VoiceData>>,
url: SocketAddr,
ssrc: u32,
) -> UdpHandle {
// Bind with a port number of 0, so the os assigns this listener a port // Bind with a port number of 0, so the os assigns this listener a port
let udp_socket = UdpSocket::bind("0.0.0.0:0").await.unwrap(); let udp_socket = UdpSocket::bind("0.0.0.0:0").await.unwrap();
@ -84,6 +91,7 @@ impl UdpHandler {
let socket = Arc::new(udp_socket); let socket = Arc::new(udp_socket);
let mut handler = UdpHandler { let mut handler = UdpHandler {
data: data_reference,
socket: socket.clone(), socket: socket.clone(),
}; };