ii
All checks were successful
/ upload (release) Successful in 18s

This commit is contained in:
pavel 2026-02-24 01:02:26 +01:00
commit 737267567e
3 changed files with 125 additions and 9 deletions

View file

@ -17,6 +17,7 @@ pub struct VoiceHub {
struct ClientHandle {
display_name: String,
is_sharing_video: bool,
is_sharing_screen: bool,
tx: mpsc::UnboundedSender<ServerEvent>,
}
@ -25,6 +26,7 @@ pub struct VoiceParticipant {
pub user_id: Uuid,
pub display_name: String,
pub is_sharing_video: bool,
pub is_sharing_screen: bool,
}
#[derive(Serialize, Clone)]
@ -44,6 +46,10 @@ enum ServerEvent {
user_id: Uuid,
is_sharing_video: bool,
},
ScreenStatusChanged {
user_id: Uuid,
is_sharing_screen: bool,
},
Signal {
from_user_id: Uuid,
kind: String,
@ -65,6 +71,9 @@ enum ClientEvent {
SetVideoStatus {
is_sharing_video: bool,
},
SetScreenStatus {
is_sharing_screen: bool,
},
}
impl VoiceHub {
@ -79,6 +88,7 @@ impl VoiceHub {
user_id: *user_id,
display_name: handle.display_name.clone(),
is_sharing_video: handle.is_sharing_video,
is_sharing_screen: handle.is_sharing_screen,
})
.collect()
}
@ -99,6 +109,7 @@ impl VoiceHub {
user_id: *peer_id,
display_name: peer.display_name.clone(),
is_sharing_video: peer.is_sharing_video,
is_sharing_screen: peer.is_sharing_screen,
})
.collect::<Vec<_>>();
@ -107,6 +118,7 @@ impl VoiceHub {
ClientHandle {
display_name: display_name.clone(),
is_sharing_video: false,
is_sharing_screen: false,
tx,
},
);
@ -181,6 +193,26 @@ impl VoiceHub {
}
}
}
pub async fn set_screen_status(&self, room_id: Uuid, user_id: Uuid, is_sharing_screen: 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_sharing_screen = is_sharing_screen;
for (peer_id, peer) in room.iter() {
if *peer_id != user_id {
let _ = peer.tx.send(ServerEvent::ScreenStatusChanged {
user_id,
is_sharing_screen,
});
}
}
}
}
}
pub async fn handle_socket(state: AppState, socket: WebSocket, room_id: Uuid, user_id: Uuid) {
@ -229,6 +261,12 @@ pub async fn handle_socket(state: AppState, socket: WebSocket, room_id: Uuid, us
.set_video_status(room_id, user_id, is_sharing_video)
.await;
}
Ok(ClientEvent::SetScreenStatus { is_sharing_screen }) => {
state
.voice
.set_screen_status(room_id, user_id, is_sharing_screen)
.await;
}
Err(err) => {
let _ = tx.send(ServerEvent::Error {
message: format!("invalid voice message: {err}"),