2019-10-10 11:07:00 +00:00
|
|
|
import React from 'react';
|
|
|
|
import './App.css';
|
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
//let ws = new WebSocket("ws://" + window.location.host + "/sub")
|
|
|
|
let ws = new WebSocket("ws://127.0.0.1:2975/sub")
|
|
|
|
|
|
|
|
ws.onmessage = (ev) => {
|
|
|
|
console.log(ev)
|
|
|
|
let update = JSON.parse(ev.data)
|
|
|
|
|
|
|
|
this.setState( prev => ({
|
|
|
|
...prev, [update.From]: update.Update,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let best = Object.keys(this.state).map(k => this.state[k]).reduce((p, n) => p > n.Height ? p : n.Height, -1)
|
|
|
|
console.log(best)
|
|
|
|
|
2019-10-11 02:45:45 +00:00
|
|
|
return <table>{Object.keys(this.state).map(k => [k, this.state[k]]).map(([k, v]) => {
|
|
|
|
let l = [<td>{k}</td>, <td>{v.NodeName}</td>, <td>{v.Height}</td>]
|
|
|
|
if (best !== v.Height) {
|
|
|
|
l = <tr style={{color: '#f00'}}>{l}</tr>
|
|
|
|
} else {
|
|
|
|
l = <tr>{l}</tr>
|
2019-10-10 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
2019-10-11 02:45:45 +00:00
|
|
|
return l
|
2019-10-10 11:07:00 +00:00
|
|
|
})
|
2019-10-11 02:45:45 +00:00
|
|
|
}</table>
|
2019-10-10 11:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export default App;
|