Skip to content

Commit

Permalink
Makes Display Configurable
Browse files Browse the repository at this point in the history
This patch adds configuration for the displayed texts and colors.
  • Loading branch information
lkiesow committed Jan 31, 2024
1 parent 72508df commit 7c2aea7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
32 changes: 21 additions & 11 deletions assets/index.js
Original file line number Diff line number Diff line change
@@ -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;
})
}
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,6 +53,11 @@ type Config struct {
Agent string
}

Display struct {
Capturing DisplayConfig `json:"capturing"`
Idle DisplayConfig `json:"idle"`
}

Listen string
}

Expand Down Expand Up @@ -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{}
Expand Down
11 changes: 11 additions & 0 deletions opencast-ca-display.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7c2aea7

Please sign in to comment.