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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
<!doctype html>
<html>
<head>
<title>Vainsocial backend status</title>
</head>
<body>
<p>
<form id="update-form">
<input type="text" id="update-name">
<input type="checkbox" id="update-force">
<label for="update-force">Force refresh</label>
<input type="submit" value="Update">
</form>
</p>
<p>
<form id="update-random-form">
<input type="submit" value="Update random player">
</form>
</p>
<p>
<form id="get-samples-form">
<input type="submit" value="Download latest samples">
</form>
</p>
<p>
<form id="crunch-form">
<input type="text" id="crunch-name">
<input type="submit" value="Crunch">
</form>
</p>
<p>
<form id="crunchglobal-form">
<input type="submit" value="Crunch global stats">
</form>
</p>
<ul id="updates"></ul>
<script src="https://cdn.jsdelivr.net/sockjs/1/sockjs.min.js"></script>
<script type="text/javascript" src="/js/webstomp.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
let client;
// set up the client
if ('WebSocket' in window && (typeof WebSocket === 'function' || typeof WebSocket === 'object')) {
client = webstomp.client("ws://localhost:15674/ws");
} else {
// http fallback
client = webstomp.over(SockJS("http://localhost:15674/stomp"));
}
let notif = (text, color) => {
$("#updates").append(
$("<li>")
.text(text)
.css("color", color)
);
};
// connect
client.connect("web", "web", () => {
notif("connected to socket", "purple");
client.subscribe("/topic/#", (msg) => {
let name = "";
if (msg.headers.destination.indexOf("player") != -1)
name = msg.headers.destination.substring(
"/topic/player.".length);
else name = "global";
notif(msg.body, "grey");
switch (msg.body) {
case "search_fail":
notif(name + ": not found", "red"); break;
case "search_success":
notif(name + ": found", "green"); break;
case "matches_update":
notif(name + ": new match(es) available", "orange"); break;
case "stats_update":
notif(name + ": player profile stats updated", "orange"); break;
}
msg.ack();
}, {"ack": "client"});
},
(err) => notif("error connecting to socket: " + JSON.stringify(err), "red"));
$("#update-form").submit((e) => {
e.preventDefault();
let ign = $("#update-name").val(),
force = $("#update-force").is(":checked");
if (force) {
$.post("/api/player/" + ign + "/search");
} else {
$.post("/api/player/" + ign + "/update");
}
});
$("#update-random-form").submit((e) => {
e.preventDefault();
$.post("/api/player");
});
$("#get-samples-form").submit((e) => {
e.preventDefault();
$.post("/api/samples").done((resp) => {
notif("downloading samples", "green");
});
});
$("#crunch-form").submit((e) => {
e.preventDefault();
let ign = $("#crunch-name").val();
$.post("/api/player/" + ign + "/crunch");
});
$("#crunchglobal-form").submit((e) => {
e.preventDefault();
$.post("/api/crunch");
});
</script>
</body>
</html>
|