mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
room events optional sse.
This commit is contained in:
+12
-1
@@ -252,10 +252,16 @@ func (manager *ApiManagerCtx) roomGenericAction(action func(ctx context.Context,
|
||||
}
|
||||
|
||||
func (manager *ApiManagerCtx) events(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
w.Header().Set("Connection", "keep-alive")
|
||||
|
||||
sse := r.URL.Query().Has("sse")
|
||||
if sse {
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
} else {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
}
|
||||
|
||||
flusher, ok := w.(http.Flusher)
|
||||
if !ok {
|
||||
http.Error(w, "Connection does not support streaming", http.StatusBadRequest)
|
||||
@@ -277,7 +283,12 @@ func (manager *ApiManagerCtx) events(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if sse {
|
||||
fmt.Fprintf(w, "data: %s\n\n", jsonData)
|
||||
} else {
|
||||
fmt.Fprintf(w, "%s\n", jsonData)
|
||||
}
|
||||
|
||||
flusher.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user