diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 72b927bd9c7..cfc19b2fe4e 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -535,6 +535,7 @@ export class MatrixCall extends EventEmitter { this.emit(CallEvent.FeedsChanged, this.feeds); } + // TODO: Find out what is going on here // why do we enable audio (and only audio) tracks here? -- matthew setTracksEnabled(stream.getAudioTracks(), true); @@ -708,8 +709,6 @@ export class MatrixCall extends EventEmitter { this.getUserMediaFailed(e); return; } - } else if (this.localUsermediaStream) { - this.gotUserMediaForAnswer(this.localUsermediaStream); } else if (this.waitForLocalAVStream) { this.setState(CallState.WaitLocalMedia); } @@ -721,14 +720,10 @@ export class MatrixCall extends EventEmitter { * @param {MatrixCall} newCall The new call. */ replacedBy(newCall: MatrixCall) { - logger.debug(this.callId + " being replaced by " + newCall.callId); if (this.state === CallState.WaitLocalMedia) { logger.debug("Telling new call to wait for local media"); newCall.waitForLocalAVStream = true; - } else if (this.state === CallState.CreateOffer) { - logger.debug("Handing local stream to new call"); - newCall.gotUserMediaForAnswer(this.localUsermediaStream); - } else if (this.state === CallState.InviteSent) { + } else if ([CallState.CreateOffer, CallState.InviteSent].includes(this.state)) { logger.debug("Handing local stream to new call"); newCall.gotUserMediaForAnswer(this.localUsermediaStream); } @@ -1029,7 +1024,6 @@ export class MatrixCall extends EventEmitter { this.pushLocalFeed(stream, SDPStreamMetadataPurpose.Usermedia); this.setState(CallState.CreateOffer); - logger.info("Got local AV stream with id " + this.localUsermediaStream.id); logger.debug("gotUserMediaForInvite -> " + this.type); // Now we wait for the negotiationneeded event }; @@ -1087,9 +1081,6 @@ export class MatrixCall extends EventEmitter { } this.pushLocalFeed(stream, SDPStreamMetadataPurpose.Usermedia); - - logger.info("Got local AV stream with id " + this.localUsermediaStream.id); - this.setState(CallState.CreateAnswer); let myAnswer; diff --git a/src/webrtc/callEventHandler.ts b/src/webrtc/callEventHandler.ts index 2ad4bcc7132..0ce2472638a 100644 --- a/src/webrtc/callEventHandler.ts +++ b/src/webrtc/callEventHandler.ts @@ -80,7 +80,7 @@ export class CallEventHandler { continue; } try { - this.handleCallEvent(e); + await this.handleCallEvent(e); } catch (e) { logger.error("Caught exception handling call event", e); } @@ -100,7 +100,7 @@ export class CallEventHandler { if (event.isBeingDecrypted() || event.isDecryptionFailure()) { // add an event listener for once the event is decrypted. - event.once("Event.decrypted", () => { + event.once("Event.decrypted", async () => { if (!this.eventIsACall(event)) return; if (this.callEventBuffer.includes(event)) { @@ -110,7 +110,7 @@ export class CallEventHandler { // This one wasn't buffered so just run the event handler for it // straight away try { - this.handleCallEvent(event); + await this.handleCallEvent(event); } catch (e) { logger.error("Caught exception handling call event", e); } @@ -128,7 +128,7 @@ export class CallEventHandler { return type.startsWith("m.call.") || type.startsWith("org.matrix.call."); } - private handleCallEvent(event: MatrixEvent) { + private async handleCallEvent(event: MatrixEvent) { const content = event.getContent(); const type = event.getType() as EventType; const weSentTheEvent = event.getSender() === this.client.credentials.userId; @@ -169,7 +169,7 @@ export class CallEventHandler { } call.callId = content.call_id; - call.initWithInvite(event); + await call.initWithInvite(event); this.calls.set(call.callId, call); // if we stashed candidate events for that call ID, play them back now @@ -201,9 +201,11 @@ export class CallEventHandler { // we've got an invite, pick the incoming call because we know // we haven't sent our invite yet otherwise, pick whichever // call has the lowest call ID (by string comparison) - if (existingCall.state === CallState.WaitLocalMedia || - existingCall.state === CallState.CreateOffer || - existingCall.callId > call.callId) { + if ( + existingCall.state === CallState.WaitLocalMedia || + existingCall.state === CallState.CreateOffer || + existingCall.callId > call.callId + ) { logger.log( "Glare detected: answering incoming call " + call.callId + " and canceling outgoing call " + existingCall.callId,