From 1612c21c8e9bda4dbc9bcbcfa3a8f4beb4e47bf5 Mon Sep 17 00:00:00 2001 From: 3nd3r Date: Fri, 2 Jan 2026 21:59:26 -0600 Subject: [PATCH] Improve listener error reporting and add auto-retry for empty buffers --- script.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index e3714a4..68e52c6 100644 --- a/script.js +++ b/script.js @@ -2397,9 +2397,28 @@ async function enableListenerAudio() { if (audioText) audioText.textContent = 'RETRY ENABLE'; if (stashedStatus) { - stashedStatus.textContent = '⚠️ ' + (error.message === 'Timeout waiting for audio data' - ? 'No stream data yet. Is the DJ broadcasting?' - : 'Browser blocked audio. Please click again.'); + // Show the actual error message to help debugging + let errorMsg = error.name + ': ' + error.message; + if (error.name === 'NotAllowedError') { + errorMsg = 'Browser blocked audio (NotAllowedError). Check permissions.'; + } else if (error.name === 'NotSupportedError') { + errorMsg = 'Format not supported or buffer empty (NotSupportedError).'; + } + + stashedStatus.textContent = '⚠️ ' + errorMsg; + + // If it was a NotSupportedError (likely empty buffer), we can try to recover automatically + // by waiting for data and trying to play again (even if it might fail without gesture) + if (error.name === 'NotSupportedError') { + console.log('🔄 Retrying playback in background once data arrives...'); + const retryInterval = setInterval(() => { + if (window.listenerAudio.buffered && window.listenerAudio.buffered.length > 0) { + clearInterval(retryInterval); + window.listenerAudio.play().catch(e => console.error('Background retry failed:', e)); + stashedStatus.textContent = '🟢 Recovered - Playing'; + } + }, 1000); + } } } }