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

Mute disconnected peers in PTT mode #2421

Merged
merged 1 commit into from
May 31, 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
18 changes: 17 additions & 1 deletion src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
public peerConn?: RTCPeerConnection;
public toDeviceSeq = 0;

// whether this call should have push-to-talk semantics
// This should be set by the consumer on incoming & outgoing calls.
public isPtt = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: would this be more legible long term as isRadioMode or similar?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've used 'ptt' in Element Call internally, so I think we'll probably stick with 'ptt' in the code for (hopefully) less confusion, irrespective of what it ends up being called to the user. And yep, I'm not yet 100% sure how we'll get the test coverage up on the voip code, but it's definitely a thing on my mind - thanks for the poke. :)


private client: MatrixClient;
private forceTURN: boolean;
private turnServers: Array<TurnServer>;
Expand Down Expand Up @@ -1876,9 +1880,10 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
logger.debug(
"Call ID " + this.callId + ": ICE connection state changed to: " + this.peerConn.iceConnectionState,
);

// ideally we'd consider the call to be connected when we get media but
// chrome doesn't implement any of the 'onstarted' events yet
if (this.peerConn.iceConnectionState == 'connected') {
if (["connected", "completed"].includes(this.peerConn.iceConnectionState)) {
clearTimeout(this.iceDisconnectedTimeout);
this.setState(CallState.Connected);

Expand All @@ -1900,6 +1905,17 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
this.hangup(CallErrorCode.IceFailed, false);
}, 30 * 1000);
}

// In PTT mode, override feed status to muted when we lose connection to
// the peer, since we don't want to block the line if they're not saying anything.
// Experimenting in Chrome, this happens after 5 or 6 seconds, which is probably
// fast enough.
if (this.isPtt && !["connected", "completed"].includes(this.peerConn.iceConnectionState)) {
for (const feed of this.getRemoteFeeds()) {
feed.setAudioMuted(true);
feed.setVideoMuted(true);
}
}
};

private onSignallingStateChanged = (): void => {
Expand Down
5 changes: 5 additions & 0 deletions src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH

logger.log(`GroupCall: incoming call from: ${opponentMemberId}`);

// we are handlng this call as a PTT call, so enable PTT semantics
newCall.isPtt = true;

// Check if the user calling has an existing call and use this call instead.
if (existingCall) {
this.replaceCall(existingCall, newCall);
Expand Down Expand Up @@ -775,6 +778,8 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH
},
);

newCall.isPtt = true;

const requestScreenshareFeed = opponentDevice.feeds.some(
(feed) => feed.purpose === SDPStreamMetadataPurpose.Screenshare);

Expand Down