Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent double mute status changed events #2502

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,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();
await this.sendMetadataUpdate();
return this.isLocalVideoMuted();
Expand Down Expand Up @@ -1296,7 +1296,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();
await this.sendMetadataUpdate();
return this.isMicrophoneMuted();
Expand Down Expand Up @@ -1801,8 +1801,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
const streamId = feed.stream.id;
const metadata = this.remoteSDPStreamMetadata[streamId];

feed.setAudioMuted(metadata?.audio_muted);
feed.setVideoMuted(metadata?.video_muted);
feed.setAudioVideoMuted(metadata?.audio_muted, metadata?.video_muted);
feed.purpose = this.remoteSDPStreamMetadata[streamId]?.purpose;
}
}
Expand Down Expand Up @@ -2027,8 +2026,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
// fast enough.
if (this.isPtt && ["failed", "disconnected"].includes(this.peerConn.iceConnectionState)) {
for (const feed of this.getRemoteFeeds()) {
feed.setAudioMuted(true);
feed.setVideoMuted(true);
feed.setAudioVideoMuted(true, true);
}
}
};
Expand Down
23 changes: 10 additions & 13 deletions src/webrtc/callFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,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
6 changes: 3 additions & 3 deletions src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH
}

for (const call of this.calls) {
call.localUsermediaFeed.setAudioMuted(muted);
call.localUsermediaFeed.setAudioVideoMuted(muted, null);
}

if (sendUpdatesBefore) {
Expand All @@ -474,7 +474,7 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH
if (this.localCallFeed) {
logger.log(`groupCall ${this.groupCallId} setMicrophoneMuted stream ${
this.localCallFeed.stream.id} muted ${muted}`);
this.localCallFeed.setAudioMuted(muted);
this.localCallFeed.setAudioVideoMuted(muted, null);
// I don't believe its actually necessary to enable these tracks: they
// are the one on the groupcall's own CallFeed and are cloned before being
// given to any of the actual calls, so these tracks don't actually go
Expand Down Expand Up @@ -514,7 +514,7 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH
if (this.localCallFeed) {
logger.log(`groupCall ${this.groupCallId} setLocalVideoMuted stream ${
this.localCallFeed.stream.id} muted ${muted}`);
this.localCallFeed.setVideoMuted(muted);
this.localCallFeed.setAudioVideoMuted(null, muted);
setTracksEnabled(this.localCallFeed.stream.getVideoTracks(), !muted);
}

Expand Down