Skip to content

Commit

Permalink
webrtc: session: Add status updates to session class
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Apr 18, 2024
1 parent 767ef2a commit 690b169
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/libs/webrtc/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,22 @@ export class Session {
!this.selectedICEIPs.isEmpty() &&
!this.selectedICEIPs.some((address) => candidate.candidate!.includes(address))
) {
this.onStatusChange?.(`Ignoring ICE candidate ${candidate.candidate}`)
console.debug(`[WebRTC] [Session] ICE candidate ignored: ${JSON.stringify(candidate, null, 4)}`)
return
}

this.peerConnection
.addIceCandidate(candidate)
.then(() => console.debug(`[WebRTC] [Session] ICE candidate added: ${JSON.stringify(candidate, null, 4)}`))
.catch((reason) =>
.then(() => {
const msg = `ICE candidate added.`
console.debug(`[WebRTC] [Session] ${msg} ${JSON.stringify(candidate, null, 4)}`)
this.onStatusChange?.(msg)
})
.catch((reason) => {
console.error(`[WebRTC] [Session] Failed adding ICE candidate ${candidate}. Reason: ${reason}`)
)
this.onStatusChange?.(`Failed adding ICE candidate ${candidate}. Reason: ${reason}`)
})
}

/**
Expand All @@ -231,7 +237,9 @@ export class Session {
*/
private onIceCandidateError(event: Event): void {
const ev = event as RTCPeerConnectionIceErrorEvent
console.debug(`[WebRTC] [Session] ICE Candidate "${ev.url}" negotiation failed`)
const msg = `ICE Candidate "${ev.url}" negotiation failed.`
console.debug(`[WebRTC] [Session] ${msg}`)
this.onStatusChange?.(msg)
}

/**
Expand All @@ -248,7 +256,9 @@ export class Session {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
private onNegotiationNeeded(_event: Event): void {
console.debug('[WebRTC] [Session] Peer Connection is waiting for negotiation...')
const msg = 'Peer Connection is waiting for negotiation...'
console.debug(msg)
this.onStatusChange?.(msg)
}

/**
Expand All @@ -257,6 +267,7 @@ export class Session {
private onIceConnectionStateChange(): void {
const msg = `ICEConnection state changed to "${this.peerConnection.iceConnectionState}"`
console.debug('[WebRTC] [Session] ' + msg)
this.onStatusChange?.(msg)

if (this.peerConnection.iceConnectionState === 'failed') {
this.peerConnection.restartIce()
Expand All @@ -269,6 +280,7 @@ export class Session {
private onConnectionStateChange(): void {
const msg = `RTCPeerConnection state changed to "${this.peerConnection.connectionState}"`
console.debug('[WebRTC] [Session] ' + msg)
this.onStatusChange?.(msg)

if (this.peerConnection.connectionState === 'failed') {
this.onClose?.(this.id, 'PeerConnection failed')
Expand All @@ -289,7 +301,9 @@ export class Session {
*/
private onIceGatheringStateChange(): void {
if (this.peerConnection.iceGatheringState === 'complete') {
console.debug(`[WebRTC] [Session] ICE gathering completed for session ${this.id}`)
const msg = `ICE gathering completed for session ${this.id}`
console.debug(`[WebRTC] [Session] ${msg}`)
this.onStatusChange?.(msg)
}
}

Expand Down

0 comments on commit 690b169

Please sign in to comment.