forked from eclipse-vertx/vert.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
112 lines (99 loc) · 2.55 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
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://cdn.sockjs.org/sockjs-0.2.1.min.js"></script>
<script src="vertxbus.js"></script>
</head>
<style>
.box {
background-color: #F0F0F0;
border: 5px solid blue;
width: 400px;
height: 300px;
overflow: scroll;
float: left;
}
body {
background-color: #fff;
}
</style>
<body>
<div id="logbox" class="box">
<form onsubmit="return false;">
Address: <input type="text" id="address" value="someaddress"/><br />
Message: <input type="text" id="message" value="Hello, World!"/><br />
<div id="status">disconnected</div>
<button id="send">Send</button>
<button id="publish">Publish</button>
<button id="register">Register</button>
<button id="unregister">Unregister</button>
<button id="connection">Connect</button>
<button id="refresh">Refresh log</button>
</form>
<div>Log</div>
<ul>
</ul>
</div>
<div id="messages" class="box">
<div>Messages</div>
<ul>
</ul>
</div>
<script>
var eb = null;
var receiveHandler = function(data) {
$('#messages ul').append('<li>' + JSON.stringify(data) + '</li>');
};
function refreshLog() {
$.getJSON('/log.json', function(data) {
$('#logbox ul li').remove();
for (var i = data.length - 1; i >= 0; i--) {
$('#logbox ul').append('<li>' + data[i] + '</li>');
}
});
}
$(document).ready(function() {
$('#refresh').click(function() {
refreshLog();
});
$('#send').click(function() {
if (eb) {
eb.send($('#address').val(), {"text" : $('#message').val()});
}
});
$('#publish').click(function() {
if (eb) {
eb.publish($('#address').val(), {"text" : $('#message').val()});
}
});
$('#register').click(function() {
if (eb) {
eb.registerHandler($('#address').val(), receiveHandler);
}
});
$('#unregister').click(function() {
if (eb) {
eb.unregisterHandler($('#address').val(), receiveHandler);
}
});
$('#connection').click(function() {
if (eb) {
eb.close();
} else {
eb = new vertx.EventBus("http://localhost:8080/eventbus");
eb.onopen = function() {
$("#status").text("connected");
$('#connection').text('disconnect');
};
eb.onclose = function() {
$("#status").text("disconnected");
$('#connection').text('connect');
eb = null;
};
}
});
});
</script>
</body>
</html>