diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 50688af..7fbd942 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -49,6 +49,11 @@ pub enum ClientMethod { pin: u64, }, + UserJoinedVoice { + channel_id: String, + pubkey: String, + }, + Speaking { pubkey: String, }, @@ -167,19 +172,31 @@ pub async fn read_loop( } ServerMethod::JoinVoice { channel_id } => { - let pin = rand::random::() % (1 << 53); + { + let pin = rand::random::() % (1 << 53); + + server + .voice_pins + .lock() + .await + .insert(pin, (verifying_key, channel_id.clone())); + + send_socket( + &mut *socket.lock().await, + &ClientMethod::JoinVoice { + channel_id: channel_id.clone(), + pin, + }, + ) + .await?; + } server - .voice_pins - .lock() - .await - .insert(pin, (verifying_key, channel_id.clone())); - - send_socket( - &mut *socket.lock().await, - &ClientMethod::JoinVoice { channel_id, pin }, - ) - .await?; + .broadcast(&ClientMethod::UserJoinedVoice { + channel_id, + pubkey: crate::crypto::to_string(&verifying_key), + }) + .await?; } } diff --git a/src/vc_server.rs b/src/vc_server.rs index 25ed6c5..289c289 100644 --- a/src/vc_server.rs +++ b/src/vc_server.rs @@ -105,7 +105,7 @@ impl Server { let now = Instant::now(); - if now.duration_since(voice.last_speaking_sent).as_millis() >= 1000 { + if now.duration_since(voice.last_speaking_sent).as_millis() >= 600 { for conn in user.connections.lock().await.values() { let _ = send_socket( &mut *conn.lock().await, @@ -115,9 +115,9 @@ impl Server { ) .await; } - } - voice.last_speaking_sent = now; + voice.last_speaking_sent = now; + } let _ = self.udp_send_to(&voice.addr, payload).await; }