-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
113 lines (95 loc) · 2.4 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!doctype html>
<html>
<head>
<title>Socket benchmark</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
button, textarea {
font-family: monospace;
}
button {
display: block; float: left;
height: 3em;
}
textarea#out {
display: block;
width: 100%;
height: 80%;
border: none;
resize: none;
}
</style>
</head>
<body>
<button id="sockjs-connect">Connect SockJS</button>
<button id="engine-connect">Connect EngineIO</button>
<button id="websockets-tog">Toggle WebSockets</button>
<textarea id="out" readonly></textarea><br />
<script>
if(location.hash.indexOf('no-ws')>=0) {
window.WebSocket = false;
window.MozWebSocket = false;
}
</script>
<script src="/engine.io.js"></script>
<script src="/sockjs.min.js"></script>
<script>
var $ = document.querySelectorAll.bind(document);
$("#engine-connect")[0].onclick = function () {
var socket = eio("ws://localhost:7625/ng/"),
tester = test("engine", socket);
socket.on('open', tester.onopen);
socket.on('message', tester.onmessage);
}
$("#sockjs-connect")[0].onclick = function () {
var socket = new SockJS("http://localhost:7625/sockjs"),
tester = test ("sockjs", socket);
socket.onopen = tester.onopen;
socket.onmessage = tester.onmessage;
}
$("#websockets-tog")[0].onclick = function () {
if(location.hash.indexOf('no-ws')>=0) {
console.log("Enabling");
location.hash = "";
} else {
console.log("Disabling");
location.hash='#no-ws';
}
location.reload();
}
function test (name, socket, cb) {
var start = performance.now();
var num = 0;
return {
onopen: function () {
log(name, "conn", performance.now() - start);
start = performance.now();
socket.send('hello0');
},
onmessage: function () {
log(name, "echo", performance.now() - start);
start = performance.now();
num++;
if(num < 10) {
socket.send('hello' + num);
} else {
log(name, "done\n");
socket.close();
if(cb) cb();
}
}
};
}
function log() {
var str = Array.prototype.slice.call(arguments).join(" "),
out = $("#out")[0];
out.value = out.value + str + "\n";
out.scrollTop = out.scrollHeight;
}
</script>
</body>
</html>