forked from DileSoft/vangers_monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitoring_events_debug.html
60 lines (54 loc) · 1.96 KB
/
monitoring_events_debug.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
<html>
<head>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<meta charset="UTF-8" />
<script src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<!-- Don't use this in production: -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id="main"></div>
<script type="text/babel">
let Component = function (props) {
let [state, setState] = React.useState();
React.useEffect(() => {
let connect = () => {
var ws = new WebSocket("ws://vangers.dilesoft.ru:8088");
ws.onmessage = function (event) {
try {
let data = JSON.parse(event.data);
console.log(data);
setState(data.results);
} catch (e) {
}
}
ws.onclose = function(e) {
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
setTimeout(function() {
connect();
}, 1000);
};
ws.onerror = function(err) {
console.error('Socket encountered error: ', err.message, 'Closing socket');
ws.close();
};
}
connect();
}, []);
if (!state) {
return 'Loading...';
}
return <>
<pre>
{JSON.stringify(state, null, 2)}
</pre>
</>
}
ReactDOM.render(
<Component/>,
document.getElementById('main')
);
</script>
</body>
</html>