From 3041728e877b26357241c4bbb93c3460c4413142 Mon Sep 17 00:00:00 2001 From: Lars Kiesow Date: Thu, 1 Feb 2024 00:41:04 +0100 Subject: [PATCH] Makes Display Configurable This patch adds configuration for the displayed texts and colors. --- assets/index.js | 32 +++++++++++++++++++++----------- main.go | 16 ++++++++++++++++ opencast-ca-display.yml | 11 +++++++++++ 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/assets/index.js b/assets/index.js index 3ec9190..33702df 100644 --- a/assets/index.js +++ b/assets/index.js @@ -1,18 +1,28 @@ -const myInterval = setInterval(myTimer, 2000); +var config = null; -function myTimer() { +/** + * Load configuration and initialize timer + */ +fetch('/config') +.then(response => response.json()) +.then(cfg => { + config = cfg; + console.info('config', config) + setInterval(updateTimer, 2000); +}) + +/** + * Check for capture agent status + */ +function updateTimer() { fetch('/status') .then(response => response.json()) .then(capturing => { - console.info(capturing) - document.getElementById('text').innerText = capturing ? 'Aufzeichnung läuft' : 'Keine Aufzeichnung'; + console.debug('capturing', capturing) + const active = capturing ? config.capturing : config.idle; + document.getElementById('text').innerText = active.text; const body = document.getElementsByTagName('body')[0]; - if (capturing) { - body.style.backgroundColor = '#ac0634'; - body.style.color = '#fff'; - } else { - body.style.backgroundColor = '#fff'; - body.style.color = '#000'; - } + body.style.backgroundColor = active.background; + body.style.color = active.color; }) } diff --git a/main.go b/main.go index 3075730..f5f1907 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,12 @@ type AgentStateResult struct { } `json:"agent-state-update"` } +type DisplayConfig struct { + Text string `json:"text"` + Color string `json:"color"` + Background string `json:"background"` +} + type Config struct { Opencast struct { Url string @@ -47,6 +53,11 @@ type Config struct { Agent string } + Display struct { + Capturing DisplayConfig `json:"capturing"` + Idle DisplayConfig `json:"idle"` + } + Listen string } @@ -95,6 +106,11 @@ func setupRouter() *gin.Engine { assets, _ := fs.Sub(res, "assets") r.StaticFS("/assets", http.FS(assets)) + // Display Config + r.GET("/config", func(c *gin.Context) { + c.JSON(http.StatusOK, config.Display) + }) + // Status r.GET("/status", func(c *gin.Context) { client := &http.Client{} diff --git a/opencast-ca-display.yml b/opencast-ca-display.yml index e6909a0..c4e2cbc 100644 --- a/opencast-ca-display.yml +++ b/opencast-ca-display.yml @@ -9,5 +9,16 @@ opencast: # Capture agent to show the status for agent: test +# display configuration +display: + capturing: + text: Aufzeichnung läuft + color: white + background: '#ac0634' + idle: + text: Keine Aufzeichnung + color: black + background: white + # IP address and port to bind to listen: 127.0.0.1:8080