camera?
All checks were successful
/ upload (release) Successful in 23s

This commit is contained in:
pavel 2026-02-24 00:49:56 +01:00
commit 5f92356a9a
4 changed files with 208 additions and 13 deletions

View file

@ -16,6 +16,7 @@ pub struct VoiceHub {
#[derive(Clone)]
struct ClientHandle {
display_name: String,
is_sharing_video: bool,
tx: mpsc::UnboundedSender<ServerEvent>,
}
@ -23,20 +24,34 @@ struct ClientHandle {
pub struct VoiceParticipant {
pub user_id: Uuid,
pub display_name: String,
pub is_sharing_video: bool,
}
#[derive(Serialize, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
enum ServerEvent {
Peers { peers: Vec<VoiceParticipant> },
PeerJoined { user_id: Uuid, display_name: String },
PeerLeft { user_id: Uuid },
Peers {
peers: Vec<VoiceParticipant>,
},
PeerJoined {
user_id: Uuid,
display_name: String,
},
PeerLeft {
user_id: Uuid,
},
VideoStatusChanged {
user_id: Uuid,
is_sharing_video: bool,
},
Signal {
from_user_id: Uuid,
kind: String,
data: serde_json::Value,
},
Error { message: String },
Error {
message: String,
},
}
#[derive(Deserialize)]
@ -47,6 +62,9 @@ enum ClientEvent {
kind: String,
data: serde_json::Value,
},
SetVideoStatus {
is_sharing_video: bool,
},
}
impl VoiceHub {
@ -60,6 +78,7 @@ impl VoiceHub {
.map(|(user_id, handle)| VoiceParticipant {
user_id: *user_id,
display_name: handle.display_name.clone(),
is_sharing_video: handle.is_sharing_video,
})
.collect()
}
@ -79,6 +98,7 @@ impl VoiceHub {
.map(|(peer_id, peer)| VoiceParticipant {
user_id: *peer_id,
display_name: peer.display_name.clone(),
is_sharing_video: peer.is_sharing_video,
})
.collect::<Vec<_>>();
@ -86,6 +106,7 @@ impl VoiceHub {
user_id,
ClientHandle {
display_name: display_name.clone(),
is_sharing_video: false,
tx,
},
);
@ -119,7 +140,7 @@ impl VoiceHub {
}
}
async fn relay_signal(
pub async fn relay_signal(
&self,
room_id: Uuid,
from_user_id: Uuid,
@ -140,6 +161,26 @@ impl VoiceHub {
});
}
}
pub async fn set_video_status(&self, room_id: Uuid, user_id: Uuid, is_sharing_video: 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_video = is_sharing_video;
for (peer_id, peer) in room.iter() {
if *peer_id != user_id {
let _ = peer.tx.send(ServerEvent::VideoStatusChanged {
user_id,
is_sharing_video,
});
}
}
}
}
}
pub async fn handle_socket(state: AppState, socket: WebSocket, room_id: Uuid, user_id: Uuid) {
@ -182,6 +223,12 @@ pub async fn handle_socket(state: AppState, socket: WebSocket, room_id: Uuid, us
.relay_signal(room_id, user_id, to_user_id, kind, data)
.await;
}
Ok(ClientEvent::SetVideoStatus { is_sharing_video }) => {
state
.voice
.set_video_status(room_id, user_id, is_sharing_video)
.await;
}
Err(err) => {
let _ = tx.send(ServerEvent::Error {
message: format!("invalid voice message: {err}"),