-
Notifications
You must be signed in to change notification settings - Fork 14
/
index-socketio.html
38 lines (33 loc) · 1.27 KB
/
index-socketio.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
<html>
<title>Dante</title>
<head>
<script src="socket.io/socket.io.js"></script>
<script>
var body;
var address = window.location.protocol + '//' + window.location.host;
// Set the socket.io's resource property to allow for hosting socket.io applications at
// subordinate URL paths, which is the default when hosting node.js applications in
// IIS virtual directories. For example, if this page had been generated by navigating to
// http://localhost/dante/server-socketio.js
// then the socket.io's resource propety below will be set to
// dante/socket.io
// instead of the default
// socket.io
// Note the corresponding change in the server-socketio.js node.js backend.
var details = {
resource: (window.location.pathname.split('/').slice(0, -1).join('/') + '/socket.io').substring(1)
};
var client = io.connect(address, details);
client.on('divinecomedy', addLine);
function addLine(line) {
body = body || document.getElementsByTagName('body')[0];
var div = document.createElement('div');
div.appendChild(document.createTextNode(line));
body.appendChild(div);
}
</script>
</head>
<body>
<h1>Dante over WebSockets with socket.io</h1>
</body>
</html>