From 75750ed760c9518518d171fad695b4ab7eb68dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sun, 15 Aug 2021 12:56:48 +0200 Subject: [PATCH 1/7] Add a comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/webrtc/call.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 72b927bd9c7..028c6c8988a 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); From 4da49d926bf8354fab25dc51ac43cbf99dd3c1e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sun, 15 Aug 2021 12:57:27 +0200 Subject: [PATCH 2/7] Remove unnecessary logs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/webrtc/call.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 028c6c8988a..931d06308ba 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -722,7 +722,6 @@ 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; @@ -1030,7 +1029,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 }; @@ -1088,9 +1086,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; From 408976a1998608fe2c0d1319e5b57de238b8842d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sun, 15 Aug 2021 12:58:38 +0200 Subject: [PATCH 3/7] Simplifie some code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/webrtc/call.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 931d06308ba..56952eeb0b9 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -725,10 +725,7 @@ export class MatrixCall extends EventEmitter { 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); } From e6d1909f0b0bffb005f25d772f6b6cb989f838fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sun, 15 Aug 2021 13:02:39 +0200 Subject: [PATCH 4/7] Remove weird method call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we can get localUsermediaStream gotUserMediaForAnswer() has alredy been called before Signed-off-by: Šimon Brandner --- src/webrtc/call.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 56952eeb0b9..cfc19b2fe4e 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -709,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); } From f3856d569dfd594d08b53c9d375ecb2e5613c739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sun, 15 Aug 2021 13:03:08 +0200 Subject: [PATCH 5/7] Reformat some code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/webrtc/callEventHandler.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/webrtc/callEventHandler.ts b/src/webrtc/callEventHandler.ts index 2ad4bcc7132..8620a3f977c 100644 --- a/src/webrtc/callEventHandler.ts +++ b/src/webrtc/callEventHandler.ts @@ -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, From 51e815f0cb166e411f44453c9cd3bb87974ec8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sun, 15 Aug 2021 13:03:18 +0200 Subject: [PATCH 6/7] Fix glare MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/webrtc/callEventHandler.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webrtc/callEventHandler.ts b/src/webrtc/callEventHandler.ts index 8620a3f977c..421cd621f15 100644 --- a/src/webrtc/callEventHandler.ts +++ b/src/webrtc/callEventHandler.ts @@ -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 From d65b48204b88f92963be15f1baf2382dcb7e8e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Mon, 16 Aug 2021 13:14:04 +0200 Subject: [PATCH 7/7] Await handleCallEvent() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/webrtc/callEventHandler.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/webrtc/callEventHandler.ts b/src/webrtc/callEventHandler.ts index 421cd621f15..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); }