fix(status): stop the connection badge from lying about device state

loadMessages() called updateStatus('connected') on every successful
/api/messages fetch -- a DB read that succeeds regardless of whether
the meshcore device itself is connected. Same conflation in dm.js,
which marked 'connected' on Socket.IO transport connect (browser <->
server), unrelated to device <-> server connectivity. Together these
silently overwrote the real status (e.g. an actual device disconnect)
back to "Connected" on the very next channel switch or auto-refresh.

Also fixed the 'device_status' socket handler in app.js, which built
its own markup against a `#connectionStatus` element that doesn't
exist in any template (dead code since introduction) instead of
calling the shared updateStatus() against the real `#statusText`
element. Added a 60s polling fallback via loadStatus() in case a
push is ever missed on a long-lived tab.

Verified locally: ran the app against no real device (always
disconnected) and confirmed via Playwright that the badge now stays
correctly "Disconnected" through repeated loadMessages() calls,
instead of flipping back to "Connected" as before the fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-06-26 19:04:41 +02:00
parent 5b776bc927
commit 0eb7c772a7
2 changed files with 5 additions and 7 deletions
+5 -6
View File
@@ -482,11 +482,7 @@ function connectChatSocket() {
// Real-time device status
chatSocket.on('device_status', (data) => {
const statusEl = document.getElementById('connectionStatus');
if (statusEl) {
statusEl.className = data.connected ? 'connection-status connected' : 'connection-status disconnected';
statusEl.textContent = data.connected ? 'Connected' : 'Disconnected';
}
updateStatus(data.connected ? 'connected' : 'disconnected');
});
}
@@ -546,6 +542,10 @@ document.addEventListener('DOMContentLoaded', async function() {
// Initial badge updates (fast, sync-ish)
updatePendingContactsBadge();
loadStatus();
// Re-poll periodically as a fallback to the 'device_status' socket push —
// a missed/late socket event would otherwise leave the badge stale
// indefinitely on a long-lived tab.
setInterval(loadStatus, 60000);
// Map button in menu
const mapBtn = document.getElementById('mapBtn');
@@ -972,7 +972,6 @@ async function loadMessages() {
if (data.success) {
displayMessages(data.messages);
updateStatus('connected');
updateLastRefresh();
updateRegionIndicator();
} else {
-1
View File
@@ -134,7 +134,6 @@ function connectChatSocket() {
chatSocket.on('connect', () => {
console.log('DM: SocketIO connected to /chat');
updateStatus('connected');
});
chatSocket.on('disconnect', () => {