"use strict";
(() => {
// ns-hugo:/home/raoul-web/rc3_2021/html-infobeamer-content/assets/js/dom.js
var html = htm.bind(preact.h);
var speaker_names = (talk) => {
const nameSeparator = ", ";
let speakerNames = talk.persons.map((p) => p.public_name).join(nameSeparator);
return speakerNames;
};
var schedule_meta_here_dom = (schedule) => {
let inner = html`${schedule.map((talk) => html`
`)}`;
return inner;
};
var schedule_abstract_here_dom = (schedule) => {
let inner = html``;
let placeHolder = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec ut urna. Curabitur lorem risus, sagittis vitae, accumsan a, iaculis id, metus. Suspendisse potenti. Fusce nonummy commodo dui. Fusce venenatis ligula in pede. Aliquam velit dui, commodo quis, porttitor eget, convallis et, nisi. Nam sed nisl nec elit suscipit ullamcorper. Cras ac enim vel dui vestibulum suscipit. Suspendisse venenatis. Nam pharetra. Pellentesque et arcu. Nam sed nisl nec elit suscipit ullamcorper. Aenean turpis ipsum, rhoncus vitae, posuere vitae, euismod sed, ligula. Integer risus velit, facilisis eget, viverra et, venenatis id, leo. Aenean ligula. Mauris sed nulla quis nisi interdum tempor. Nullam libero nunc, tristique eget, laoreet eu, sagittis id, ante. Aliquam sed erat. Vestibulum viverra varius enim. Donec at diam a tellus dignissim vestibulum. Nullam sapien mauris, venenatis at, fermentum at, tempus eu, urna.";
schedule.forEach((talk) => {
let abstract = talk.abstract !== void 0 ? talk.abstract : placeHolder;
let track = talk.track !== void 0 ? talk.track : "-";
let lang = talk.language !== void 0 ? talk.language : "en";
inner = html`
${abstract}
Track: ${track}
`;
});
return inner;
};
var schedule_all_list_dom = (schedule) => {
let inner = html`
${schedule.map((talk) => html`
${talk.start}
Day ${talk.day}
${talk.room}
`)}`;
return inner;
};
var update_schedule_dom = (schedule) => {
const here_room = "Chaos-West TV";
const here_number_events = 1;
const all_number_events = 10;
let allData = schedule.slice(0, all_number_events);
let hereData = schedule.filter((i) => i.room === here_room).slice(0, 1);
let nextHereMetaDom = schedule_meta_here_dom(hereData);
let nextHereAbstractDom = schedule_abstract_here_dom(hereData);
let nextAllMetaDom = schedule_all_list_dom(allData);
let inner = html`
`;
return inner;
};
var music_playing_now_dom = (music) => {
let inner = html`
${music.map((current) => html`
(${current.license})
«${current.title}»
by
${current.artist}
`)}
`;
return inner;
};
var single_tweet_dom = (tweet) => {
let date = new Date(tweet.time);
let inner = html`
`;
return inner;
};
var social_container_dom = (tweets) => {
let inner = html`
${tweets.map((t) => single_tweet_dom(t))}
`;
return inner;
};
function update_main_slide(data) {
let schedule = data.schedule;
let music = data.music;
let twitter = data.twitter;
let scheduleDom = update_schedule_dom(schedule);
let musicDom = music_playing_now_dom(music);
let twitterDom = social_container_dom(twitter);
let inner = html`
${scheduleDom}
${musicDom}
${twitterDom}
`;
const anchorElId = "main";
const el = document.getElementById(anchorElId);
preact.render(inner, el);
}
//
var scheduleData = [];
var musicData = [];
var twitterData = [];
var mastodonData = [];
var social_limiter = (tweets, toots) => {
const numberTweets = 20;
let posts = tweets.concat(toots);
let byDate = (fst, snd) => Date.parse(fst.time) - Date.parse(snd.time);
let postsSorted = posts.sort(byDate);
if (postsSorted.length > 0) {
while (postsSorted.length < numberTweets) {
postsSorted = postsSorted.concat(postsSorted);
}
}
postsSorted = postsSorted.slice(0, numberTweets);
return postsSorted;
};
var get_tweet_author = (data, tweet) => {
let authorId = tweet.author_id;
let users = data.includes.users;
let author = users.find((item) => item.id === authorId);
let userName = author !== void 0 ? author.username : "NoOne";
return userName;
};
var get_tweet_text = (data, tweet) => tweet.text;
var get_tweet_profile_image = (data, tweet) => {
const defaultProfileImageUrl = "https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png";
let authorId = tweet.author_id;
let users = data.includes.users;
let author = users.find((item) => item.id === authorId);
let profileImageUrl = author !== void 0 ? author.profile_image_url : defaultProfileImageUrl;
return profileImageUrl;
};
var get_tweet_time = (data, tweet) => tweet.created_at;
var twitter_filter = (idata) => {
let tweets;
idata.forEach((d) => tweets = d.data.map((t) => {
return {
author: get_tweet_author(d, t),
image: get_tweet_profile_image(d, t),
text: get_tweet_text(d, t),
time: get_tweet_time(d, t)
};
}));
return tweets;
};
var mastodon_filter = (idata) => {
let toots;
idata.forEach((d) => {
toots = d.map((t) => {
return {
author: t.account.username,
image: t.account.avatar_static,
text: extractContent(t.content, true),
time: t.created_at
};
});
});
return toots;
};
function extractContent(string) {
let span = document.createElement("span");
span.innerHTML = string;
let children = span.querySelectorAll("*");
children.forEach((child) => {
child.textContent += " ";
});
return span.textContent.toString().replace(/ +/g, " ");
}
var schedule_processor = (data) => {
let dataDays = data.schedule.conference.days;
let talksData = dataDays.map((d) => {
return Object.values(d.rooms);
}).flat(2);
let byDate = (fst, snd) => Date.parse(fst.date) - Date.parse(snd.date);
let talksDataSorted = talksData.sort(byDate);
return talksDataSorted;
};
if (window.Worker) {
const workerBaseURL = window.infoBeamerConfig.get("workerBaseURL");
const scheduleWorkerCode = workerBaseURL + "js/schedule_worker.js";
console.log("Loading schedule worker JS from: " + scheduleWorkerCode);
const scheduleWorker = new Worker(scheduleWorkerCode);
const scheduleURL = window.infoBeamerConfig.get("scheduleURL");
const scheduleFetchInterval = window.infoBeamerConfig.get("scheduleFetchInterval");
scheduleWorker.postMessage({
msgType: "ScheduleFetchConfig",
scheduleURL,
scheduleFetchInterval
});
scheduleWorker.onmessage = function(e) {
let msgType = e.data.msgType;
if (msgType === "ScheduleUpdate") {
scheduleData = schedule_processor(e.data.schedule);
let time = e.data.timestamp;
console.log("Message: " + msgType + " at " + time);
console.log(scheduleData);
update_screen();
}
};
const musicWorkerCode = workerBaseURL + "js/generic_fetch_worker.js";
console.log("Loading worker JS from: " + musicWorkerCode);
const musicWorker = new Worker(musicWorkerCode);
const musicType = "Music";
const musicURL = window.infoBeamerConfig.get("musicURL");
const musicFetchInterval = window.infoBeamerConfig.get("musicFetchInterval");
musicWorker.postMessage({
fetchType: musicType,
fetchURL: musicURL,
fetchInterval: musicFetchInterval
});
musicWorker.onmessage = function(e) {
let msgType = e.data.msgType;
if (msgType === musicType) {
musicData = [e.data.json];
let time = e.data.timestamp;
console.log("Message: " + msgType + " at " + time);
console.log(musicData);
update_screen();
}
};
const twitterWorkerCode = workerBaseURL + "js/generic_fetch_worker.js";
console.log("Loading worker JS from: " + twitterWorkerCode);
const twitterWorker = new Worker(twitterWorkerCode);
const twitterType = "Twitter";
const twitterURL = window.infoBeamerConfig.get("twitterURL");
const twitterFetchInterval = window.infoBeamerConfig.get("twitterFetchInterval");
twitterWorker.postMessage({
fetchType: twitterType,
fetchURL: twitterURL,
fetchInterval: twitterFetchInterval
});
twitterWorker.onmessage = function(e) {
let msgType = e.data.msgType;
if (msgType === twitterType) {
twitterData = [e.data.json];
twitterData = twitter_filter(twitterData);
let time = e.data.timestamp;
console.log("Message: " + msgType + " at " + time);
console.log(twitterData);
update_screen();
}
};
const mastodonWorkerCode = workerBaseURL + "js/generic_fetch_worker.js";
console.log("Loading worker JS from: " + mastodonWorkerCode);
const mastodonWorker = new Worker(mastodonWorkerCode);
const mastodonType = "Mastodon";
const mastodonURL = window.infoBeamerConfig.get("mastodonURL");
const mastodonFetchInterval = window.infoBeamerConfig.get("mastodonFetchInterval");
mastodonWorker.postMessage({
fetchType: mastodonType,
fetchURL: mastodonURL,
fetchInterval: mastodonFetchInterval
});
mastodonWorker.onmessage = function(e) {
let msgType = e.data.msgType;
if (msgType === mastodonType) {
mastodonData = [e.data.json];
mastodonData = mastodon_filter(mastodonData);
let time = e.data.timestamp;
console.log("Message: " + msgType + " at " + time);
console.log(mastodonData);
update_screen();
}
};
} else {
console.log("Your browser doesn't support web workers.");
}
function update_screen() {
let time = new Date();
console.log("Updating screen at at: " + time);
update_main_slide({
schedule: scheduleData,
music: musicData,
twitter: social_limiter(twitterData, mastodonData)
});
}
function main_loop() {
update_screen();
setTimeout(main_loop, 10 * 1e3);
}
main_loop();
})();