]> git.r.bdr.sh - rbdr/sorting-hat-renderer/blob - lib/services/data.js
cc6c5eef3840891d9626b8adc8160b7b8be7befe
[rbdr/sorting-hat-renderer] / lib / services / data.js
1
2 const internals = {
3 kSocketLocation: 'ws://localhost:1987',
4
5 data: {
6 state: 0,
7 runningAverages: {},
8 winner: null
9 },
10
11 initSocket() {
12
13 internals.socket = new WebSocket(internals.kSocketLocation);
14 internals.socket.addEventListener('message', (data) => {
15
16 Object.assign(internals.data, JSON.parse(data.data));
17 });
18 }
19 };
20
21 export default {
22 data() {
23
24 if (!internals.socket) {
25 internals.initSocket();
26 }
27
28 return internals.data;
29 }
30 };