From 7c9aaeafa2c308ff7ccb457859ab7d390f349a45 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Fri, 8 Sep 2023 16:40:08 -0400 Subject: [PATCH] Guard Promise resolution with a shouldTrace() (#424) The Promises are created behind a shouldTrace, so they'll be undefined if you shouldn't be tracing. As a result, we need to guard the resoluton of the promises. Thanks @mlfarrell for spotting this in local dev! Signed-off-by: Paul Tagliamonte --- src/lang/std/engineConnection.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/lang/std/engineConnection.ts b/src/lang/std/engineConnection.ts index 33605d3e9..8104f9d3a 100644 --- a/src/lang/std/engineConnection.ts +++ b/src/lang/std/engineConnection.ts @@ -193,15 +193,17 @@ export class EngineConnection { ) } - Promise.all([ - handshakeSpan.promise, - iceSpan.promise, - dataChannelSpan.promise, - mediaTrackSpan.promise, - ]).then(() => { - console.log('All spans finished, reporting') - webrtcMediaTransaction?.finish() - }) + if (this.shouldTrace()) { + Promise.all([ + handshakeSpan.promise, + iceSpan.promise, + dataChannelSpan.promise, + mediaTrackSpan.promise, + ]).then(() => { + console.log('All spans finished, reporting') + webrtcMediaTransaction?.finish() + }) + } this.onWebsocketOpen(this) }) @@ -302,7 +304,9 @@ export class EngineConnection { this.pc.addEventListener('connectionstatechange', (event) => { if (this.pc?.iceConnectionState === 'connected') { - iceSpan.resolve?.() + if (this.shouldTrace()) { + iceSpan.resolve?.() + } } })