Skip to content

Commit

Permalink
Prevent double mute status changed events (#2502)
Browse files Browse the repository at this point in the history
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 #2502 from
group call branch
  • Loading branch information
dbkr committed Jul 13, 2022
1 parent 9523978 commit c59fd2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
await this.upgradeCall(false, true);
return this.isLocalVideoMuted();
}
this.localUsermediaFeed?.setVideoMuted(muted);
this.localUsermediaFeed?.setAudioVideoMuted(null, muted);
this.updateMuteStatus();
return this.isLocalVideoMuted();
}
Expand Down Expand Up @@ -1174,7 +1174,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
await this.upgradeCall(true, false);
return this.isMicrophoneMuted();
}
this.localUsermediaFeed?.setAudioMuted(muted);
this.localUsermediaFeed?.setAudioVideoMuted(muted, null);
this.updateMuteStatus();
return this.isMicrophoneMuted();
}
Expand Down Expand Up @@ -1585,8 +1585,9 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
this.remoteSDPStreamMetadata = utils.recursivelyAssign(this.remoteSDPStreamMetadata || {}, metadata, true);
for (const feed of this.getRemoteFeeds()) {
const streamId = feed.stream.id;
feed.setAudioMuted(this.remoteSDPStreamMetadata[streamId]?.audio_muted);
feed.setVideoMuted(this.remoteSDPStreamMetadata[streamId]?.video_muted);
const metadata = this.remoteSDPStreamMetadata[streamId];

feed.setAudioVideoMuted(metadata?.audio_muted, metadata?.video_muted);
feed.purpose = this.remoteSDPStreamMetadata[streamId]?.purpose;
}
}
Expand Down
23 changes: 10 additions & 13 deletions src/webrtc/callFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,18 @@ export class CallFeed extends TypedEventEmitter<CallFeedEvent, EventHandlerMap>
}

/**
* 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);
}

Expand Down

0 comments on commit c59fd2f

Please sign in to comment.