|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <title>Clock - SwimResults Stream View</title> |
| 5 | + |
| 6 | + <link rel="stylesheet" href="css/style.css"> |
| 7 | + <link rel="stylesheet" href="css/clock.css"> |
| 8 | + |
| 9 | + <script src="js/jquery-3.7.1.min.js"></script> |
| 10 | + <script src="js/api.js"></script> |
| 11 | + <script src="js/helper.js"></script> |
| 12 | + <script src="js/models.js"></script> |
| 13 | + |
| 14 | + <script> |
| 15 | + |
| 16 | + const settings = Helper.getSettings(); |
| 17 | + const refreshTime = settings.refreshTime; |
| 18 | + const skipConfig = settings.skipConfig; |
| 19 | + |
| 20 | + |
| 21 | + const MEETING = settings.meeting; |
| 22 | + |
| 23 | + let heat = { |
| 24 | + _id: "0", |
| 25 | + meeting: MEETING, |
| 26 | + event: 0, |
| 27 | + number: 0, |
| 28 | + finish_at: new Date(0) |
| 29 | + }; |
| 30 | + |
| 31 | + let interval; |
| 32 | + |
| 33 | + // it's called milliseconds, but it is actually 1/100 seconds |
| 34 | + let milliseconds = 0; |
| 35 | + |
| 36 | + // called onLoad |
| 37 | + function setup() { |
| 38 | + |
| 39 | + if (settings.background) $('#body').addClass('background') |
| 40 | + |
| 41 | + let setupTime = skipConfig ? 3000 : 30000; |
| 42 | + setTimeout(() => { |
| 43 | + $('#config').addClass("hidden"); |
| 44 | + setInterval(() => { |
| 45 | + tick(); |
| 46 | + }, refreshTime); |
| 47 | + }, setupTime); |
| 48 | + } |
| 49 | + |
| 50 | + function receiveHeat(data) { |
| 51 | + console.log(data); |
| 52 | + if (data) { |
| 53 | + |
| 54 | + // if it is a new heat, clear all starts; |
| 55 | + |
| 56 | + const newHeat = new Heat(data); |
| 57 | + |
| 58 | + if (!heat || heat._id !== newHeat._id || heat.start_at.getTime() !== newHeat.start_at.getTime()) { |
| 59 | + heat = newHeat; |
| 60 | + starts = new Map(); |
| 61 | + console.log("new heat event: " + heat.event + "; heat: " + heat.number); |
| 62 | + interval = setInterval(clockTick, 10); |
| 63 | + } else if (newHeat.finished_at.getTime() > heat.finished_at.getTime()) { |
| 64 | + console.log("heat finished"); |
| 65 | + heat = newHeat; |
| 66 | + milliseconds = 0; |
| 67 | + clearInterval(interval); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + function writeTime() { |
| 73 | + const now = new Date(); |
| 74 | + let timePassed = now - heat.start_at.getTime(); |
| 75 | + const time = new Date(timePassed); |
| 76 | + const min = time.getMinutes(); |
| 77 | + const sec = time.getSeconds(); |
| 78 | + const mil = Math.round(time.getMilliseconds() / 10); |
| 79 | + $('#min').html(("0" + min).substr(-2)); |
| 80 | + $('#sec').html(("0" + sec).substr(-2)); |
| 81 | + $('#mil').html(("0" + mil).substr(-2)); |
| 82 | + } |
| 83 | + |
| 84 | + async function clockTick() { |
| 85 | + writeTime(); |
| 86 | + } |
| 87 | + |
| 88 | + function tick() { |
| 89 | + console.log("tick"); |
| 90 | + Api.getCurrentHeat(MEETING, receiveHeat); |
| 91 | + } |
| 92 | + |
| 93 | + </script> |
| 94 | +</head> |
| 95 | + |
| 96 | +<body onload="setup()" id="body"> |
| 97 | + |
| 98 | +<div id="config"> |
| 99 | + <h1>Clock View</h1> |
| 100 | + <p> |
| 101 | + This text will be hidden after 30 seconds.<br> |
| 102 | + You can use this time to adjust the positioning in your streaming application.<br> |
| 103 | + If you want to skip this step, use query param skip_config=1. |
| 104 | + </p> |
| 105 | +</div> |
| 106 | + |
| 107 | +<div id="clock" class="clock"> |
| 108 | + <span class="min-sec"><span class="min" id="min">00</span>:<span class="sec" id="sec">00</span></span> |
| 109 | + <span class="mil" id="mil">00</span> |
| 110 | +</div> |
| 111 | + |
| 112 | +</body> |
| 113 | +</html> |
0 commit comments