From 3824f65d156ab3f9c8c5fa4215ab054c50bfb006 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 28 Jul 2022 16:13:00 +0100 Subject: [PATCH] Prevent double mute status changed events (#2502) (#2522) Audio & video mute status were set in separate calls but share a mute status changed event, so you'd always get two mute status changed events emitted. We could suppress events where the mute status didn't change, but this would still get two events saying the same thing when they both changed. Instead, merge setAudioMuted & setVideoMuted into a single call that sets either or both. Port of https://github.com/matrix-org/matrix-js-sdk/pull/2502 from group call branch --- src/webrtc/call.ts | 9 +++++---- src/webrtc/callFeed.ts | 23 ++++++++++------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 8ee5d7bb6df..e0f9ae2ff7b 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -1142,7 +1142,7 @@ export class MatrixCall extends TypedEventEmitter } /** - * Set feed's internal audio mute state - * @param muted is the feed's audio muted? - */ - public setAudioMuted(muted: boolean): void { - this.audioMuted = muted; - this.speakingVolumeSamples.fill(-Infinity); - this.emit(CallFeedEvent.MuteStateChanged, this.audioMuted, this.videoMuted); - } - - /** - * Set feed's internal video mute state + * Set one or both of feed's internal audio and video video mute state + * Either value may be null to leave it as-is * @param muted is the feed's video muted? */ - public setVideoMuted(muted: boolean): void { - this.videoMuted = muted; + public setAudioVideoMuted(audioMuted: boolean, videoMuted: boolean): void { + if (audioMuted !== null) { + if (this.audioMuted !== audioMuted) { + this.speakingVolumeSamples.fill(-Infinity); + } + this.audioMuted = audioMuted; + } + if (videoMuted !== null) this.videoMuted = videoMuted; this.emit(CallFeedEvent.MuteStateChanged, this.audioMuted, this.videoMuted); }