From 7442ff7e42ea3f2d8d1338050ff552483a2ee2ab Mon Sep 17 00:00:00 2001 From: sergystepanov Date: Tue, 9 Jun 2026 15:05:32 +0300 Subject: [PATCH] Reset ICE buffering on the client on ICE restarts --- web/js/network/webrtc.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/js/network/webrtc.js b/web/js/network/webrtc.js index d520b551..4fb87342 100755 --- a/web/js/network/webrtc.js +++ b/web/js/network/webrtc.js @@ -186,6 +186,13 @@ export const webrtc = { log.debug("[rtc] negotiation"); }; pc.ontrack = (event) => stream.addTrack(event.track); + pc.onsignalingstatechange = () => { + log.debug(`[rtc] [sig] state: ${pc.signalingState}`); + + if (pc.signalingState === "stable") { + ice.flush(pc); + } + }; connectionTime = performance.now(); if (initiator) { @@ -225,7 +232,9 @@ export const webrtc = { }, candidate: (/** @type {RTCIceCandidateInit | string} */ candidate) => { log.debug(`[rtc] [ice] remote`, candidate); - if (pc) ice.add(pc, candidate, !pc.remoteDescription); + const buffered = + !pc.remoteDescription || pc.signalingState !== "stable"; + if (pc) ice.add(pc, candidate, buffered); }, send: (chan, data) => { const ch = channels.get(chan);