Add arena status websocket API for clients that need realtime match signaling.

This commit is contained in:
Patrick Fairbank
2019-08-23 22:03:07 -07:00
parent 33378fe3eb
commit 6926aa42ad
4 changed files with 38 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import (
"encoding/json"
"github.com/Team254/cheesy-arena/game"
"github.com/Team254/cheesy-arena/model"
"github.com/Team254/cheesy-arena/websocket"
"github.com/gorilla/mux"
"net/http"
)
@@ -176,3 +177,20 @@ func (web *Web) alliancesApiHandler(w http.ResponseWriter, r *http.Request) {
return
}
}
// Websocket API for receiving arena status updates.
func (web *Web) arenaWebsocketApiHandler(w http.ResponseWriter, r *http.Request) {
if !web.userIsAdmin(w, r) {
return
}
ws, err := websocket.NewWebsocket(w, r)
if err != nil {
handleWebErr(w, err)
return
}
defer ws.Close()
// Subscribe the websocket to the notifiers whose messages will be passed on to the client.
ws.HandleNotifiers(web.arena.MatchTimingNotifier, web.arena.MatchLoadNotifier, web.arena.MatchTimeNotifier)
}