1
0
Fork 0
mirror of https://github.com/Kunsi/pretalx-plugin-broadcast-tools synced 2024-11-21 12:11:02 +00:00

fix all the javascript i broke

This commit is contained in:
Franzi 2024-10-31 20:04:23 +01:00
parent 90c50c9652
commit 410ca28b79
Signed by: kunsi
GPG key ID: 12E3D2136B818350
3 changed files with 62 additions and 57 deletions

View file

@ -1,5 +1,6 @@
schedule = null;
event_info = null;
req = {};
function get_current_talk(max_offset) {
room_name = get_room_name();
@ -88,27 +89,31 @@ function format_time_from_pretalx(from_pretalx) {
}
function xhr_get(url, callback_func) {
req = new XMLHttpRequest();
req.timeout = 10000;
req.open('GET', url);
req.setRequestHeader('Accept', 'application/json');
req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
req.addEventListener('load', function(event) {
if (req.status != 200) {
return;
}
req[url] = new XMLHttpRequest();
req[url].timeout = 10000;
req[url].onreadystatechange = () => {
if (req[url].readyState === 4) {
if (req[url].status != 200) {
return;
}
callback_func(event);
});
req.send();
callback_func(req[url].responseText);
}
};
req[url].open('GET', url);
req[url].setRequestHeader('Accept', 'application/json');
req[url].setRequestHeader("Content-Type", "application/json;charset=UTF-8");
req[url].send();
}
function update_schedule() {
xhr_get('../event.json', function() {
event_info = JSON.parse(req.responseText);
xhr_get('../event.json', function(text) {
console.log("events: " + text);
event_info = JSON.parse(text);
});
xhr_get('../schedule.json', function() {
data = JSON.parse(req.responseText);
xhr_get('../schedule.json', function(text) {
console.log("schedule: " + text);
data = JSON.parse(text);
if ('error' in data) {
console.error(data['error']);
} else {

View file

@ -7,40 +7,40 @@ function update_lower_third() {
}
box = document.getElementById('broadcast_tools_lower_thirds_box');
title = document.getElementById('broadcast_tools_lower_thirds_title').innerHTML;
speaker = document.getElementById('broadcast_tools_lower_thirds_speaker').innerHTML;
infoline = document.getElementById('broadcast_tools_lower_thirds_infoline').innerHTML;
title = document.getElementById('broadcast_tools_lower_thirds_title');
speaker = document.getElementById('broadcast_tools_lower_thirds_speaker');
infoline = document.getElementById('broadcast_tools_lower_thirds_infoline');
box.style.backgroundColor = event_info['color']);
box.style.backgroundColor = event_info['color'];
if (!schedule) {
title = 'Waiting for schedule ...';
title.innerHTML = 'Waiting for schedule ...';
return
}
if ('error' in schedule) {
title = 'Error';
speaker = schedule['error'].join('<br>');
infoline = '';
title.innerHTML = 'Error';
speaker.innerHTML = schedule['error'].join('<br>');
infoline.innerHTML = '';
return
}
if (schedule['rooms'].length > 1 && !schedule['rooms'].includes(room_name)) {
title = 'Error';
speaker = 'Invalid room_name. Valid names: ' + schedule['rooms'].join(', ');
infoline = '';
title.innerHTML = 'Error';
speaker.innerHTML = 'Invalid room_name. Valid names: ' + schedule['rooms'].join(', ');
infoline.innerHTML = '';
return
}
current_talk = get_current_talk(5);
if (current_talk) {
title = current_talk['title'];
speaker = current_talk['persons'].join(', ');
infoline = current_talk['infoline'];
title.innerHTML = current_talk['title'];
speaker.innerHTML = current_talk['persons'].join(', ');
infoline.innerHTML = current_talk['infoline'];
} else {
title = event_info['no_talk'];
speaker = '';
infoline = '';
title.innerHTML = event_info['no_talk'];
speaker.innerHTML = '';
infoline.innerHTML = '';
}
if (current_talk && current_talk['track']) {

View file

@ -7,36 +7,36 @@ function update_room_info() {
}
box = document.getElementById('broadcast_tools_room_info');
roomname = document.getElementById('broadcast_tools_room_info_roomname').innerHTML;
title = document.getElementById('broadcast_tools_room_info_title').innerHTML;
speaker = document.getElementById('broadcast_tools_room_info_speaker').innerHTML;
qr = document.getElementById('broadcast_tools_room_info_qr').innerHTML;
roomname = document.getElementById('broadcast_tools_room_info_roomname');
title = document.getElementById('broadcast_tools_room_info_title');
speaker = document.getElementById('broadcast_tools_room_info_speaker');
qr = document.getElementById('broadcast_tools_room_info_qr');
if (!room_name) {
roomname = event_info['name'];
title = 'Backstage';
speaker = '';
qr = '';
roomname.innerHTML = event_info['name'];
title.innerHTML = 'Backstage';
speaker.innerHTML = '';
qr.innerHTML = '';
box.style.backgroundColor = event_info['color'];
return
}
if (!schedule) {
speaker = 'Waiting for schedule ...';
speaker.innerHTML = 'Waiting for schedule ...';
return
}
if ('error' in schedule) {
title = 'Error';
speaker = schedule['error'].join('<br>');
qr = '';
title.innerHTML = 'Error';
speaker.innerHTML = schedule['error'].join('<br>');
qr.innerHTML = '';
return
}
if (schedule['rooms'].length > 1 && !schedule['rooms'].includes(room_name)) {
title = 'Error';
speaker = 'Invalid room_name. Valid names: ' + schedule['rooms'].join(', ');
qr = '';
title.innerHTML = 'Error';
speaker.innerHTML = 'Invalid room_name. Valid names: ' + schedule['rooms'].join(', ');
qr.innerHTML = '';
return
}
@ -54,19 +54,19 @@ function update_room_info() {
qr_info = '';
}
roomname = room_name;
title = current_talk['title'];
speaker = current_talk['persons'].join(', ');
qr = qr_info;
roomname.innerHTML = room_name;
title.innerHTML = current_talk['title'];
speaker.innerHTML = current_talk['persons'].join(', ');
qr.innerHTML = qr_info;
} else {
roomname = event_info['name'];
title = room_name;
qr = '';
roomname.innerHTML = event_info['name'];
title.innerHTML = room_name;
qr.innerHTML = '';
if (next_talk && event_info['room-info']['show_next_talk']) {
speaker = format_time_from_pretalx(next_talk['start']) + ' ' + next_talk['title'];
speaker.innerHTML = format_time_from_pretalx(next_talk['start']) + ' ' + next_talk['title'];
} else {
speaker = '';
speaker.innerHTML = '';
}
}