diff --git a/spec/unit/webrtc/call.spec.ts b/spec/unit/webrtc/call.spec.ts index 02d15fda8..06884c7b4 100644 --- a/spec/unit/webrtc/call.spec.ts +++ b/spec/unit/webrtc/call.spec.ts @@ -15,7 +15,7 @@ limitations under the License. */ import {TestClient} from '../../TestClient'; -import {MatrixCall} from '../../../src/webrtc/call'; +import {MatrixCall, CallErrorCode} from '../../../src/webrtc/call'; const DUMMY_SDP = ( "v=0\r\n" + @@ -78,6 +78,7 @@ class MockRTCPeerConnection { setLocalDescription() { return Promise.resolve(); } + close() {} } describe('Call', function() { @@ -118,6 +119,9 @@ describe('Call', function() { global.document = {}; client = new TestClient("@alice:foo", "somedevice", "token", undefined, {}); + // We just stub out sendEvent: we're not interested in testing the client's + // event sending code here + client.client.sendEvent = () => {}; call = new MatrixCall({ client: client.client, roomId: '!foo:bar', @@ -135,12 +139,16 @@ describe('Call', function() { it('should ignore candidate events from non-matching party ID', async function() { await call.placeVoiceCall(); - await call.receivedAnswer({ - version: 0, - call_id: call.callId, - party_id: 'the_correct_party_id', - answer: { - sdp: DUMMY_SDP, + await call.onAnswerReceived({ + getContent: () => { + return { + version: 0, + call_id: call.callId, + party_id: 'the_correct_party_id', + answer: { + sdp: DUMMY_SDP, + }, + }; }, }); @@ -178,5 +186,8 @@ describe('Call', function() { }, }); expect(call.peerConn.addIceCandidate.mock.calls.length).toBe(1); + + // Hangup to stop timers + call.hangup(CallErrorCode.UserHangup, true); }); }); diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index b972241a6..9f75c3b08 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -236,6 +236,7 @@ export class MatrixCall extends EventEmitter { // The party ID of the other side: undefined if we haven't chosen a partner // yet, null if we have but they didn't send a party ID. private opponentPartyId: string; + private inviteTimeout; constructor(opts: CallOpts) { super(); @@ -941,7 +942,8 @@ export class MatrixCall extends EventEmitter { try { await this.sendVoipEvent(EventType.CallInvite, content); this.setState(CallState.InviteSent); - setTimeout(() => { + this.inviteTimeout = setTimeout(() => { + this.inviteTimeout = null; if (this.state === CallState.InviteSent) { this.hangup(CallErrorCode.InviteTimeout, false); } @@ -1165,6 +1167,11 @@ export class MatrixCall extends EventEmitter { private terminate(hangupParty: CallParty, hangupReason: CallErrorCode, shouldEmit: boolean) { if (this.state === CallState.Ended) return; + if (this.inviteTimeout) { + clearTimeout(this.inviteTimeout); + this.inviteTimeout = null; + } + const remoteVid = this.getRemoteVideoElement(); const remoteAud = this.getRemoteAudioElement(); const localVid = this.getLocalVideoElement();