blob: c07fcff020c901b3449bb8b06d64e31be09fc47b (
plain)
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
|
import { Component } from 'react';
class SocketController extends Component {
connectSocket() {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const socket = new WebSocket(protocol + '//' + window.location.host + '/api/socket');
socket.onclose = () => {
setTimeout(() => this.connectSocket(), 60 * 1000);
};
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.positions) {
// TODO update positions
console.log(data.positions);
}
}
}
componentDidMount() {
this.connectSocket();
}
render() {
return null;
}
}
export default SocketController;
|