Unified · Split
| @@ -163,6 +163,7 @@ impl Room { · 162 unmodified lines | ||
| 163 | 163 | screen_track: LocalTrack::None, |
| 164 | 164 | microphone_track: LocalTrack::None, |
| 165 | 165 | next_publish_id: 0, |
| 166 | + muted_by_user: false, | |
| 166 | 167 | deafened: false, |
| 167 | 168 | speaking: false, |
| 168 | 169 | _maintain_room, |
| @@ -1231,6 +1232,10 @@ impl Room { · 1062 unmodified lines | ||
| 1231 | 1232 | should_mute: bool, |
| 1232 | 1233 | cx: &mut ModelContext<Self>, |
| 1233 | 1234 | ) -> Result<Task<Result<()>>> { |
| 1235 | + if !should_mute { | |
| 1236 | + // clear user muting state. | |
| 1237 | + live_kit.muted_by_user = false; | |
| 1238 | + } | |
| 1234 | 1239 | match &mut live_kit.microphone_track { |
| 1235 | 1240 | LocalTrack::None => Err(anyhow!("microphone was not shared")), |
| 1236 | 1241 | LocalTrack::Pending { muted, .. } => { |
| @@ -1249,9 +1254,11 @@ impl Room { · 12 unmodified lines | ||
| 1249 | 1254 | } |
| 1250 | 1255 | } |
| 1251 | 1256 | 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(); | |
| 1253 | 1258 | 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 | |
| 1255 | 1262 | } else { |
| 1256 | 1263 | Err(anyhow!("LiveKit not started")) |
| 1257 | 1264 | } |
| @@ -1264,9 +1271,9 @@ impl Room { · 6 unmodified lines | ||
| 1264 | 1271 | let mut tasks = Vec::with_capacity(self.remote_participants.len()); |
| 1265 | 1272 | // Context notification is sent within set_mute itself. |
| 1266 | 1273 | 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 { | |
| 1270 | 1277 | mute_task = Some(Self::set_mute(live_kit, live_kit.deafened, cx)?); |
| 1271 | 1278 | }; |
| 1272 | 1279 | for participant in self.remote_participants.values() { |
| @@ -1331,6 +1338,8 @@ struct LiveKitRoom { · 58 unmodified lines | ||
| 1331 | 1338 | room: Arc<live_kit_client::Room>, |
| 1332 | 1339 | screen_track: LocalTrack, |
| 1333 | 1340 | 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, | |
| 1334 | 1343 | deafened: bool, |
| 1335 | 1344 | speaking: bool, |
| 1336 | 1345 | next_publish_id: usize, |