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,15 +193,17 @@ export class EngineConnection {
) )
} }
Promise.all([ if (this.shouldTrace()) {
handshakeSpan.promise, Promise.all([
iceSpan.promise, handshakeSpan.promise,
dataChannelSpan.promise, iceSpan.promise,
mediaTrackSpan.promise, dataChannelSpan.promise,
]).then(() => { mediaTrackSpan.promise,
console.log('All spans finished, reporting') ]).then(() => {
webrtcMediaTransaction?.finish() console.log('All spans finished, reporting')
}) webrtcMediaTransaction?.finish()
})
}
this.onWebsocketOpen(this) this.onWebsocketOpen(this)
}) })
@ -302,7 +304,9 @@ export class EngineConnection {
this.pc.addEventListener('connectionstatechange', (event) => { this.pc.addEventListener('connectionstatechange', (event) => {
if (this.pc?.iceConnectionState === 'connected') { if (this.pc?.iceConnectionState === 'connected') {
iceSpan.resolve?.() if (this.shouldTrace()) {
iceSpan.resolve?.()
}
} }
}) })