Skip to content

Commit ec38634

Browse files
committed
add clock.html
1 parent daf0ea5 commit ec38634

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

src/stream-ui/clock.html

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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>

src/stream-ui/css/clock.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.clock {
2+
display: block;
3+
background-color: black;
4+
color: white;
5+
font-family: "Georama Regular", sans-serif;
6+
font-size: 0;
7+
border-top-left-radius: 12px;
8+
border-bottom-left-radius: 12px;
9+
padding: 8px 14px;
10+
margin-left: 30px;
11+
}
12+
13+
.min-sec {
14+
font-size: 32px;
15+
display: inline-block;
16+
margin-right: 4px;
17+
}
18+
19+
.mil {
20+
font-family: "Georama Light", sans-serif;
21+
font-size: 18px;
22+
}

src/stream-ui/js/api.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ class Api {
99
static getCurrentStarts(meeting, callback) {
1010
$.get(this.start_service_url + "start/meet/" + meeting + "/current", callback)
1111
}
12-
}
12+
13+
static getCurrentHeat(meeting, callback) {
14+
$.get(this.start_service_url + "heat/meet/" + meeting + "/current", callback)
15+
}
16+
}

0 commit comments

Comments
 (0)