Add host connection status check endpoint and UI indicator

- Implement handle_connection_status API to test host port reachability
- Display Host:Up/Down status in the UI
This commit is contained in:
dido committed 2026-09-18 12:01:18 +03:00
1 parent 1209384cad
commit e4a3066445
3 files changed
+92

No files matched your search

+40
View File
@@ -10,6 +10,7 @@ let maxUploadSize = localStorage.getItem('maxUploadSize') ? parseInt(localStorag
let apiBaseUrl = window.location.origin;
let backendWsPort = null;
let backendWsHost = null;
let hostStatusTimer = null;
// Use the frontend proxy so the browser does not need direct access to the backend port.
function getWsUrl() {
@@ -41,6 +42,8 @@ async function loadSavedConnections() {
if (!conn.terminalBuffer) conn.terminalBuffer = [];
});
renderConnectionList();
refreshHostStatuses();
startHostStatusPolling();
if (connections.length > 0) {
term.writeln(`[Loaded ${connections.length} connections from server]`);
}
@@ -454,6 +457,9 @@ function renderConnectionList() {
<span class="connection-status ${conn.connected ? 'connected' : 'disconnected'}"></span>
${conn.username}@${conn.host}:${conn.port}
</div>
<div class="host-status ${conn.hostStatus === true ? 'up' : conn.hostStatus === false ? 'down' : 'checking'}">
Host: ${conn.hostStatus === true ? 'Up' : conn.hostStatus === false ? 'Down' : 'Checking...'}
</div>
<div class="connection-actions" onclick="event.stopPropagation()">
${conn.connected
? `<button class="btn-small btn-disconnect" onclick="disconnectConnection('${conn.id}')">Disconnect</button>`
@@ -467,6 +473,40 @@ function renderConnectionList() {
});
}
async function refreshHostStatuses() {
if (!authToken || connections.length === 0) return;
connections.forEach(conn => { conn.hostStatus = null; });
renderConnectionList();
try {
const response = await fetch(`${apiBaseUrl}/api/connections/status`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
},
body: JSON.stringify({ ids: connections.map(conn => conn.id) })
});
if (!response.ok) return;
const data = await response.json();
connections.forEach(conn => {
if (Object.prototype.hasOwnProperty.call(data.statuses || {}, conn.id)) {
conn.hostStatus = data.statuses[conn.id];
}
});
renderConnectionList();
} catch (e) {
console.warn('Failed to refresh host statuses:', e);
}
}
function startHostStatusPolling() {
if (hostStatusTimer) clearInterval(hostStatusTimer);
hostStatusTimer = setInterval(refreshHostStatuses, 30000);
}
function selectConnection(id) {
currentConnectionId = id;
const conn = getCurrentConnection();