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
<!doctype html>
<html>
<head>
<title>IRC Client Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="/resources/js/sockjs-0.3.min.js"></script>
<style>
#container {
width: 800px;
margin: 40px auto;
padding: 0;
}
#irc-holder {
height: 600px;
width: 800px;
overflow: auto;
border: 2px solid black;
}
#irc { width: 100%; border-collapse: collapse; }
#irc tr { border-bottom: 1px solid gray; }
#chatter input[type="text"] { width: 700px; }
#chatter input[type="submit"] { width: 90px; }
#protocol { font-size: 1.5em; margin: auto; width: 300px; display: block; }
</style>
</head>
<body>
<div id="container">
<div id="irc-holder">
<table id="irc"></table>
</div>
<form method="GET" id="chatter">
<input type="text" />
<input type="submit" value="Send" />
<br />
<select id="protocol">
<option value="websocket" selected>Websocket</option>
<option value="xdr-streaming">XDR Streaming</option>
<option value="xhr-streaming">XHR Streaming</option>
<option value="iframe-eventsource">Eventsource</option>
<option value="iframe-htmlfile">HTMLFile</option>
<option value="xdr-polling">XDR Polling</option>
<option value="xhr-polling">XHR Polling</option>
<option value="iframe-xhr-polling">XHR Polling (IFrame)</option>
<option value="jsonp-polling">JSONP Polling</option>
</select>
</form>
</div>
<script>
$(document).keypress(function(e) { return e.which !== 0; });
if(window.location.port!="")
url = window.location.protocol+'//'+window.location.hostname+':'+window.location.port+'/sockjschat';
else
url = window.location.protocol+'//'+window.location.hostname+'/sockjschat';
var conn = false;
function connect() {
if(conn)
conn.close()
conn = false
var protocol = $('#protocol').val();
conn = new SockJS(url,null,{debug:true,devel:true,protocols_whitelist:[protocol]});
var log = function(msg) { $('#irc').append($('<tr>').html($('<td>').html(msg))); };
conn.onopen = function(evt) { log('<i>Connected via '+$('#protocol').val()+'</i>'); };
conn.onclose = function(evt) { log('<i>Disconnected</i>'); };
conn.onmessage = function(evt) { log($('<div>').text(evt.data).html()); };
}
$('#chatter').submit(function() {
var txt = $(this).find('input[type="text"]');
var m = txt.val();
conn.send(m+"\r\n");
txt.val('');
return false;
});
$('#protocol').change(connect);
connect();
</script>
</body>
</html>