-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.html
55 lines (46 loc) · 1.6 KB
/
client.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
<script type="text/javascript" src="json-viewer.js"></script>
<link rel="stylesheet" type="text/css" href="/json-viewer.css">
<div id="output"></div>
<script>
var output = document.getElementById("output");
var wsClient = {};
wsClient.connect = function() {
var ws = new WebSocket('ws://100.109.0.10:8000/');
ws.onopen = function() {
console.log('ws connected');
ws.send(window.JSON.stringify('connect'));
};
ws.onerror = function() {
console.log('ws error');
};
ws.onclose = function() {
console.log('ws closed');
};
ws.onmessage = function(msgevent) {
console.log('received');
var notification = JSON.parse(msgevent.data);
console.log(notification);
onNotificationReceived(notification);
};
};
function onNotificationReceived(notification){
var display = {};
var instance_payload = notification.payload['nova_object.data'];
display.event_type = notification.event_type;
if (! display.event_type.includes('scheduler'))
{
display.name = instance_payload.display_name;
display.state = instance_payload.state;
display.power_state = instance_payload.power_state;
display.task_sate = instance_payload.task_state;
display.host = instance_payload.host;
display.full_payload = notification.payload;
}
display.full_payload = notification.payload;
var jsonViewer = new JSONViewer();
var container = jsonViewer.getContainer();
output.appendChild(container);
jsonViewer.showJSON(display, null, 1);
}
wsClient.connect();
</script>