mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Fix rounding causes negative timer (#7650)
When the floor operation is used it can go below zero causing the value to show as `-1👎-1` instead of 0:0:0 for a start time.
This commit is contained in:
@@ -339,21 +339,35 @@ echo "<script src='resources/javascript/arrows.js?v=$version'></script>\n";
|
||||
client.ws.addEventListener("open", async () => {
|
||||
try {
|
||||
console.log('Connected');
|
||||
console.log('Requesting authentication');
|
||||
await client.request('authentication');
|
||||
reconnectAttempts = 0;
|
||||
const status = document.getElementById('calls_active_count');
|
||||
status.style.backgroundColor = colors.INACTIVE;
|
||||
bindEventHandlers(client);
|
||||
console.log('Sent request for calls in progress');
|
||||
client.request('active.calls', 'in.progress');
|
||||
status.style.backgroundColor = colors.CONNECTED;
|
||||
} catch (err) {
|
||||
console.error("WS setup failed: ", err);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// Handle incoming messages for authentication
|
||||
client.ws.addEventListener("message", async (event) => {
|
||||
try {
|
||||
const message = JSON.parse(event.data);
|
||||
// Check for authentication request from server
|
||||
if (message.status_code === 407 && message.service_name === 'authentication') {
|
||||
console.log('Authentication required - sending credentials');
|
||||
await client.request('authentication');
|
||||
console.log('Authentication sent');
|
||||
const status = document.getElementById('calls_active_count');
|
||||
bindEventHandlers(client);
|
||||
console.log('Sent request for calls in progress');
|
||||
client.request('active.calls', 'in.progress');
|
||||
status.style.backgroundColor = colors.CONNECTED;
|
||||
}
|
||||
} catch (err) {
|
||||
// Let the ws_client handle other messages
|
||||
}
|
||||
});
|
||||
|
||||
// DISCONNECTED
|
||||
client.ws.addEventListener("close", async () => {
|
||||
const status = document.getElementById('calls_active_count');
|
||||
@@ -552,7 +566,7 @@ echo "<script src='resources/javascript/arrows.js?v=$version'></script>\n";
|
||||
replace_arrow_icon(uuid, 'local');
|
||||
row.dataset.forced_direction = 'local';
|
||||
}
|
||||
console.log('application', uuid, application_data);
|
||||
//console.log('application', uuid, application_data);
|
||||
update_call_element(`application_${uuid}`, application_data);
|
||||
}
|
||||
<?php endif; ?>
|
||||
@@ -782,7 +796,7 @@ echo "<script src='resources/javascript/arrows.js?v=$version'></script>\n";
|
||||
// add the row to the table
|
||||
tbody.appendChild(row);
|
||||
|
||||
console.log('NEW ROW ADDED', row.id);
|
||||
//console.log('NEW ROW ADDED', row.id);
|
||||
|
||||
// Hide/show domain column
|
||||
const domain = document.getElementById('th_domain');
|
||||
@@ -988,7 +1002,12 @@ echo "<script src='resources/javascript/arrows.js?v=$version'></script>\n";
|
||||
//calculate already elapsed time
|
||||
const start = new Date(start_time / 1000);
|
||||
const now = new Date();
|
||||
const elapsed = Math.floor(now.getTime() - start.getTime());
|
||||
let elapsed = Math.floor(now.getTime() - start.getTime());
|
||||
|
||||
// Fix negative timer issue - if start time is in the future, set elapsed to 0
|
||||
if (elapsed < 0) {
|
||||
elapsed = 0;
|
||||
}
|
||||
|
||||
//format time
|
||||
const hh = Math.floor(elapsed / (1000 * 3600)).toString();
|
||||
|
||||
@@ -267,31 +267,43 @@ if (!empty($_SESSION['user']['extension'])) {
|
||||
active_calls_widget_client.ws.addEventListener("open", async () => {
|
||||
try {
|
||||
console.log('Connected');
|
||||
console.log('Requesting authentication');
|
||||
reconnectAttempts = 0;
|
||||
|
||||
//set the status as inactive while waiting
|
||||
const status = document.getElementById('calls_active_count');
|
||||
status.style.backgroundColor = colors.INACTIVE;
|
||||
|
||||
//wait to be authenticated
|
||||
await active_calls_widget_client.request('authentication');
|
||||
reconnectAttempts = 0;
|
||||
|
||||
//bind active call event to function
|
||||
active_calls_widget_client.onEvent("CHANNEL_CALLSTATE", channel_callstate_event);
|
||||
console.log('Sent request for calls in progress');
|
||||
|
||||
//get the in progress calls
|
||||
active_calls_widget_client.request('active.calls', 'in.progress');
|
||||
|
||||
//display green circle for connected
|
||||
status.style.backgroundColor = colors.CONNECTED;
|
||||
} catch (err) {
|
||||
console.error("WS setup failed: ", err);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// Handle incoming messages for authentication
|
||||
active_calls_widget_client.ws.addEventListener("message", async (event) => {
|
||||
try {
|
||||
const message = JSON.parse(event.data);
|
||||
// Check for authentication request from server
|
||||
if (message.status_code === 407 && message.service_name === 'authentication') {
|
||||
console.log('Authentication required - sending credentials');
|
||||
await active_calls_widget_client.request('authentication');
|
||||
console.log('Authentication sent');
|
||||
|
||||
//bind active call event to function
|
||||
active_calls_widget_client.onEvent("CHANNEL_CALLSTATE", channel_callstate_event);
|
||||
console.log('Sent request for calls in progress');
|
||||
|
||||
//get the in progress calls
|
||||
active_calls_widget_client.request('active.calls', 'in.progress');
|
||||
|
||||
//display green circle for connected
|
||||
const status = document.getElementById('calls_active_count');
|
||||
status.style.backgroundColor = colors.CONNECTED;
|
||||
}
|
||||
} catch (err) {
|
||||
// Let the ws_client handle other messages
|
||||
}
|
||||
});
|
||||
|
||||
// DISCONNECTED
|
||||
active_calls_widget_client.ws.addEventListener("close", async () => {
|
||||
const status = document.getElementById('calls_active_count');
|
||||
@@ -320,8 +332,6 @@ if (!empty($_SESSION['user']['extension'])) {
|
||||
const other_leg_unique_id = call.other_leg_unique_id ?? '';
|
||||
switch (state) {
|
||||
case 'ringing':
|
||||
//calls that are already in progress should be answered status
|
||||
if (call.caller_channel_created_time > Date.now()) call.answer_state = 'answered';
|
||||
//update the data
|
||||
update_call(call);
|
||||
replace_arrow_color(uuid, colors.RINGING);
|
||||
@@ -461,15 +471,14 @@ echo '<td id="answer_state_${uuid}">${call.answer_state}</td>' . PHP_EOL;
|
||||
echo '<td id="duration_${uuid}"></td>'.PHP_EOL;
|
||||
?>`;
|
||||
//end string block
|
||||
// Only display calls that belong to the current domain (server-side filtering ensures proper security)
|
||||
// The backend filter already restricts calls based on user permissions
|
||||
row.style.display = 'table-row';
|
||||
|
||||
// add the row to the table
|
||||
tbody.appendChild(row);
|
||||
|
||||
console.log('NEW ROW ADDED', row.id);
|
||||
|
||||
// add the uuid to the map
|
||||
callsMap.set(call.unique_id, row);
|
||||
//console.log('NEW ROW ADDED', row.id);
|
||||
|
||||
// start the timer
|
||||
start_duration_timer(call.unique_id, call.caller_channel_created_time);
|
||||
@@ -541,7 +550,12 @@ echo '<td id="duration_${uuid}"></td>'.PHP_EOL;
|
||||
//calculate already elapsed time
|
||||
const start = new Date(start_time / 1000);
|
||||
const now = new Date();
|
||||
const elapsed = Math.floor(now.getTime() - start.getTime());
|
||||
let elapsed = Math.floor(now.getTime() - start.getTime());
|
||||
|
||||
// Fix rounding issue where floor can produce negative elapsed time
|
||||
if (elapsed < 0) {
|
||||
elapsed = 0;
|
||||
}
|
||||
|
||||
//format time
|
||||
const hh = Math.floor(elapsed / (1000 * 3600)).toString();
|
||||
|
||||
Reference in New Issue
Block a user