From b347ca472faaf8b7ba8e043d39bf219966888670 Mon Sep 17 00:00:00 2001 From: Filipi Fuchter Date: Tue, 29 Apr 2025 12:04:20 -0300 Subject: [PATCH] Checking the state again to avoid any eventual race condition --- examples/p2p-webrtc/voice-agent/index.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/p2p-webrtc/voice-agent/index.html b/examples/p2p-webrtc/voice-agent/index.html index e0250a58f..a6def2b30 100644 --- a/examples/p2p-webrtc/voice-agent/index.html +++ b/examples/p2p-webrtc/voice-agent/index.html @@ -26,7 +26,7 @@ const waitForIceGatheringComplete = async (pc, timeoutMs = 2000) => { if (pc.iceGatheringState === 'complete') return; - console.log("Waiting for ICE gathering to complete..."); + console.log("Waiting for ICE gathering to complete. Current state:", pc.iceGatheringState); return new Promise((resolve) => { let timeoutId; const checkState = () => { @@ -47,6 +47,8 @@ }; pc.addEventListener('icegatheringstatechange', checkState); timeoutId = setTimeout(onTimeout, timeoutMs); + // Checking the state again to avoid any eventual race condition + checkState(); }); };