feat: making SSE work on mobiles

This commit is contained in:
2025-05-12 20:11:58 +01:00
parent 636bd9df0e
commit 076e230a01
2 changed files with 13 additions and 25 deletions

View File

@@ -144,14 +144,15 @@ func CreateEventsHandler(notifier *Notifier[Notification]) http.HandlerFunc {
w.Header().Set("Connection", "keep-alive")
// w.(http.Flusher).Flush()
if err := notifier.Create(userId.String()); err != nil {
// TODO: this could be better.
// EG: The user could attempt to create many connections
// and they just get a 500, with no explanation.
w.WriteHeader(http.StatusInternalServerError)
// w.(http.Flusher).Flush()
return
}
// if err := notifier.Create(userId.String()); err != nil {
// // TODO: this could be better.
// // EG: The user could attempt to create many connections
// // and they just get a 500, with no explanation.
// fmt.Println(err)
// w.WriteHeader(http.StatusInternalServerError)
// // w.(http.Flusher).Flush()
// return
// }
listener := notifier.Listeners[userId.String()]
@@ -171,7 +172,7 @@ func CreateEventsHandler(notifier *Notifier[Notification]) http.HandlerFunc {
fmt.Printf("Sending msg %s\n", msg)
fmt.Fprintf(w, "event: data\ndata: %s\n\n", string(msgString))
// w.(http.Flusher).Flush()
w.(http.Flusher).Flush()
}
}
}