Sessions now update live across all users and devices

This commit is contained in:
NPS Agent
2026-05-18 11:41:02 +09:30
parent 75c6614e81
commit a17aafbbc9
5 changed files with 108 additions and 16 deletions
+22
View File
@@ -3,6 +3,28 @@ class ApiService {
this.baseUrl = '/api';
this.token = localStorage.getItem('dashy_token');
this.subscribers = new Set();
this.connectSSE();
}
connectSSE() {
const url = `${this.baseUrl}/stream`;
this.sse = new EventSource(url);
this.sse.onmessage = (event) => {
try {
const data = JSON.parse(event.data);
if (data.type === 'refresh') {
this.notify();
}
} catch (e) {
// Fallback for non-JSON messages or just generic refresh
this.notify();
}
};
this.sse.onerror = (err) => {
console.error('SSE connection error. EventSource will auto-reconnect.', err);
};
}
subscribe(fn) {