WIP: Add mute icons

This commit is contained in:
Mikayla Maki 2023-06-27 13:12:52 -07:00
parent 37cb202c93
commit 60ce584427
No known key found for this signature in database
4 changed files with 26 additions and 2 deletions

View file

@ -43,6 +43,7 @@ pub struct RemoteParticipant {
pub peer_id: proto::PeerId, pub peer_id: proto::PeerId,
pub projects: Vec<proto::ParticipantProject>, pub projects: Vec<proto::ParticipantProject>,
pub location: ParticipantLocation, pub location: ParticipantLocation,
pub muted: bool,
pub video_tracks: HashMap<live_kit_client::Sid, Arc<RemoteVideoTrack>>, pub video_tracks: HashMap<live_kit_client::Sid, Arc<RemoteVideoTrack>>,
pub audio_tracks: HashMap<live_kit_client::Sid, Arc<RemoteAudioTrack>>, pub audio_tracks: HashMap<live_kit_client::Sid, Arc<RemoteAudioTrack>>,
} }

View file

@ -647,6 +647,7 @@ impl Room {
peer_id, peer_id,
projects: participant.projects, projects: participant.projects,
location, location,
muted: false,
video_tracks: Default::default(), video_tracks: Default::default(),
audio_tracks: Default::default(), audio_tracks: Default::default(),
}, },
@ -781,6 +782,21 @@ impl Room {
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
match change { match change {
RemoteAudioTrackUpdate::MuteChanged { track_id, muted } => {
for participant in &mut self.remote_participants.values_mut() {
let mut found = false;
for track in participant.audio_tracks.values() {
if track.sid() == track_id {
found = true;
break;
}
}
if found {
participant.muted = muted;
break;
}
}
}
RemoteAudioTrackUpdate::Subscribed(track) => { RemoteAudioTrackUpdate::Subscribed(track) => {
let user_id = track.publisher_id().parse()?; let user_id = track.publisher_id().parse()?;
let track_id = track.sid().to_string(); let track_id = track.sid().to_string();
@ -1213,11 +1229,12 @@ impl Room {
let mut tasks = Vec::with_capacity(self.remote_participants.len()); let mut tasks = Vec::with_capacity(self.remote_participants.len());
// Context notification is sent within set_mute itself. // Context notification is sent within set_mute itself.
let mut mute_task = None;
if live_kit.deafened { if live_kit.deafened {
// Unmute microphone only if we're going from unmuted -> muted state. // Unmute microphone only if we're going from unmuted -> muted state.
// We don't want to unmute user automatically. // We don't want to unmute user automatically.
let _ = Self::set_mute(live_kit, live_kit.deafened, cx)?; // todo (osiewicz): we probably want to schedule it on fg/bg? mute_task = Some(Self::set_mute(live_kit, live_kit.deafened, cx)?);
} };
for participant in self.remote_participants.values() { for participant in self.remote_participants.values() {
for track in live_kit for track in live_kit
.room .room
@ -1226,7 +1243,11 @@ impl Room {
tasks.push(cx.foreground().spawn(track.set_enabled(!live_kit.deafened))); tasks.push(cx.foreground().spawn(track.set_enabled(!live_kit.deafened)));
} }
} }
Ok(cx.foreground().spawn(async move { Ok(cx.foreground().spawn(async move {
if let Some(mute_task) = mute_task {
mute_task.await?;
}
for task in tasks { for task in tasks {
task.await?; task.await?;
} }

View file

@ -761,6 +761,7 @@ pub enum RemoteVideoTrackUpdate {
} }
pub enum RemoteAudioTrackUpdate { pub enum RemoteAudioTrackUpdate {
MuteChanged { track_id: Sid, muted: bool},
Subscribed(Arc<RemoteAudioTrack>), Subscribed(Arc<RemoteAudioTrack>),
Unsubscribed { publisher_id: Sid, track_id: Sid }, Unsubscribed { publisher_id: Sid, track_id: Sid },
} }

View file

@ -580,6 +580,7 @@ pub enum RemoteVideoTrackUpdate {
#[derive(Clone)] #[derive(Clone)]
pub enum RemoteAudioTrackUpdate { pub enum RemoteAudioTrackUpdate {
MuteChanged { track_id: Sid, muted: bool},
Subscribed(Arc<RemoteAudioTrack>), Subscribed(Arc<RemoteAudioTrack>),
Unsubscribed { publisher_id: Sid, track_id: Sid }, Unsubscribed { publisher_id: Sid, track_id: Sid },
} }