-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathindex.html
125 lines (112 loc) · 3.25 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
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Person Listeners</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"
integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ=="
crossorigin="anonymous">
<script type="text/javascript"
src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
var wsocket;
var isConnected=false;
function openWebSocket() {
var wsurl = "ws://localhost:9292/newPersonEvent";
wsocket = new WebSocket(wsurl);
isConnected=true;
wsocket.onmessage = function(evt) {
var person = JSON.parse(evt.data);
console.log("onMessage: " + person);
addPersonToTable(person);
}
wsocket.onerror = function(evt) {
console.error(evt);
alert("Failed to connect to " + wsurl + ". Are you sure that the server has started yet?");
isConnected=false;
}
waitForSocketConnection(wsocket, function() {
console.log("WebSocket connected!");
$("#connectButton").text("Disconnect");
$("#personTable").removeClass("hidden");
isConnected=true;
});
}
function toogleConnect() {
if(isConnected) {
wsocket.close();
$("#connectButton").text("Connect");
$("#personTable").addClass("hidden");
isConnected=false;
clearPersonTable();
} else {
openWebSocket();
}
}
function addPersonToTable(person) {
$('#personTable > tbody:last-child')
.append($("<tr>")
.append($("<td>")
.append(person.id)
)
.append($("<td>")
.append(person.firstName + " " + person.lastName)
)
.append($("<td>")
.append(person.age)
)
);
}
function clearPersonTable() {
$('#personTable > tbody').empty();
}
function waitForSocketConnection(socket, callback) {
setTimeout(function() {
if (socket.readyState === 1) {
if (callback !== undefined) {
callback();
}
return;
} else {
waitForSocketConnection(socket, callback);
}
}, 5);
};
</script>
</head>
<body style="margin: 20px">
<h1>Camel-jbossdatagrid example</h1>
<p>This example uses websockets to listen to events from the JBoss
Data Grid via JBoss Fuse. When connected a table will appear below
that is populated with events from the Data Grid (via websockets)</p>
<p>Persons are added by providing a CSV file that will be processed
by JBoss Fuse</p>
<p>How to add persons via command line in a *NIX platform:</p>
<p>
<code>$ echo "99,Diego,Maradona,75" >
$incomingFolderPath/sample.csv</code>
</p>
<p>Or add a list of players in a CSV file like this:</p>
<p>
<code>$ cp best-footballplayers-2015.csv $incomingFolderPath/</code>
</p>
<p>
<i>Environment varialbe $incomingFolderPath should be set at build
time see README.md for more details</i>
</p>
<button type="button" class="btn btn-default" id="connectButton"
onclick="toogleConnect()">Connect</button>
<p></p>
<table id="personTable" class="table table-striped hidden">
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
<th>AGE</th>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>