// requires env, utils and config (function () { // where am I? var isOnDemand = /ondemand/.test(location.pathname); var isPostLive = /postlive/.test(location.pathname); var isLive = !isPostLive && /live/.test(location.pathname); console.info('is ondemand: ', isOnDemand, ' - isPostLive: ', isPostLive, ' - isLive: ', isLive); var now = new Date().getTime(); console.info('now', new Date(), ' ms ', new Date().getTime()); // restrict redirect logic to production if (!env.DEV) { if (now > Config.onDemandInitUTC) { console.info('ON DEMAND SLOT'); // first case: ondemand if (!isOnDemand) { Utils.redirect('ondemand.html'); } } else if (now > Config.liveEndUTC) { console.info('LIVE END SLOT'); // second case: postlive if (!isPostLive) { Utils.redirect('postlive.html'); } } else if (now > Config.countdownEndUTC - 60000) { console.info('LIVE SLOT'); // third case: live // the 60000 shift is due to an hack inside the flipclock lib which will trigger // countdown end 1 minute earlier (because seconds are not shown and otherwise // the ui would stay for one minute with 00:00) if (!isLive) { Utils.redirect('live.html'); } } else { console.info('COUNTDOWN SLOT'); // last: countdown // the 60000 shift is due to an hack inside the flipclock lib which will trigger // countdown end 1 minute earlier (because seconds are not shown and otherwise // the ui would stay for one minute with 00:00) if (isLive || isOnDemand || isPostLive) { Utils.redirect('index.html'); } } // switch from // live -> postlive // postlive -> ondemand // automatically, needs an interval callback to be run every 5 seconds if (isLive) { var checkLiveEnd = function () { if (now > Config.liveEndUTC) { Utils.redirect('postlive.html'); } }; setInterval(checkLiveEnd, 5 * 1000); } if (isPostLive) { var checkPostLiveEnd = function () { if (now > Config.onDemandInitUTC) { Utils.redirect('ondemand.html'); } }; setInterval(checkPostLiveEnd, 5 * 1000); } } })();