forked from rabbitmq/sockjs-erlang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo.html
72 lines (70 loc) · 2.02 KB
/
echo.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
<!DOCTYPE html>
<html><head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
<script src="http://cdn.sockjs.org/sockjs-0.3.4.min.js">
</script>
<style>
.box {
border: 1px dashed black;
border-radius: 4px;
-moz-border-radius: 4px;
width: 400px;
display: block;
height: 300px;
float: left;
}
#output {
border-color: grey;
overflow:auto;
}
#input {
vertical-align: text-top;
-moz-outline-style: none;
outline-style: none;
outline-width: 0px;
outline-color: -moz-use-text-color;
}
body {
background-color: #F0F0F0;
}
</style>
</head><body lang="en">
<h2>SockJS-erlang Echo example</h2>
<form id="form">
<input id="input" autocomplete="off" class="box"
placeholder="type something here" />
</form>
<div id="output" class="box"></div>
<script>
function log(m) {
$('#output').append($("<code>").text(m));
$('#output').append($("<br>"));
$('#output').scrollTop($('#output').scrollTop()+10000);
}
var sockjs_url = '/echo';
var sockjs = new SockJS(sockjs_url);
sockjs.onopen = function() {
log(' [*] Connected (using: '+sockjs.protocol+')');
};
sockjs.onclose = function(e) {
log(' [*] Disconnected ('+e.status + ' ' + e.reason+ ')');
};
sockjs.onmessage = function(e) {
log(' [ ] received: ' + JSON.stringify(e.data));
};
$('#input').focus();
$('#form').submit(function() {
var val = $('#input').val();
$('#input').val('');
var l = ' [ ] sending: ' + JSON.stringify(val);
if (sockjs.readyState !== SockJS.OPEN) {
l += ' (error, connection not established)';
} else {
sockjs.send(val);
}
log(l);
return false;
});
</script>
</body></html>