From b6f42b25dd35db2aedebee24cd6ae453d188bd8d Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 18 Dec 2020 13:45:13 +0000 Subject: [PATCH] Honour a call reject event from another of our own devices Fixes a bug where the call would ring again when you refreshed, even though you'd previously rejected it. --- src/webrtc/call.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index da884c2ca..fea0db149 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -446,6 +446,7 @@ export class MatrixCall extends EventEmitter { */ async initWithInvite(event: MatrixEvent) { this.msg = event.getContent(); + this.direction = CallDirection.Inbound; this.peerConn = this.createPeerConnection(); try { await this.peerConn.setRemoteDescription(this.msg.offer); @@ -467,7 +468,6 @@ export class MatrixCall extends EventEmitter { this.type = this.remoteStream.getTracks().some(t => t.kind === 'video') ? CallType.Video : CallType.Voice; this.setState(CallState.Ringing); - this.direction = CallDirection.Inbound; this.opponentVersion = this.msg.version; this.opponentPartyId = this.msg.party_id || null; this.opponentMember = event.sender; @@ -1314,7 +1314,16 @@ export class MatrixCall extends EventEmitter { // No need to check party_id for reject because if we'd received either // an answer or reject, we wouldn't be in state InviteSent - if (this.state === CallState.InviteSent) { + const shouldTerminate = ( + // reject events also end the call if it's ringing: it's another of + // our devices rejecting the call. + ([CallState.InviteSent, CallState.Ringing].includes(this.state)) || + // also if we're in the init state and it's an inbound call, since + // this means we just haven't entered the ringing state yet + this.state === CallState.Fledgling && this.direction === CallDirection.Inbound + ); + + if (shouldTerminate) { this.terminate(CallParty.Remote, CallErrorCode.UserHangup, true); } else { logger.debug(`Call is in state: ${this.state}: ignoring reject`);