diff --git a/pretalx_broadcast_tools/static/pretalx_broadcast_tools/generic.js b/pretalx_broadcast_tools/static/pretalx_broadcast_tools/generic.js index fa0eeba..b9190f1 100644 --- a/pretalx_broadcast_tools/static/pretalx_broadcast_tools/generic.js +++ b/pretalx_broadcast_tools/static/pretalx_broadcast_tools/generic.js @@ -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 { diff --git a/pretalx_broadcast_tools/static/pretalx_broadcast_tools/lower_thirds.js b/pretalx_broadcast_tools/static/pretalx_broadcast_tools/lower_thirds.js index 40f2428..efe97f7 100644 --- a/pretalx_broadcast_tools/static/pretalx_broadcast_tools/lower_thirds.js +++ b/pretalx_broadcast_tools/static/pretalx_broadcast_tools/lower_thirds.js @@ -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('
'); - infoline = ''; + title.innerHTML = 'Error'; + speaker.innerHTML = schedule['error'].join('
'); + 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']) { diff --git a/pretalx_broadcast_tools/static/pretalx_broadcast_tools/room_info.js b/pretalx_broadcast_tools/static/pretalx_broadcast_tools/room_info.js index 486d658..8edd925 100644 --- a/pretalx_broadcast_tools/static/pretalx_broadcast_tools/room_info.js +++ b/pretalx_broadcast_tools/static/pretalx_broadcast_tools/room_info.js @@ -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('
'); - qr = ''; + title.innerHTML = 'Error'; + speaker.innerHTML = schedule['error'].join('
'); + 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 = ''; } }