This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket.js
55 lines (43 loc) · 1.57 KB
/
websocket.js
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
var hidden = false;
var variables = {
startTime: 0,
pauseTime: 0,
lineupType: "Test"
};
var isController = window.location.pathname.indexOf("control.html") > 0
var ws = new WebSocket("ws://" + window.location.hostname + ":8080");
ws.onmessage = function (data) {
data = data.data;
console.log(data);
if (typeof data === 'string') {
data = JSON.parse(data);
if (!isController && data.type === "goto") {
if (!hidden && typeof window["hide"] === "function") {
window["hide"]();
setTimeout(function () {
window.location = data.target;
}, 2000)
} else {
window.location = data.target;
}
// window.location = data.target;
} else if (!isController && data.type === "func") {
if (typeof window[data.name] === "function") {
window[data.name]();
hidden = data.name === "hide";
}
} else if (data.type === "var") {
variables[data.name] = data.value;
if (data.name === "score1") {
document.getElementById("counter").setAttribute("data-team1", data.value)
} else if (data.name === "score2") {
document.getElementById("counter").setAttribute("data-team2", data.value)
} else if (data.name.indexOf('_') == 2) {
document.getElementById(data.name).innerHTML = data.value
}
}
}
};
ws.onclose = function () {
//window.location = window.location;
};