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

Wait for mute event to send in PTT mode #2401

Merged
merged 1 commit into from
May 26, 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
13 changes: 9 additions & 4 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
}
this.localUsermediaFeed?.setVideoMuted(muted);
this.updateMuteStatus();
await this.sendMetadataUpdate();
return this.isLocalVideoMuted();
}

Expand Down Expand Up @@ -1256,6 +1257,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
}
this.localUsermediaFeed?.setAudioMuted(muted);
this.updateMuteStatus();
await this.sendMetadataUpdate();
return this.isMicrophoneMuted();
}

Expand Down Expand Up @@ -1291,6 +1293,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
transceiver.direction = onHold ? 'sendonly' : 'sendrecv';
}
this.updateMuteStatus();
this.sendMetadataUpdate();

this.emit(CallEvent.RemoteHoldUnhold, this.remoteOnHold);
}
Expand Down Expand Up @@ -1332,10 +1335,6 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
}

private updateMuteStatus(): void {
this.sendVoipEvent(EventType.CallSDPStreamMetadataChangedPrefix, {
[SDPStreamMetadataKey]: this.getLocalSDPStreamMetadata(),
});

const micShouldBeMuted = this.isMicrophoneMuted() || this.remoteOnHold;
const vidShouldBeMuted = this.isLocalVideoMuted() || this.remoteOnHold;

Expand All @@ -1345,6 +1344,12 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
setTracksEnabled(this.localUsermediaStream.getVideoTracks(), !vidShouldBeMuted);
}

public async sendMetadataUpdate(): Promise<void> {
await this.sendVoipEvent(EventType.CallSDPStreamMetadataChangedPrefix, {
[SDPStreamMetadataKey]: this.getLocalSDPStreamMetadata(),
});
}

private gotCallFeedsForInvite(callFeeds: CallFeed[], requestScreenshareFeed = false): void {
if (this.successor) {
this.successor.queueGotCallFeedsForAnswer(callFeeds);
Expand Down
28 changes: 27 additions & 1 deletion src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH
return false;
}

const sendUpdatesBefore = !muted && this.isPtt;

// set a timer for the maximum transmit time on PTT calls
if (this.isPtt) {
// Set or clear the max transmit timer
Expand All @@ -443,15 +445,39 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH
}
}

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

if (sendUpdatesBefore) {
try {
await Promise.all(this.calls.map(c => c.sendMetadataUpdate()));
} catch (e) {
logger.info("Failed to send one or more metadata updates", e);
}
}

if (this.localCallFeed) {
logger.log(`groupCall ${this.groupCallId} setMicrophoneMuted stream ${
this.localCallFeed.stream.id} muted ${muted}`);
this.localCallFeed.setAudioMuted(muted);
// 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
// anywhere. Let's do it anyway to avoid confusion.
setTracksEnabled(this.localCallFeed.stream.getAudioTracks(), !muted);
}

for (const call of this.calls) {
await call.setMicrophoneMuted(muted);
setTracksEnabled(call.localUsermediaFeed.stream.getAudioTracks(), !muted);
}

if (!sendUpdatesBefore) {
try {
await Promise.all(this.calls.map(c => c.sendMetadataUpdate()));
} catch (e) {
logger.info("Failed to send one or more metadata updates", e);
}
}

this.emit(GroupCallEvent.LocalMuteStateChanged, muted, this.isLocalVideoMuted());
Expand Down