aboutsummaryrefslogtreecommitdiff
path: root/modern/src/SocketContoller.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/SocketContoller.js')
-rw-r--r--modern/src/SocketContoller.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/modern/src/SocketContoller.js b/modern/src/SocketContoller.js
new file mode 100644
index 0000000..c07fcff
--- /dev/null
+++ b/modern/src/SocketContoller.js
@@ -0,0 +1,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;