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

39 lines
902 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;
fetchType = e.data.fetchType;
fetchURL = e.data.fetchURL;
fetchInterval = 1000 * e.data.fetchInterval;
console.log("Configiuration Message:");
console.log(' Fetch type: ' + fetchType);
console.log(' Using fetch url: ' + fetchURL);
console.log(' Fetching data each [ms]: ' + 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);
})();