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
This commit is contained in:
SWINDI
2026-08-20 09:53:50 +02:00
committed by Jannis Mattheis
parent eab15068a1
commit 9f87229a8f
+2 -10
View File
@@ -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();
}