indicators
This commit is contained in:
parent
4358d49b48
commit
af46da77a7
6 changed files with 216 additions and 26 deletions
37
src/voice.rs
37
src/voice.rs
|
|
@ -19,6 +19,7 @@ struct ClientHandle {
|
|||
is_sharing_video: bool,
|
||||
is_sharing_screen: bool,
|
||||
is_speaking: bool,
|
||||
is_muted: bool,
|
||||
tx: mpsc::UnboundedSender<ServerEvent>,
|
||||
}
|
||||
|
||||
|
|
@ -29,6 +30,7 @@ pub struct VoiceParticipant {
|
|||
pub is_sharing_video: bool,
|
||||
pub is_sharing_screen: bool,
|
||||
pub is_speaking: bool,
|
||||
pub is_muted: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
|
|
@ -56,6 +58,10 @@ enum ServerEvent {
|
|||
user_id: Uuid,
|
||||
is_speaking: bool,
|
||||
},
|
||||
MuteStatusChanged {
|
||||
user_id: Uuid,
|
||||
is_muted: bool,
|
||||
},
|
||||
Signal {
|
||||
from_user_id: Uuid,
|
||||
kind: String,
|
||||
|
|
@ -87,6 +93,9 @@ enum ClientEvent {
|
|||
SetSpeakingStatus {
|
||||
is_speaking: bool,
|
||||
},
|
||||
SetMuteStatus {
|
||||
is_muted: bool,
|
||||
},
|
||||
PlaySound {
|
||||
sound_url: String,
|
||||
},
|
||||
|
|
@ -106,6 +115,7 @@ impl VoiceHub {
|
|||
is_sharing_video: handle.is_sharing_video,
|
||||
is_sharing_screen: handle.is_sharing_screen,
|
||||
is_speaking: handle.is_speaking,
|
||||
is_muted: handle.is_muted,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
@ -128,6 +138,7 @@ impl VoiceHub {
|
|||
is_sharing_video: peer.is_sharing_video,
|
||||
is_sharing_screen: peer.is_sharing_screen,
|
||||
is_speaking: peer.is_speaking,
|
||||
is_muted: peer.is_muted,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
|
@ -138,6 +149,7 @@ impl VoiceHub {
|
|||
is_sharing_video: false,
|
||||
is_sharing_screen: false,
|
||||
is_speaking: false,
|
||||
is_muted: false,
|
||||
tx,
|
||||
},
|
||||
);
|
||||
|
|
@ -253,6 +265,25 @@ impl VoiceHub {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn set_mute_status(&self, room_id: Uuid, user_id: Uuid, is_muted: 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_muted = is_muted;
|
||||
|
||||
for (peer_id, peer) in room.iter() {
|
||||
if *peer_id != user_id {
|
||||
let _ = peer
|
||||
.tx
|
||||
.send(ServerEvent::MuteStatusChanged { user_id, is_muted });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn play_sound(&self, room_id: Uuid, user_id: Uuid, sound_url: String) {
|
||||
let rooms = self.rooms.read().await;
|
||||
let Some(room) = rooms.get(&room_id) else {
|
||||
|
|
@ -329,6 +360,12 @@ pub async fn handle_socket(state: AppState, socket: WebSocket, room_id: Uuid, us
|
|||
.set_speaking_status(room_id, user_id, is_speaking)
|
||||
.await;
|
||||
}
|
||||
Ok(ClientEvent::SetMuteStatus { is_muted }) => {
|
||||
state
|
||||
.voice
|
||||
.set_mute_status(room_id, user_id, is_muted)
|
||||
.await;
|
||||
}
|
||||
Ok(ClientEvent::PlaySound { sound_url }) => {
|
||||
state.voice.play_sound(room_id, user_id, sound_url).await;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue