Rotate immediately if waitUntil is in the past

This commit is contained in:
Henri Bergius 2018-12-26 21:10:10 +01:00
parent b589e07bae
commit 5b6e323a90

View file

@ -85,13 +85,16 @@ function DisplayParticipant(broker, role, defaultUrls, timer) {
window.onmessage = null; window.onmessage = null;
const now = new Date(); const now = new Date();
if (!event.data if (!event.data
|| !event.data.waitUntil || !event.data.waitUntil) {
|| event.data.waitUntil < now.getTime()) {
return; return;
} }
if (timeout) { if (timeout) {
clearTimeout(timeout); clearTimeout(timeout);
} }
if (event.data.waitUntil < now.getTime()) {
participant.send('open', getRotationUrl(urls, indata));
return;
}
timeout = setTimeout(() => { timeout = setTimeout(() => {
participant.send('open', getRotationUrl(urls, indata)); participant.send('open', getRotationUrl(urls, indata));
}, event.data.waitUntil - now.getTime()); }, event.data.waitUntil - now.getTime());