From 4925fe4857bf23b9b4126222236be5fd0e942e1e Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Fri, 13 Mar 2026 18:21:20 +0000 Subject: [PATCH] Close old SSE connections, push down type strings --- api/event.go | 14 ++++++++++++- html/static/js/events.js | 5 +++++ html/template/sync/layout/authenticated.html | 6 +++++- platform/event/event.go | 21 ++++++++++++++++++-- 4 files changed, 42 insertions(+), 4 deletions(-) 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 }}