-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
93 lines (77 loc) · 2.35 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
<html>
<head>
<title>WebSocket</title>
<style type="text/css">
body {text-align:center;
text-size:150%;
-webkit-font-smoothing: antialiased;
}
.textInput
{
background: #cccccc;
font-size: 200%;
-webkit-box-shadow: 1px 1px 2px #211f21;
-moz-box-shadow: 1px 1px 2px #211f21;
box-shadow: 1px 1px 2px #211f21;
}
.textOutput
{
background: #cccccc;
font-size: 200%;
-webkit-box-shadow: 1px 1px 2px #211f21;
-moz-box-shadow: 1px 1px 2px #211f21;
box-shadow: 1px 1px 2px #211f21;
}
.button
{width:100px;
height:40px;
font-size: 180%}
</style>
<script type="text/javascript" src="web-socket-js/swfobject.js"></script>
<script type="text/javascript" src="web-socket-js/FABridge.js"></script>
<script type="text/javascript" src="web-socket-js/web_socket.js"></script>
<script>
var socket;
WEB_SOCKET_SWF_LOCATION = "web-socket-js/WebSocketMain.swf";
WEB_SOCKET_DEBUG = true;
function openWebSocket() {
if (window.WebSocket) {
socket = new WebSocket('ws://localhost:10000/');
socket.onopen = function(event) { alert('WebSocket open!'); };
socket.onclose = function(event) { alert('WebSocket closed'); };
socket.onmessage = function(event) { parse(event.data); };
} else {
alert('Your browser does not support WebSockets yet.');
}
}
function closeWebSocket() {
socket.close();
}
function $(id) {
return document.getElementById(id);
}
function send(message) {
if (!window.WebSocket) { return; }
if (socket.readyState == WebSocket.OPEN) {
socket.send(message);
} else {
alert('The WebSocket is not open dude!');
}
}
function parse( response ) {
// parse response: json or xml, etc
$('messages').appendChild(document.createTextNode(response));
$('messages').appendChild(document.createTextNode('\n'));
$('messages').scrollTop = $('messages').scrollHeight - $('messages').clientHeight;
}
</script>
</head>
<body onload='openWebSocket()' onunload='closeWebSocket()'>
<BR>
<INPUT type="text" id="message" class="textInput" onkeydown="if (event.keyCode == 13) document.getElementById('button1').click()"><BR><BR>
<INPUT type="button" value="Send" id="button1" class="button" onClick="send(document.getElementById('message').value)">
<BR><BR>
<textarea rows="20" cols="50" id="messages" class="textOutput">
</textarea>
</body>
</html>