Refactor displays to allow for centralized remote configuration.

This commit is contained in:
Patrick Fairbank
2018-09-09 22:42:38 -07:00
parent 6cfdcc924d
commit 833bd32ab2
46 changed files with 1018 additions and 201 deletions

View File

@@ -6,6 +6,7 @@
package web
import (
"github.com/Team254/cheesy-arena/field"
"github.com/Team254/cheesy-arena/model"
"github.com/Team254/cheesy-arena/websocket"
"net/http"
@@ -17,6 +18,10 @@ func (web *Web) pitDisplayHandler(w http.ResponseWriter, r *http.Request) {
return
}
if !web.enforceDisplayConfiguration(w, r, nil) {
return
}
template, err := web.parseFiles("templates/pit_display.html")
if err != nil {
handleWebErr(w, err)
@@ -38,6 +43,14 @@ func (web *Web) pitDisplayWebsocketHandler(w http.ResponseWriter, r *http.Reques
return
}
display, err := field.DisplayFromUrl(r.URL.Path, r.URL.Query())
if err != nil {
handleWebErr(w, err)
return
}
web.arena.RegisterDisplay(display)
defer web.arena.MarkDisplayDisconnected(display)
ws, err := websocket.NewWebsocket(w, r)
if err != nil {
handleWebErr(w, err)
@@ -46,5 +59,5 @@ func (web *Web) pitDisplayWebsocketHandler(w http.ResponseWriter, r *http.Reques
defer ws.Close()
// Subscribe the websocket to the notifiers whose messages will be passed on to the client.
ws.HandleNotifiers(web.arena.ReloadDisplaysNotifier)
ws.HandleNotifiers(web.arena.DisplayConfigurationNotifier, web.arena.ReloadDisplaysNotifier)
}