2021-12-24 02:16:26 +01:00
|
|
|
let fetchType;
|
|
|
|
let fetchInterval;
|
|
|
|
let fetchURL;
|
|
|
|
|
|
|
|
|
|
|
|
onmessage = function(e) {
|
|
|
|
let msgType = e.data.msgType;
|
|
|
|
|
2021-12-27 16:11:53 +01:00
|
|
|
// 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);
|
|
|
|
})();
|