signaling
All checks were successful
/ upload (release) Successful in 20s

This commit is contained in:
pavel 2026-02-24 01:25:27 +01:00
commit be1451ce45
3 changed files with 109 additions and 7 deletions

View file

@ -18,6 +18,7 @@ struct ClientHandle {
display_name: String,
is_sharing_video: bool,
is_sharing_screen: bool,
is_speaking: bool,
tx: mpsc::UnboundedSender<ServerEvent>,
}
@ -27,6 +28,7 @@ pub struct VoiceParticipant {
pub display_name: String,
pub is_sharing_video: bool,
pub is_sharing_screen: bool,
pub is_speaking: bool,
}
#[derive(Serialize, Clone)]
@ -50,6 +52,10 @@ enum ServerEvent {
user_id: Uuid,
is_sharing_screen: bool,
},
SpeakingStatusChanged {
user_id: Uuid,
is_speaking: bool,
},
Signal {
from_user_id: Uuid,
kind: String,
@ -74,6 +80,9 @@ enum ClientEvent {
SetScreenStatus {
is_sharing_screen: bool,
},
SetSpeakingStatus {
is_speaking: bool,
},
}
impl VoiceHub {
@ -89,6 +98,7 @@ impl VoiceHub {
display_name: handle.display_name.clone(),
is_sharing_video: handle.is_sharing_video,
is_sharing_screen: handle.is_sharing_screen,
is_speaking: handle.is_speaking,
})
.collect()
}
@ -110,6 +120,7 @@ impl VoiceHub {
display_name: peer.display_name.clone(),
is_sharing_video: peer.is_sharing_video,
is_sharing_screen: peer.is_sharing_screen,
is_speaking: peer.is_speaking,
})
.collect::<Vec<_>>();
@ -119,6 +130,7 @@ impl VoiceHub {
display_name: display_name.clone(),
is_sharing_video: false,
is_sharing_screen: false,
is_speaking: false,
tx,
},
);
@ -213,6 +225,26 @@ impl VoiceHub {
}
}
}
pub async fn set_speaking_status(&self, room_id: Uuid, user_id: Uuid, is_speaking: bool) {
let mut rooms = self.rooms.write().await;
let Some(room) = rooms.get_mut(&room_id) else {
return;
};
if let Some(handle) = room.get_mut(&user_id) {
handle.is_speaking = is_speaking;
for (peer_id, peer) in room.iter() {
if *peer_id != user_id {
let _ = peer.tx.send(ServerEvent::SpeakingStatusChanged {
user_id,
is_speaking,
});
}
}
}
}
}
pub async fn handle_socket(state: AppState, socket: WebSocket, room_id: Uuid, user_id: Uuid) {
@ -267,6 +299,12 @@ pub async fn handle_socket(state: AppState, socket: WebSocket, room_id: Uuid, us
.set_screen_status(room_id, user_id, is_sharing_screen)
.await;
}
Ok(ClientEvent::SetSpeakingStatus { is_speaking }) => {
state
.voice
.set_speaking_status(room_id, user_id, is_speaking)
.await;
}
Err(err) => {
let _ = tx.send(ServerEvent::Error {
message: format!("invalid voice message: {err}"),