mirror of
https://github.com/fishtank-dashboard/fishtank-dashboard.git
synced 2026-05-02 11:52:03 -04:00
minor fixes
This commit is contained in:
committed by
GitHub
parent
2f50144fe7
commit
1c63a3c95f
18
server.js
18
server.js
@@ -89,6 +89,22 @@ function sendSubscriptions() {
|
||||
sendBinary(buildSubscribeFrame('presence'));
|
||||
}
|
||||
|
||||
// Presence is client-driven — must re-request every 30s to get updated counts
|
||||
let presenceTimer = null;
|
||||
|
||||
function startPresencePolling() {
|
||||
if (presenceTimer) clearInterval(presenceTimer);
|
||||
presenceTimer = setInterval(() => {
|
||||
if (ftSocket && ftSocket.readyState === 1) {
|
||||
sendBinary(buildSubscribeFrame('presence'));
|
||||
}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
function stopPresencePolling() {
|
||||
if (presenceTimer) { clearInterval(presenceTimer); presenceTimer = null; }
|
||||
}
|
||||
|
||||
// ── Simple msgpack decoder (enough for fishtank events) ─────
|
||||
function mpDecode(buf, offset = 0) {
|
||||
if (offset >= buf.length) return [null, offset];
|
||||
@@ -205,6 +221,7 @@ function handleBinaryFrame(buf) {
|
||||
namespaceReady = true;
|
||||
broadcast({ _ft: 'ws_status', status: 'connected' });
|
||||
sendSubscriptions();
|
||||
startPresencePolling();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -286,6 +303,7 @@ function connectFishtankWS(token) {
|
||||
console.log(`[WS] Disconnected (${code} ${reason || ''}). Reconnecting in 5s...`);
|
||||
broadcast({ _ft: 'ws_status', status: 'disconnected' });
|
||||
namespaceReady = false;
|
||||
stopPresencePolling();
|
||||
reconnectTimer = setTimeout(() => connectFishtankWS(null), 5000);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user