Improve SSE status and event auth handling
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
import { state } from './state.js';
|
||||
import { api } from './api.js';
|
||||
import { api, getStoredToken } from './api.js';
|
||||
|
||||
let _es = null;
|
||||
let _reconnectTimer = null;
|
||||
@@ -19,7 +19,12 @@ export function connectSSE() {
|
||||
}
|
||||
|
||||
function _connect() {
|
||||
_es = new EventSource('/api/events');
|
||||
const token = getStoredToken();
|
||||
const url = token
|
||||
? `/api/events?access_token=${encodeURIComponent(token)}`
|
||||
: '/api/events';
|
||||
|
||||
_es = new EventSource(url);
|
||||
|
||||
_es.onopen = () => {
|
||||
console.debug('[SSE] connected');
|
||||
@@ -43,7 +48,6 @@ function _connect() {
|
||||
|
||||
_es.onerror = () => {
|
||||
console.warn('[SSE] connection lost – reconnecting in', RECONNECT_DELAY_MS, 'ms');
|
||||
state.set('serverOnline', false);
|
||||
_reconnecting = true;
|
||||
state.set('sseReconnecting', true);
|
||||
_es.close();
|
||||
|
||||
Reference in New Issue
Block a user