diff --git a/app/active_calls/resources/dashboard/active_calls.php b/app/active_calls/resources/dashboard/active_calls.php index f8369362e3..cddc0cf7fc 100644 --- a/app/active_calls/resources/dashboard/active_calls.php +++ b/app/active_calls/resources/dashboard/active_calls.php @@ -82,9 +82,10 @@ if ($dashboard_details_state != 'disabled') { echo "
| ".$text['label-cid-number']." | \n"; - echo "".$text['label-destination']." | \n"; - echo "".$text['label-status']." | \n"; + echo "".$text['label-cid-number']." | \n"; + echo "".$text['label-destination']." | \n"; + echo "".$text['label-status']." | \n"; + echo "".$text['label-duration']." | \n"; echo "${call.caller_caller_id_number} | ' . PHP_EOL; echo '${call.caller_destination_number} | ' . PHP_EOL; echo '${call.answer_state} | ' . PHP_EOL; +echo ''.PHP_EOL; ?>`; //end string block row.style.display = 'table-row'; @@ -390,6 +395,11 @@ echo ' | ${call.answer_state} | ' . PHP_EOL; // add the uuid to the map callsMap.set(call.unique_id, row); + // start the timer + start_duration_timer(call.unique_id, call.caller_channel_created_time); + + // add the uuid to the map + callsMap.set(call.unique_id, row); } updateCount(); } @@ -443,6 +453,42 @@ echo '${call.answer_state} | ' . PHP_EOL; calls_active_count.textContent = `${visibleCount}`; } + function start_duration_timer(uuid, start_time) { + const td = document.getElementById(`duration_${uuid}`) + + // Render function closes over startMs + function render() { + //calculate already elapsed time + const start = new Date(start_time / 1000); + const now = new Date(); + const elapsed = Math.floor(now.getTime() - start.getTime()); + + //format time + const hh = Math.floor(elapsed / (1000 * 3600)).toString(); + const mm = Math.floor((elapsed % (1000 * 3600)) / (1000 * 60)).toString().padStart(2, "0"); + const ss = Math.floor((elapsed % (1000 * 60)) / 1000).toString().padStart(2, "0"); // Convert remaining milliseconds to seconds + + td.textContent = `${hh}:${mm}:${ss}`; + } + + render(); + const timerId = setInterval(render, 1000); + + timers[uuid] = timerId + + // Return stop function + return () => clearInterval(timerId); + } + + function stop_duration_timer(uuid) { + //clear the timer on the row + const timer_id = timers[uuid] + if (timer_id) { + clearInterval(timer_id) + delete timers[uuid] + } + } + function hangup_call(call) { const row = callsMap.get(call.unique_id); if (row) { @@ -458,6 +504,7 @@ echo '${call.answer_state} | ' . PHP_EOL; const totalCount = callsMap.size; calls_active_count.textContent = `${visibleCount}`; + stop_duration_timer(uuid); row.remove(); } }
|---|