From 6805caae0e5cdbfa450ba2b2f75c77ffd56778bc Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Tue, 14 Apr 2026 12:02:06 +0400 Subject: [PATCH] fix(ui): P2P badge showing stale status from previous call The callDebugBuffer persisted across calls, so .find() returned the path_negotiated event from Call 1 (P2P Direct) when rendering the badge during Call 2 (Relay). Two fixes: 1. Clear callDebugBuffer in showConnectScreen() between calls 2. Use .findLast() instead of .find() so the most recent event wins Co-Authored-By: Claude Opus 4.6 (1M context) --- desktop/src/main.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/desktop/src/main.ts b/desktop/src/main.ts index ebb9fc0..5a05d39 100644 --- a/desktop/src/main.ts +++ b/desktop/src/main.ts @@ -886,6 +886,9 @@ function showConnectScreen() { connectBtn.textContent = "Connect"; levelBar.style.width = "0%"; directCallPeer = null; + // Clear stale call-debug events so the next call's P2P indicator + // doesn't pick up a path_negotiated from a previous call. + callDebugBuffer.length = 0; // Clear the media-degraded banner if present const banner = document.getElementById("media-degraded-banner"); if (banner) banner.remove(); @@ -1052,8 +1055,9 @@ async function pollStatus() { if (directCallPeer) { // Check the debug buffer for the race result to label // the connection type (P2P Direct vs Relay). - const pathNeg = callDebugBuffer.find((e) => e.step === "connect:path_negotiated"); - const engineOk = callDebugBuffer.find((e) => e.step === "connect:call_engine_started"); + // findLast: use the MOST RECENT event in case buffer has leftovers + const pathNeg = callDebugBuffer.findLast((e) => e.step === "connect:path_negotiated"); + const engineOk = callDebugBuffer.findLast((e) => e.step === "connect:call_engine_started"); if (engineOk) { if (pathNeg?.details?.use_direct === true) { dcBadge.textContent = "P2P Direct";