From 7af9440ed09596a3d1f215ea4524a127f09213c4 Mon Sep 17 00:00:00 2001 From: Kevin Kipp Date: Wed, 14 Aug 2024 13:12:25 -0500 Subject: [PATCH 1/3] Retry on pushing tracks --- app/utils/rxjs/RxjsPeer.client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils/rxjs/RxjsPeer.client.ts b/app/utils/rxjs/RxjsPeer.client.ts index f7b86d7f..19804311 100644 --- a/app/utils/rxjs/RxjsPeer.client.ts +++ b/app/utils/rxjs/RxjsPeer.client.ts @@ -279,7 +279,7 @@ export class RxjsPeer { }) }) } - }) + }).pipe(retry(2)) } pushTrack( From b00b65c83c2ebc4539fb374b7e95df2d7b30b219 Mon Sep 17 00:00:00 2001 From: Kevin Kipp Date: Wed, 14 Aug 2024 13:12:58 -0500 Subject: [PATCH 2/3] Bail on re-establishing connection if possible --- app/utils/rxjs/RxjsPeer.client.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/app/utils/rxjs/RxjsPeer.client.ts b/app/utils/rxjs/RxjsPeer.client.ts index 19804311..8aa33ba6 100644 --- a/app/utils/rxjs/RxjsPeer.client.ts +++ b/app/utils/rxjs/RxjsPeer.client.ts @@ -92,6 +92,7 @@ export class RxjsPeer { // for the best like we do here for now) const timeoutSeconds = 7 iceTimeout = window.setTimeout(() => { + if (peerConnection.iceConnectionState === 'connected') return console.debug( `💥 Peer iceConnectionState was ${peerConnection.iceConnectionState} for more than ${timeoutSeconds} seconds` ) From 5d6ccc292b04bf8e9739bd672a8673ccc235870b Mon Sep 17 00:00:00 2001 From: Kevin Kipp Date: Wed, 14 Aug 2024 13:14:14 -0500 Subject: [PATCH 3/3] Fix cleanup logic when waiting for peer connection to be connected --- app/utils/rxjs/RxjsPeer.client.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/utils/rxjs/RxjsPeer.client.ts b/app/utils/rxjs/RxjsPeer.client.ts index 8aa33ba6..b03e4b40 100644 --- a/app/utils/rxjs/RxjsPeer.client.ts +++ b/app/utils/rxjs/RxjsPeer.client.ts @@ -248,7 +248,7 @@ export class RxjsPeer { await peerConnection.setRemoteDescription( new RTCSessionDescription(response.sessionDescription) ) - await connected(peerConnection) + await peerConnectionIsConnected(peerConnection) } return { @@ -425,7 +425,7 @@ export class RxjsPeer { if (renegotiationResponse.errorCode) { throw new Error(renegotiationResponse.errorDescription) } else { - await connected(peerConnection) + await peerConnectionIsConnected(peerConnection) } } @@ -560,26 +560,30 @@ async function resolveTrack( }) } -async function connected(peerConnection: RTCPeerConnection) { +async function peerConnectionIsConnected(peerConnection: RTCPeerConnection) { if (peerConnection.connectionState !== 'connected') { const connected = new Promise((res, rej) => { // timeout after 5s - setTimeout(rej, 5000) + const timeout = setTimeout(() => { + peerConnection.removeEventListener( + 'connectionstatechange', + connectionStateChangeHandler + ) + rej() + }, 5000) const connectionStateChangeHandler = () => { if (peerConnection.connectionState === 'connected') { peerConnection.removeEventListener( 'connectionstatechange', connectionStateChangeHandler ) + clearTimeout(timeout) res(undefined) } } peerConnection.addEventListener( 'connectionstatechange', - connectionStateChangeHandler, - { - once: true, - } + connectionStateChangeHandler ) })