Skip to content

Commit

Permalink
Fixed the bug mentioned by Lars and followed up on most of the other …
Browse files Browse the repository at this point in the history
…comments
  • Loading branch information
Jan-Matthis committed Jul 19, 2024
1 parent 2363064 commit a364416
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
47 changes: 22 additions & 25 deletions assets/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var config = null;
var calendar = updateCalendar();
updateCalendar();
var is_active = null;

/**
Expand Down Expand Up @@ -47,50 +47,47 @@ function updateTimer() {
}
return response.json()
}).then(capturing => {
console.log('capturing', capturing);
if(is_active != capturing && !capturing){
updateCalendar()
}
console.debug('capturing', capturing);
is_active = capturing;
updateView(capturing ? config.capturing : config.idle);
})
}

function parseCalendar(active){
// Do we want 'Startet/Endet in' or 'Startet/Endet um'?
let diff = 0;
let t = 0;
let time_remaining = 0;
console.debug('Is Active? ', is_active);
const event_time = is_active ? calendar[0].End : calendar[0].Start;

now = Date.now();
if (calendar.length > 0){
t = is_active ? calendar[0].End : calendar[0].Start;
diff = t - now;
console.debug('Diff ', diff, t, now);
// TODO Maybe switch 'is_active' to 'capturing' here?
//t = is_active ? calendar[0].End : calendar[0].Start;
time_remaining = event_time - now;
console.debug('Time Remaining: ', time_remaining, event_time, now);
} else {
console.debug('Calendar is empty');

if(!is_active){
return active.none;
}
}

hours = (diff > 0) ? Math.floor(diff / (1000 * 60 * 60)) : 0;
minutes = (diff > 0) ? Math.floor((diff / (1000 * 60)) % 60) : 0;
seconds = (diff > 0) ? Math.floor((diff / 1000) % 60) : 0;

hours = (time_remaining > 0) ? Math.floor(time_remaining / (1000 * 60 * 60)) : 0;
minutes = (time_remaining > 0) ? Math.floor((time_remaining / (1000 * 60)) % 60) : 0;
seconds = (time_remaining > 0) ? Math.floor((time_remaining / 1000) % 60) : 0;
hours = (hours < 10) ? '0' + hours : hours;
minutes = (minutes < 10) ? '0' + minutes : minutes;
seconds = (seconds < 10) ? '0' + seconds : seconds;

console.debug('Remaining ', diff/1000);
if (calendar.length == 0 && !is_active) {
return 'Keine Aufzeichnung geplant';
} else {
return (hours > 0) ? active.info + ' ' + hours + ':' + minutes + ':' + seconds : active.info + ' ' + minutes + ':' + seconds;
}

time_remaining = `${hours}:${minutes}:${seconds}`;
console.debug('Compare ', is_active, now, event_time);
return (is_active && now < calendar[0].Start) ? "" : active.info + ' ' + time_remaining;
}

function updateCalendar() {
fetch("/calendar")
.then(response => {
console.debug('Calednar fetched; Status ', response.status)
console.debug('Calendar fetched; Status ', response.status);
return response.json()})
.then(json => {
console.log('Calendar ', json);
Expand Down
2 changes: 1 addition & 1 deletion assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ body {
align-items: center;
position: absolute;
top: 0;
bottom: 75;
left: 0;
right: 0;
padding: 3vw;
font-size: 3vw;
font-weight: 500;
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type DisplayConfig struct {
Background string `json:"background"`
Image string `json:"image"`
Info string `json:"info"`
Empty string `json:"none"`
}

type Config struct {
Expand Down Expand Up @@ -154,7 +155,7 @@ func setupRouter() *gin.Engine {
r.GET("/calendar", func(c *gin.Context) {
client := &http.Client{}
// Cutoff is set to 24 hours from now
cutoff := time.Now().UnixMilli() + int64(86400000)
cutoff := time.Now().UnixMilli() + 86400000
url := config.Opencast.Url + "/recordings/calendar.json?agentid=" + config.Opencast.Agent + "&cutoff=" + fmt.Sprint(cutoff) + "&timestamp=true"
req, err := http.NewRequest("GET", url, nil)
req.SetBasicAuth(config.Opencast.Username, config.Opencast.Password)
Expand All @@ -172,6 +173,7 @@ func setupRouter() *gin.Engine {

bodyText, err := io.ReadAll(resp.Body)
s := string([]byte(bodyText))

start := regexp.MustCompile(`"startDate":[\d]+`)
end := regexp.MustCompile(`"endDate":[\d]+`)
t := regexp.MustCompile(`"event.title":"[^"]+"`)
Expand Down
1 change: 1 addition & 0 deletions opencast-ca-display.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ display:
bdf+Ja02rbN0Tm63v7bb1/63qhYAAAAAAAAAAAAAAAAAAAAAAAAAAIDY8w9T
Gxe/25sMhQAAAABJRU5ErkJggg==
info: Nächste Aufzeichnung in
empty: Keine Aufzeichnung geplant

unknown:
text: Unknown
Expand Down

0 comments on commit a364416

Please sign in to comment.