From 49f2d1501c5217c9da37992116dbefefd08cd90a Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 8 Oct 2020 15:42:39 +0100 Subject: [PATCH] Set the type of the call based on the tracks Remove the old hack of inspecting the SDP which no longer seems to be necessary. --- src/webrtc/call.ts | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 15b7135fc..e2fa2d010 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -416,23 +416,20 @@ export class MatrixCall extends EventEmitter { return; } + // According to previous comments in this file, firefox at some point did not + // add streams until media started ariving on them. Testing latest firefox + // (81 at time of writing), this is no longer a problem, so let's do it the correct way. + if (!this.remoteStream || this.remoteStream.getTracks().length === 0) { + logger.error("No remote stream or no tracks after setting remote description!"); + this.terminate(CallParty.Local, CallErrorCode.SetRemoteDescription, false); + return; + } + + this.type = this.remoteStream.getTracks().some(t => t.kind === 'video') ? CallType.Video : CallType.Voice; + this.setState(CallState.Ringing); this.direction = CallDirection.Inbound; - // firefox and OpenWebRTC's RTCPeerConnection doesn't add streams until it - // starts getting media on them so we need to figure out whether a video - // channel has been offered by ourselves. - // XXX: This comment is probably outdated: check & remove this if so - if ( - this.msg.offer && - this.msg.offer.sdp && - this.msg.offer.sdp.indexOf('m=video') > -1 - ) { - this.type = CallType.Video; - } else { - this.type = CallType.Voice; - } - if (event.getLocalAge()) { setTimeout(() => { if (this.state == CallState.Ringing) { @@ -918,10 +915,6 @@ export class MatrixCall extends EventEmitter { private onTrack = (ev: RTCTrackEvent) => { logger.debug(`Track id ${ev.track.id} of kind ${ev.track.kind} added`); - if (ev.track.kind == 'video') { - this.type = CallType.Video; - } - // This is relatively complex as we may get any number of tracks that may // be in any number of streams, or not in streams at all, etc. // I'm not entirely sure how this API is supposed to be used: it would