-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
81 lines (68 loc) · 2.46 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Latency Test | Red5 Pro</title>
<link rel="stylesheet" href="normalize.min.css">
<style>
body {
background-color: white;
color: black;
}
</style>
</head>
<body>
<h1>Red5 Pro Latency Test</h1>
<table border="1">
<!--
<tr>
<td>client</td>
<td id="client"></td>
</tr>
-->
<tr>
<td>server</td>
<td id="server"></td>
</tr>
<tr>
<td>difference</td>
<td id="difference" style="text-align: right"></td>
</tr>
</table>
<script type="module">
import { getServerDate } from "./serverDate.js.php";
let lastSample = {};
const synchronize = async () => {
lastSample = await getServerDate();
console.log("Synchronized lastSample: " + JSON.stringify(lastSample));
};
// Display two real time clocks, the server's and the client's, and show
// the difference between them in milliseconds.
function updateClocks() {
var { offset, uncertainty } = lastSample;
var clientDate = new Date();
var serverDate = new Date(clientDate.getTime() + offset);
try {
var clientDateISO = clientDate.toISOString();
var serverDateISO = serverDate.toISOString();
// console.log("clientDate: " + clientDate.toISOString() + " serverDate: " + serverDate.toISOString());
} catch (error) {
var clientDateISO = "";
var serverDateISO = "";
}
// document.getElementById("client").innerHTML = clientDateISO;
document.getElementById("server").innerHTML = serverDateISO;
document.getElementById(
"difference"
).innerHTML = `${offset} ± ${uncertainty} ms`;
};
synchronize();
setInterval(synchronize, 10 * 60 * 1000);
// Display the clocks and update them 100 times a second.
updateClocks();
setInterval(updateClocks, 10);
</script>
</body>
</html>