-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.html
executable file
·66 lines (60 loc) · 2.02 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
<!doctype html>
<html>
<head>
<title>Socket.IO</title>
<script src="/socket.io/socket.io.js"></script>
<script src="/smoothie.js"></script>
<script>
window.onload = function () {
var chart = new SmoothieChart({ grid: { fillStyle: "#ffffff"}, labels: { fillStyle: "#000" } })
, latency = new TimeSeries()
chart.addTimeSeries(latency, { strokeStyle: 'rgba(69, 183, 244, 1)', fillStyle: 'rgba(255, 255, 255, 1)', lineWidth: 4 });
chart.streamTo(document.getElementById("smoothie"), 500);
document.getElementById('v').innerHTML = io.version;
var socket = io.connect()
, lastDate
socket.on('connect', function () {
document.getElementById('transport').innerHTML = socket.socket.transport.name;
var allMs = 0;
var allCount = 0;
var highest = 0;
socket.on('message', function () {
var date = +new Date
, ms = date - lastDate
allMs += ms;
allCount++;
if (ms > highest) highest = ms;
var mean = allMs/allCount;
mean = (~~(mean*1000))/1000;
document.getElementById('c').innerHTML = allCount;
document.getElementById('l').innerHTML = mean;
document.getElementById('h').innerHTML = highest;
latency.append(date, ms);
write();
});
function write() {
setTimeout(function () {
lastDate = new Date
socket.send('ping');
}, 100);
}
write();
});
}
</script>
<style>
h1 {
font: bold 16px Helvetica;
}
em {
background: #fbec94;
-webkit-border-radius: 4px;
font-style: normal;
}
</style>
</head>
<body>
<h1>Socket.IO v<span id="v"></span> - <em id="transport"></em> count: <span id="c"></span>, latency (mean): <span id="l"></span> ms, highest: <span id="h"></span> ms</h1>
<canvas id="smoothie">
</body>
</html>