From 121f221a4f17ceb41a85ec2004ff8a8ddac37a35 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Sat, 11 Apr 2026 09:01:30 -0700 Subject: [PATCH] Prevent duplicate audio streams from rapid play button clicks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added _streamLock flag to startStream() that prevents concurrent stream requests when the user clicks play multiple times before the first request completes. Lock is released in finally block so it always clears on success, error, or exception. Previously, rapid clicks would fire multiple stream requests to the backend, each creating a separate audio playback — the only way to stop them was a browser force refresh. --- webui/static/script.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/webui/static/script.js b/webui/static/script.js index 43694708..32806aae 100644 --- a/webui/static/script.js +++ b/webui/static/script.js @@ -3307,9 +3307,17 @@ function setLoadingProgress(percentage) { // STREAMING FUNCTIONALITY // =============================== +let _streamLock = false; + async function startStream(searchResult) { // Start streaming a track - handles same track toggle and new track streaming try { + // Prevent multiple concurrent stream starts (rapid clicking) + if (_streamLock) { + console.log('⏳ Stream already starting, ignoring duplicate click'); + return; + } + console.log(`🎮 startStream() called with data:`, searchResult); // Check if this is the same track that's currently playing/loading @@ -3327,6 +3335,9 @@ async function startStream(searchResult) { return; } + // Lock to prevent duplicate stream starts + _streamLock = true; + // Different track or no current track - start new stream console.log("🎵 Starting new stream"); @@ -3373,6 +3384,8 @@ async function startStream(searchResult) { showToast(`Failed to start stream: ${error.message}`, 'error'); hideLoadingAnimation(); clearTrack(); + } finally { + _streamLock = false; } }