Skip to content

Commit

Permalink
The time remaining until the next recording is parsed accordingly and…
Browse files Browse the repository at this point in the history
… displayed at the bottom. It also works if no recording is scheduled in the next 24 hours. Not tested for the 'capturing' case. Need to parse the yml file to get the agent id and the username/password
  • Loading branch information
Jan-Matthis committed May 29, 2024
1 parent 7cbf52f commit 610c9b8
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 5 deletions.
1 change: 1 addition & 0 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<img id=logo />
<div id=text></div>
<div id=info></div>

</body>
</html>
97 changes: 92 additions & 5 deletions assets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ fetch('/config')
*/
function updateView(active) {
// Update text
document.getElementById('text').innerText = active.text;
document.getElementById('text').innerText = active ? config.capturing.text : config.idle.text;

// Update colors
const body = document.getElementsByTagName('body')[0];
body.style.backgroundColor = active.background;
body.style.color = active.color;
body.style.backgroundColor = active ? config.capturing.background : config.idle.background;
body.style.color = active? config.capturing.color : config.idle.color;

// Update logo
document.getElementById('logo').src = active.image.replace(/\s/g, '');
document.getElementById('logo').src = active ? config.capturing.image.replace(/\s/g, '') : config.idle.image.replace(/\s/g, '');

document.getElementById('info').innerText = getAdditionalInfo(active);
}


/**
* Check for capture agent status
*/
Expand All @@ -42,6 +45,90 @@ function updateTimer() {
return response.json()
}).then(capturing => {
console.debug('capturing', capturing)
updateView(capturing ? config.capturing : config.idle);
//updateView(capturing ? config.capturing : config.idle);
updateView(capturing);
})
}

function formatSeconds(s){
return (new Date(s * 1000)).toUTCString().match(/(\d\d:\d\d:\d\d)/)[0];
}

function parseCalendar(calendar, active){
//console.log('In parseCalendar ', calendar, active);
// Do we want 'Startet/Endet in' or 'Startet/Endet um'?
let diff = 0;
let t = 0;

console.log('Active ', active);
console.log('Lenght ', calendar.length);

now = Date.now();
try{
t = active ? Date.parse(calendar[0].data.endDate) : Date.parse(calendar[0].data.startDate);
diff = t - now;
console.log('Diff ', diff, t, now);
} catch (TypeError) {
console.debug('Calendar is empty');
}

let remaining = null;
console.log('Remaining ', new Date(diff/1000).toISOString());
remaining = formatSeconds(diff/1000)
if(calendar.length > 0){
return (active ? config.capturing.info : config.idle.info) + ' ' + remaining;
} else {
return (active ? config.capturing.info + ' ' + remaining : 'Keine Aufzeichnung geplant');
}
}

function getAdditionalInfo(active) {
// TODO find a better cutoff (24h ?)
/**
* [ ] Task A: Updating the textbox
* [x] A1: Fetch the calendar
* [x] A2: Parse the calendar according to the capturing status (either start or end date)
* [ ] A3: Set the correct time remaining until end/next
* --> Check for capturing state, not changing for some reason
* [ ] Task B: Retrieving the authentication details, the agent and the url
* [ ] B1: read & parse yaml
* [ ] B2: make a request with fetch
*/

time = Date.now();
cutoff = time + 86400000; // Cutoff is set to 24h from now

user = 'admin';
pw = 'opencast';
url = 'https://develop.opencast.org/recordings/calendar.json';
agent = 'test';

calendar = null;

let headers = new Headers();

headers.set('Authorization', 'Basic ' + btoa(user + ":" + pw));

url = url + '?' + new URLSearchParams({
agentid: agent,
cutoff: cutoff,
});

console.log('Request URL ', url);

fetch(url, {method:'GET',
headers:headers,
})
.then(response => {
console.debug('Status ', response.status)
return response.json()})
.then(json => {
console.debug('Calendar ', json);
calendar = json;
ans = parseCalendar(calendar, active);
console.debug('Ans ', ans);
return ans;
});
console.debug('Answer ', ans);
return String(ans);
}
12 changes: 12 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ body {
right: 5;
padding: 5vw;
}

#info {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding: 3vw;
font-size: 3vw;
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type DisplayConfig struct {
Color string `json:"color"`
Background string `json:"background"`
Image string `json:"image"`
Info string `json:"info"`
}

type Config struct {
Expand Down
2 changes: 2 additions & 0 deletions opencast-ca-display.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ display:
HrhVPXVWTkn97VSgt/62FZZY0/33iOhe/l+Lb5X8k000WMtkiZpKH0S9QSaT
OeiRdiQV+jtsszv4S0ehWoGoej5se96jOgMAAAAAAAAAAAAAAAAAAAAAuBD/
AO9hftIMDgN8AAAAAElFTkSuQmCC
info: Aufzeichnung endet in

idle:
text: Keine Aufzeichnung
Expand Down Expand Up @@ -109,6 +110,7 @@ display:
f4+spFz+r0VResjN9mzc3jXalThjwh+ybVHjPl+Xy+X60+fO9CjG+Gv5fn9N
bdf+Ja02rbN0Tm63v7bb1/63qhYAAAAAAAAAAAAAAAAAAAAAAAAAAIDY8w9T
Gxe/25sMhQAAAABJRU5ErkJggg==
info: Nächste Aufzeichnung in

unknown:
text: Unknown
Expand Down

0 comments on commit 610c9b8

Please sign in to comment.