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 <paul@kittycad.io>
This commit is contained in:
Paul Tagliamonte
2023-09-08 16:40:08 -04:00
committed by GitHub
parent 46c0078885
commit 7c9aaeafa2

View File

@ -193,6 +193,7 @@ export class EngineConnection {
) )
} }
if (this.shouldTrace()) {
Promise.all([ Promise.all([
handshakeSpan.promise, handshakeSpan.promise,
iceSpan.promise, iceSpan.promise,
@ -202,6 +203,7 @@ export class EngineConnection {
console.log('All spans finished, reporting') console.log('All spans finished, reporting')
webrtcMediaTransaction?.finish() webrtcMediaTransaction?.finish()
}) })
}
this.onWebsocketOpen(this) this.onWebsocketOpen(this)
}) })
@ -302,8 +304,10 @@ export class EngineConnection {
this.pc.addEventListener('connectionstatechange', (event) => { this.pc.addEventListener('connectionstatechange', (event) => {
if (this.pc?.iceConnectionState === 'connected') { if (this.pc?.iceConnectionState === 'connected') {
if (this.shouldTrace()) {
iceSpan.resolve?.() iceSpan.resolve?.()
} }
}
}) })
this.pc.addEventListener('icecandidate', (event) => { this.pc.addEventListener('icecandidate', (event) => {