From 9832f899c363caa5c2b036212e3730c4ee07f5c3 Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Fri, 15 Aug 2025 10:28:39 -0700 Subject: [PATCH] Fix alert system to stop when queues become empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Enhance checkForNewCalls to monitor queue emptiness and auto-stop alerts - Update startAlert to verify waiting calls exist before starting - Add continuous monitoring to stop alerts when no calls remain - Prevent false alerts when calls disconnect before pickup - Add console logging for better alert behavior tracking 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- assets/js/browser-phone-frontend.js | 41 +++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/assets/js/browser-phone-frontend.js b/assets/js/browser-phone-frontend.js index d3ddce6..1d7ef6a 100644 --- a/assets/js/browser-phone-frontend.js +++ b/assets/js/browser-phone-frontend.js @@ -508,22 +508,39 @@ * Check for new calls in queues and trigger alerts */ function checkForNewCalls(newQueues) { + let hasWaitingCalls = false; + let newCallDetected = false; + newQueues.forEach(function(queue) { const queueId = queue.id; const currentWaiting = parseInt(queue.current_waiting) || 0; const previousWaiting = lastQueueUpdate[queueId] || 0; + // Track if any queue has waiting calls + if (currentWaiting > 0) { + hasWaitingCalls = true; + } + // If waiting count increased, we have new calls if (currentWaiting > previousWaiting) { console.log('New call detected in queue:', queue.queue_name); - // Trigger alert if enabled - if (alertEnabled && !currentCall) { - startAlert(); - } + newCallDetected = true; } lastQueueUpdate[queueId] = currentWaiting; }); + + // Manage alerts based on queue state + if (alertEnabled && !currentCall) { + if (newCallDetected) { + // Start alert for new calls + startAlert(); + } else if (!hasWaitingCalls) { + // Stop alert if no calls are waiting in any queue + console.log('No calls waiting in any queue, stopping alerts'); + stopAlert(); + } + } } /** @@ -871,13 +888,27 @@ function startAlert() { if (!alertEnabled || alertInterval) return; + // Check if there are actually waiting calls before starting alert + const hasWaitingCalls = userQueues.some(q => parseInt(q.current_waiting) > 0); + if (!hasWaitingCalls) { + console.log('No waiting calls found, not starting alert'); + return; + } + // Play initial alert playAlertSound(); // Repeat every 30 seconds alertInterval = setInterval(function() { if (alertEnabled && !currentCall) { - playAlertSound(); + // Check if there are still waiting calls + const stillHasWaitingCalls = userQueues.some(q => parseInt(q.current_waiting) > 0); + if (stillHasWaitingCalls) { + playAlertSound(); + } else { + console.log('No more waiting calls, stopping alert'); + stopAlert(); + } } else { stopAlert(); }