mirror of
https://github.com/Kioubit/ColorPing
synced 2024-12-05 06:00:40 +08:00
Ensure client has been added before starting the streamServer
This commit is contained in:
parent
c2be44274b
commit
35d5f94fd5
1 changed files with 2 additions and 2 deletions
4
http.go
4
http.go
|
@ -174,7 +174,6 @@ func stream(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, "Streaming unsupported!", http.StatusInternalServerError)
|
http.Error(w, "Streaming unsupported!", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
streamServer()
|
|
||||||
w.Header().Set("Content-Type", "text/event-stream")
|
w.Header().Set("Content-Type", "text/event-stream")
|
||||||
w.Header().Set("Cache-Control", "no-cache")
|
w.Header().Set("Cache-Control", "no-cache")
|
||||||
w.Header().Set("Connection", "keep-alive")
|
w.Header().Set("Connection", "keep-alive")
|
||||||
|
@ -186,8 +185,9 @@ func stream(w http.ResponseWriter, r *http.Request) {
|
||||||
clientMutex.Lock()
|
clientMutex.Lock()
|
||||||
clients = append(clients, newClient)
|
clients = append(clients, newClient)
|
||||||
clientMutex.Unlock()
|
clientMutex.Unlock()
|
||||||
|
streamServer()
|
||||||
|
|
||||||
// For when clients are removed prior to connection closed, to avoid a call to delete(clients, id)
|
// For when clients are removed prior to connection close, to avoid a call to deleteClient()
|
||||||
var channelClosedFirst = false
|
var channelClosedFirst = false
|
||||||
go func() {
|
go func() {
|
||||||
// Listen for connection close
|
// Listen for connection close
|
||||||
|
|
Loading…
Reference in a new issue