Prevent duplicate audio streams from rapid play button clicks

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.
pull/279/head
Broque Thomas 4 days ago
parent 6fb32228e0
commit 121f221a4f

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

Loading…
Cancel
Save