This commit is contained in:
2026-04-28 16:00:39 -06:00
parent 1e998dabf3
commit 7df663d9c4
12 changed files with 493 additions and 128 deletions
+10 -5
View File
@@ -9,17 +9,17 @@ import (
)
func handleSSE(w http.ResponseWriter, r *http.Request) {
roomID := getPathInt(r, "room_id")
roomID, err := getPathInt(r, "room_id")
if err != nil {
http.Error(w, "invalid room id", http.StatusBadRequest)
return
}
user, ok := r.Context().Value(userKey).(*lib.User)
if !ok {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}
ch := make(chan string, 10)
addSSEClient(roomID, user.ID, ch)
broadcast(roomID, "members")
w.Header().Set("Content-Type", "text/event-stream")
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Connection", "keep-alive")
@@ -30,6 +30,11 @@ func handleSSE(w http.ResponseWriter, r *http.Request) {
http.Error(w, "streaming unsupported", http.StatusInternalServerError)
return
}
ch := make(chan string, 10)
addSSEClient(roomID, user.ID, ch)
broadcast(roomID, "members")
notify := r.Context().Done()
heartbeat := time.NewTicker(25 * time.Second)
defer heartbeat.Stop()