History

Undeafen: unmute if user was not muted prior to deafening

Piotr Osiewicz committed 3 years ago

Commit 2ddf0e11 parent 749f60b1 file · +14 −5Browse files

Unified · Split

crates/call/src/room.rs+14−5
@@ -163,6 +163,7 @@ impl Room { · 162 unmodified lines
163163 screen_track: LocalTrack::None,
164164 microphone_track: LocalTrack::None,
165165 next_publish_id: 0,
166+ muted_by_user: false,
166167 deafened: false,
167168 speaking: false,
168169 _maintain_room,
@@ -1231,6 +1232,10 @@ impl Room { · 1062 unmodified lines
12311232 should_mute: bool,
12321233 cx: &mut ModelContext<Self>,
12331234 ) -> Result<Task<Result<()>>> {
1235+ if !should_mute {
1236+ // clear user muting state.
1237+ live_kit.muted_by_user = false;
1238+ }
12341239 match &mut live_kit.microphone_track {
12351240 LocalTrack::None => Err(anyhow!("microphone was not shared")),
12361241 LocalTrack::Pending { muted, .. } => {
@@ -1249,9 +1254,11 @@ impl Room { · 12 unmodified lines
12491254 }
12501255 }
12511256 pub fn toggle_mute(&mut self, cx: &mut ModelContext<Self>) -> Result<Task<Result<()>>> {
1252− let should_mute = self.is_muted();
1257+ let should_mute = !self.is_muted();
12531258 if let Some(live_kit) = self.live_kit.as_mut() {
1254− Self::set_mute(live_kit, !should_mute, cx)
1259+ let ret = Self::set_mute(live_kit, should_mute, cx);
1260+ live_kit.muted_by_user = should_mute;
1261+ ret
12551262 } else {
12561263 Err(anyhow!("LiveKit not started"))
12571264 }
@@ -1264,9 +1271,9 @@ impl Room { · 6 unmodified lines
12641271 let mut tasks = Vec::with_capacity(self.remote_participants.len());
12651272 // Context notification is sent within set_mute itself.
12661273 let mut mute_task = None;
1267− if live_kit.deafened {
1268− // Unmute microphone only if we're going from unmuted -> muted state.
1269− // We don't want to unmute user automatically.
1274+ // When deafening, mute user's mic as well.
1275+ // When undeafening, unmute user's mic unless it was manually muted prior to deafening.
1276+ if live_kit.deafened || !live_kit.muted_by_user {
12701277 mute_task = Some(Self::set_mute(live_kit, live_kit.deafened, cx)?);
12711278 };
12721279 for participant in self.remote_participants.values() {
@@ -1331,6 +1338,8 @@ struct LiveKitRoom { · 58 unmodified lines
13311338 room: Arc<live_kit_client::Room>,
13321339 screen_track: LocalTrack,
13331340 microphone_track: LocalTrack,
1341+ /// Tracks whether we're currently in a muted state due to auto-mute from deafening or manual mute performed by user.
1342+ muted_by_user: bool,
13341343 deafened: bool,
13351344 speaking: bool,
13361345 next_publish_id: usize,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t