2014-09-06 17:06:06 -07:00
|
|
|
// Copyright 2014 Team 254. All Rights Reserved.
|
|
|
|
|
// Author: pat@patfairbank.com (Patrick Fairbank)
|
|
|
|
|
//
|
|
|
|
|
// Web handlers for the pit rankings display.
|
|
|
|
|
|
2017-08-31 23:26:22 -07:00
|
|
|
package web
|
2014-09-06 17:06:06 -07:00
|
|
|
|
|
|
|
|
import (
|
2017-08-23 22:41:56 -07:00
|
|
|
"github.com/Team254/cheesy-arena/model"
|
2018-08-31 22:40:08 -07:00
|
|
|
"github.com/Team254/cheesy-arena/websocket"
|
2014-09-06 17:06:06 -07:00
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Renders the pit display which shows scrolling rankings.
|
2017-08-28 20:14:32 -07:00
|
|
|
func (web *Web) pitDisplayHandler(w http.ResponseWriter, r *http.Request) {
|
2018-09-16 19:50:23 -07:00
|
|
|
if !web.enforceDisplayConfiguration(w, r, map[string]string{"scrollMsPerRow": "1000"}) {
|
2018-09-09 22:42:38 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-31 23:26:22 -07:00
|
|
|
template, err := web.parseFiles("templates/pit_display.html")
|
2014-09-06 17:06:06 -07:00
|
|
|
if err != nil {
|
|
|
|
|
handleWebErr(w, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
data := struct {
|
2017-08-23 22:41:56 -07:00
|
|
|
*model.EventSettings
|
2017-08-28 20:14:32 -07:00
|
|
|
}{web.arena.EventSettings}
|
2017-08-31 23:26:22 -07:00
|
|
|
err = template.ExecuteTemplate(w, "pit_display.html", data)
|
2014-09-06 17:06:06 -07:00
|
|
|
if err != nil {
|
|
|
|
|
handleWebErr(w, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The websocket endpoint for the pit display, used only to force reloads remotely.
|
2017-08-28 20:14:32 -07:00
|
|
|
func (web *Web) pitDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
|
2018-09-16 22:27:08 -07:00
|
|
|
display, err := web.registerDisplay(r)
|
2018-09-09 22:42:38 -07:00
|
|
|
if err != nil {
|
|
|
|
|
handleWebErr(w, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
defer web.arena.MarkDisplayDisconnected(display)
|
|
|
|
|
|
2018-08-31 22:40:08 -07:00
|
|
|
ws, err := websocket.NewWebsocket(w, r)
|
2014-09-06 17:06:06 -07:00
|
|
|
if err != nil {
|
|
|
|
|
handleWebErr(w, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2018-08-31 22:40:08 -07:00
|
|
|
defer ws.Close()
|
2014-09-06 17:06:06 -07:00
|
|
|
|
2018-08-31 22:40:08 -07:00
|
|
|
// Subscribe the websocket to the notifiers whose messages will be passed on to the client.
|
2018-09-09 22:42:38 -07:00
|
|
|
ws.HandleNotifiers(web.arena.DisplayConfigurationNotifier, web.arena.ReloadDisplaysNotifier)
|
2014-09-06 17:06:06 -07:00
|
|
|
}
|