Sessions now update live across all users and devices
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user