From 9f87229a8f9dc7bc91178a0e9ebd58409410ef26 Mon Sep 17 00:00:00 2001 From: SWINDI Date: Thu, 20 Aug 2026 09:53:50 +0200 Subject: [PATCH] fix: don't close peer connection on transient 'disconnected' state Both connectionstatechange handlers treated 'disconnected' the same as 'closed' and 'failed' and immediately called peer.close(). Per the WebRTC spec, 'disconnected' only means that ICE connectivity checks are currently failing. The connection frequently recovers on its own -- brief network hiccups, Wi-Fi roaming between access points, or NAT rebinding all trigger it. Calling close() makes that recovery impossible, because a closed RTCPeerConnection cannot be reopened. The result was that a short network glitch permanently killed the stream and the viewer had to reload the page. Leaving 'disconnected' unhandled lets the browser's own ICE recovery do its job. Refs #53 --- ui/src/useRoom.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/ui/src/useRoom.ts b/ui/src/useRoom.ts index 5385b9b1..bebbf291 100644 --- a/ui/src/useRoom.ts +++ b/ui/src/useRoom.ts @@ -62,11 +62,7 @@ const hostSession = async ({ peer.onconnectionstatechange = (event) => { console.log('host change', event); - if ( - peer.connectionState === 'closed' || - peer.connectionState === 'disconnected' || - peer.connectionState === 'failed' - ) { + if (peer.connectionState === 'closed' || peer.connectionState === 'failed') { peer.close(); done(); } @@ -134,11 +130,7 @@ const clientSession = async ({ }; peer.onconnectionstatechange = (event) => { console.log('client change', event); - if ( - peer.connectionState === 'closed' || - peer.connectionState === 'disconnected' || - peer.connectionState === 'failed' - ) { + if (peer.connectionState === 'closed' || peer.connectionState === 'failed') { peer.close(); done(); }