diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 4889c942110..4b5dcbae614 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -343,7 +343,7 @@ export class MatrixCall extends TypedEventEmitter = []; private candidateSendTries = 0; - private sentEndOfCandidates = false; + private candidatesEnded = false; private feeds: Array = []; private usermediaSenders: Array = []; private screensharingSenders: Array = []; @@ -1597,6 +1597,11 @@ export class MatrixCall extends TypedEventEmitter => { if (event.candidate) { + if (this.candidatesEnded) { + logger.warn("Got candidate after candidates have ended - ignoring!"); + return; + } + logger.debug( "Call " + this.callId + " got local ICE " + event.candidate.sdpMid + " candidate: " + event.candidate.candidate, @@ -1606,29 +1611,18 @@ export class MatrixCall extends TypedEventEmitter { logger.debug(`Call ${this.callId} ice gathering state changed to ${this.peerConn.iceGatheringState}`); - if (this.peerConn.iceGatheringState === 'complete' && !this.sentEndOfCandidates) { - // If we didn't get an empty-string candidate to signal the end of candidates, - // create one ourselves now gathering has finished. - // We cast because the interface lists all the properties as required but we - // only want to send 'candidate' - // XXX: We probably want to send either sdpMid or sdpMLineIndex, as it's not strictly - // correct to have a candidate that lacks both of these. We'd have to figure out what - // previous candidates had been sent with and copy them. - const c = { - candidate: '', - } as RTCIceCandidate; - this.queueCandidate(c); - this.sentEndOfCandidates = true; + if (this.peerConn.iceGatheringState === 'complete') { + this.queueCandidate(null); } }; @@ -2247,7 +2241,12 @@ export class MatrixCall extends TypedEventEmitter candidate.toJSON()) }; + if (this.candidatesEnded) { + // If there are no more candidates, signal this by adding an empty string candidate + content.candidates.push({ + candidate: '', + }); + } logger.debug(`Call ${this.callId} attempting to send ${candidates.length} candidates`); try { await this.sendVoipEvent(EventType.CallCandidates, content);