fix(ui): P2P badge showing stale status from previous call
Some checks failed
Mirror to GitHub / mirror (push) Failing after 26s
Build Release Binaries / build-amd64 (push) Failing after 3m47s

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) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-04-14 12:02:06 +04:00
parent 5a03da72d3
commit 6805caae0e

View File

@@ -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";