diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index cfc19b2fe4e..72b927bd9c7 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -535,7 +535,6 @@ 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); @@ -709,6 +708,8 @@ 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); } @@ -720,10 +721,14 @@ 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 ([CallState.CreateOffer, CallState.InviteSent].includes(this.state)) { + } else if (this.state === CallState.CreateOffer) { + logger.debug("Handing local stream to new call"); + newCall.gotUserMediaForAnswer(this.localUsermediaStream); + } else if (this.state === CallState.InviteSent) { logger.debug("Handing local stream to new call"); newCall.gotUserMediaForAnswer(this.localUsermediaStream); } @@ -1024,6 +1029,7 @@ 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 }; @@ -1081,6 +1087,9 @@ 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 0ce2472638a..2ad4bcc7132 100644 --- a/src/webrtc/callEventHandler.ts +++ b/src/webrtc/callEventHandler.ts @@ -80,7 +80,7 @@ export class CallEventHandler { continue; } try { - await this.handleCallEvent(e); + 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", async () => { + event.once("Event.decrypted", () => { 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 { - await this.handleCallEvent(event); + 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 async handleCallEvent(event: MatrixEvent) { + private 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; - await call.initWithInvite(event); + call.initWithInvite(event); this.calls.set(call.callId, call); // if we stashed candidate events for that call ID, play them back now @@ -201,11 +201,9 @@ 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,