Skip to content

Commit

Permalink
Add a console.error when ICE fails (#1067)
Browse files Browse the repository at this point in the history
This is purely cosmetic right now, but I want to try and make it easier
to tell when the browser is unable to communicate with the ICE server
by writing it to the console.

I want to add some Sentry logging in the future, but for now, when we
see a stream failing to start, we can at least see what I suspect is the
most common trigger in the console.

Signed-off-by: Paul R. Tagliamonte <paul@kittycad.io>
  • Loading branch information
paultag committed Nov 13, 2023
1 parent fa7943d commit 381d0b3
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/lang/std/engineConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ export class EngineConnection {
}
})

this.pc.addEventListener('icecandidateerror', (_event) => {
const event = _event as RTCPeerConnectionIceErrorEvent
console.error(
`ICE candidate returned an error: ${event.errorCode}: ${event.errorText} for ${event.url}`
)
})

this.pc.addEventListener('connectionstatechange', (event) => {
if (this.pc?.iceConnectionState === 'connected') {
if (this.shouldTrace()) {
iceSpan.resolve?.()
}
} else if (this.pc?.iceConnectionState === 'failed') {
// failed is a terminal state; let's explicitly kill the
// connection to the server at this point.
console.log('failed to negotiate ice connection; restarting')
this.close()
}
})

this.websocket.addEventListener('open', (event) => {
if (this.shouldTrace()) {
websocketSpan.resolve?.()
Expand Down Expand Up @@ -351,19 +371,6 @@ export class EngineConnection {
// until the end of this function is setup of our end of the
// PeerConnection and waiting for events to fire our callbacks.

this.pc.addEventListener('connectionstatechange', (event) => {
if (this.pc?.iceConnectionState === 'connected') {
if (this.shouldTrace()) {
iceSpan.resolve?.()
}
} else if (this.pc?.iceConnectionState === 'failed') {
// failed is a terminal state; let's explicitly kill the
// connection to the server at this point.
console.log('failed to negotiate ice connection; restarting')
this.close()
}
})

this.pc.addEventListener('icecandidate', (event) => {
if (!this.pc || !this.websocket) return
if (event.candidate !== null) {
Expand Down

1 comment on commit 381d0b3

@vercel
Copy link

@vercel vercel bot commented on 381d0b3 Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.