-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwae.html
205 lines (180 loc) · 6.32 KB
/
wae.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="This is an activemq eavesdropper.">
<meta name="keywords" content="activemq, stomp, websocket, SPA">
<title>WebSocket ActiveMQ Eavesdropper</title>
<link rel="stylesheet" href="wae.css">
</head>
<body>
<div id="wrapper">
<header id="main_header">
<h1>WebSocket ActiveMQ Eavesdropper</h1>
</header>
<nav id="main_menu">
<ul>
<li>
<label for="servers">Choose a server:</label>
<select id="servers" onchange="changeServer()">
<option value="Bandersnatch">Bandersnatch</option>
<option value="Joe">Joe</option>
<option value="Jumar">Jumar</option>
</select>
</li>
<li>
<label for="topics">Choose a topic:</label>
<select id="topics" onchange="changeTopic()">
<option value="/topic/ARCINDI/responses">
arcindi-responses
</option>
<option value="/topic/ARCINDI/testtest">
arcindi-testtest
</option>
<option value="/topic/TCS.TCSSharedVariables.TCSHighLevelStatusSV.TCSTcsStatusSV">
TCSHighLevelStatusSV
</option>
<option value="/topic/TCS.TCSSharedVariables.TCSSubData.TCSActiveOpticsCommandSV">
TCSActiveOpticsCommandSV
</option>
<option value="/topic/TCS.TCSSharedVariables.TCSSubData.TCSGuiderCommandSV">
TCSGuiderCommandSV
</option>
<option value="/topic/TCS.TCSSharedVariables.TCSSubData.TCSTcsCommandSV">
TCSTcsCommandSV
</option>
<option value="/topic/WRS.WRSPubDataSV.WRSDataPacket">
WRSDataPacket
</option>
<option value="/topic/LOUI.lemi.loisCommand">
LOUI.lemi.loisCommand
</option>
<option value="/topic/wrs.loisTelemetry">
wrs.loisTelemetry
</option>
<option value="/topic/RC2.loisTelemetry">
RC2.loisTelemetry
</option>
</select>
</li>
</ul>
</nav>
<p id="demo"></p>
</div>
<script src="./stomp.js"></script>
<script type="text/javascript">
function changeServer() {
var x = document.getElementById("servers").value;
/* Always unsubscribe, disconnect, and clear when changing servers. */
subscription.unsubscribe();
client.disconnect(function () { console.log("disconnecting")});
document.getElementById("demo").innerHTML = "";
if (x == "Jumar") {
console.log("ws://jumar:61614/stomp");
server = "ws://jumar:61614/stomp";
connectClient(server, topic);
} else if (x == "Joe") {
console.log("ws://joe:61614/stomp");
server = "ws://joe:61614/stomp";
connectClient(server, topic);
} else if (x == "Bandersnatch") {
console.log("ws://bandersnatch:61614/stomp");
server = "ws://bandersnatch:61614/stomp";
connectClient(server, topic);
}
}
function changeTopic() {
var x = document.getElementById("topics").value;
/* Always unsubscribe, disconnect, and clear when changing topics. */
subscription.unsubscribe();
client.disconnect(function () { console.log("disconnecting")});
document.getElementById("demo").innerHTML = "";
topic = x
connectClient(server, topic);
}
function BuildXMLFromString (text) {
var message = "";
var parser = new DOMParser();
/* Create and XML structure from a string. */
try {
xmlDoc = parser.parseFromString (text, "text/xml");
} catch (e) {
// if text is not well-formed,
// it raises an exception in IE from version 9
alert ("XML parsing error.");
return false;
};
var errorMsg = null;
if (xmlDoc.parseError && xmlDoc.parseError.errorCode != 0) {
errorMsg = "XML Parsing Error: " + xmlDoc.parseError.reason
+ " at line " + xmlDoc.parseError.line
+ " at position " + xmlDoc.parseError.linepos;
}
else {
if (xmlDoc.documentElement) {
if (xmlDoc.documentElement.nodeName == "parsererror") {
errorMsg = xmlDoc.documentElement.childNodes[0].nodeValue;
}
}
else {
errorMsg = "XML Parsing Error!";
}
}
if (errorMsg) {
/* alert (errorMsg); */
return false;
}
/* alert ("Parsing was successful!"); */
return true;
}
function xmlToForm(xmlDoc) {
/* Retreive information from XML structure, format for easy reading.
A few HTML tags are used in the formatting. */
var nodes = xmlDoc.querySelectorAll("*");
var framed_html = "<pre>";
for (var i = 0; i < nodes.length; i++) {
var text = null;
if (nodes[i].childNodes.length == 1 &&
nodes[i].childNodes[0].nodeType == 3) //if nodeType == text node
text = nodes[i].textContent; //get text of the node
framed_html += nodes[i].tagName;
framed_html += " -- ";
if (text != null) {
framed_html += text;
}
framed_html += "<br>";
}
framed_html += "</pre>";
return(framed_html);
}
function connectClient(server, topic) {
/* Connect to server and subscribe to topic.
When we get a message, try to parse it as XML.
If it parses, format it on the web page.
If it won't parse, just dump the message body on the web page.
*/
delete client;
client = Stomp.client(server, "v11.stomp");
client.connect("", "",
function() {
subscription = client.subscribe(topic,
function(message) {
var xmlStr = message.body;
tf = BuildXMLFromString(xmlStr);
if (tf) {
document.getElementById("demo").innerHTML = xmlToForm(xmlDoc);
} else {
document.getElementById("demo").innerHTML = message.body;
}
}, {priority: 9 }
);
}
);
}
/* Default server and topic, initial connection. */
var server = "ws://bandersnatch:61614/stomp";
var topic = "/topic/ARCINDI/responses";
connectClient(server, topic);
</script>
</body>
</html>