This commit is contained in:
parent
be1451ce45
commit
33da605c03
13 changed files with 534 additions and 9 deletions
24
src/voice.rs
24
src/voice.rs
|
|
@ -64,6 +64,10 @@ enum ServerEvent {
|
|||
Error {
|
||||
message: String,
|
||||
},
|
||||
PlaySound {
|
||||
user_id: Uuid,
|
||||
sound_url: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
@ -83,6 +87,9 @@ enum ClientEvent {
|
|||
SetSpeakingStatus {
|
||||
is_speaking: bool,
|
||||
},
|
||||
PlaySound {
|
||||
sound_url: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl VoiceHub {
|
||||
|
|
@ -245,6 +252,20 @@ impl VoiceHub {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
return;
|
||||
};
|
||||
|
||||
for peer in room.values() {
|
||||
let _ = peer.tx.send(ServerEvent::PlaySound {
|
||||
user_id,
|
||||
sound_url: sound_url.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_socket(state: AppState, socket: WebSocket, room_id: Uuid, user_id: Uuid) {
|
||||
|
|
@ -305,6 +326,9 @@ 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::PlaySound { sound_url }) => {
|
||||
state.voice.play_sound(room_id, user_id, sound_url).await;
|
||||
}
|
||||
Err(err) => {
|
||||
let _ = tx.send(ServerEvent::Error {
|
||||
message: format!("invalid voice message: {err}"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue