This repository was archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-sync.html
82 lines (63 loc) · 2 KB
/
test-sync.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
82
<html>
<head>
<title>GoTime Example</title>
</head>
<body>
Local:
<br />
<h1 id="local"></h1>
Server:
<br />
<h1 id="server"></h1>
<h1 id="syncs">Sync History</h1>
<table id="sync-table">
</table>
<h1>Stats</h1>
Offset:
<span id="offset"></span> with best precision:
<span id="precision"></span>
<script src="GoTime.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="logging.js"></script>
<script src="LoggingService.js"></script>
<script>
function appendHistory(t, method, offset, precision) {
$('#sync-table').append("<tr><td>" + (new Date(t)).toLocaleTimeString() + "</td><td>" + method + "</td><td>" + offset + "ms</td><td>" + precision + "ms</td></tr>");
}
function updateData(t, method, off, precision) {
var l = new Date();
var s = new GoTime();
$('#local').text(l.getTime());
$('#server').text(s.getTime());
$('#offset').text(GoTime.getOffset());
$('#precision').text(GoTime.getPrecision());
appendHistory(t, method, off, precision);
console.log(GoTime.getHistory());
}
$(function() {
// Set options before first GoTime use
GoTime.setOptions({
//AjaxURL: "/time",
WhenSynced: updateData, // Is called for the first sync
OnSync: updateData, // Calls on ever sync starting with the second sync
SyncInitialTimeouts: [500, 3000, 9000, 15000],
SyncInterval: 20000 // Set this often for demo purposes only
});
var socket = io.connect(location.origin);
socket.on('time', function(data) {
console.log('syncing from received server time ', data);
GoTime.wsReceived(data);
});
console.log(socket);
GoTime.wsSend(function() {
if (socket !== null && socket.connected) {
socket.emit("time");
return true;
}
return false;
});
});
</script>
</body>
</html>