diff --git a/api/event.go b/api/event.go index 992de703..89414f8e 100644 --- a/api/event.go +++ b/api/event.go @@ -20,8 +20,20 @@ type ConnectionSSE struct { userID int } +type Message struct { + Resource string `json:"resource"` + Time time.Time `json:"time"` + Type string `json:"type"` + URI string `json:"uri"` +} + func (c *ConnectionSSE) SendEvent(w http.ResponseWriter, m platform.Event) error { - return send(w, m) + return send(w, Message{ + Resource: m.Resource, + Time: m.Time, + Type: m.Type.String(), + URI: m.URI, + }) } func (c *ConnectionSSE) SendHeartbeat(w http.ResponseWriter, t time.Time) error { return send(w, platform.Event{ diff --git a/html/static/js/events.js b/html/static/js/events.js index f14119c3..ee1928a2 100644 --- a/html/static/js/events.js +++ b/html/static/js/events.js @@ -59,6 +59,11 @@ window.SSEManager = (function () { console.error("SSE error:", err); isConnected = false; + // Close old connection + if (eventSource) { + eventSource.close(); + } + // Reconnect after delay setTimeout(() => { connectionPromise = null; diff --git a/html/template/sync/layout/authenticated.html b/html/template/sync/layout/authenticated.html index 7ca41874..96d43f86 100644 --- a/html/template/sync/layout/authenticated.html +++ b/html/template/sync/layout/authenticated.html @@ -14,7 +14,11 @@ {{ block "extraheader" . }}{{ end }}