rc3-html-infobeamer/public/js/generic_fetch_worker.js

37 lines
767 B
JavaScript
Raw Normal View History

2021-12-24 02:16:26 +01:00
let fetchType;
let fetchInterval;
let fetchURL;
onmessage = function(e) {
let msgType = e.data.msgType;
// console.log("Configuration Message:");
2021-12-25 22:19:20 +01:00
console.log(e.data);
2021-12-24 02:16:26 +01:00
fetchType = e.data.fetchType;
fetchURL = e.data.fetchURL;
fetchInterval = 1000 * e.data.fetchInterval;
};
function doFetch() {
let now = new Date();
if (fetchURL) {
fetch(fetchURL).then(
b => b.json()).then(
j => postMessage({msgType: fetchType,
json: j,
timestamp: now}))
.catch(e => console.log(e.message));
}
}
// Periodic resource fetching
(function periodicFetch() {
doFetch();
setTimeout(periodicFetch, fetchInterval);
})();