summaryrefslogtreecommitdiff
path: root/index.html
blob: 26c0f5e15a1e2c87d296cc88ad35f65317e572cd (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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!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="checkbox" id="update-brawl">
                <label for="update-brawl">Get Brawls</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="checkbox" id="crunch-force">
                <label for="crunch-force">Force recrunch</label>
                <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"));
            }

            const 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 "grab_fail":
                            notif(name + ": grabbed everything", "grey"); break;
                        case "grab_success":
                            notif(name + ": grabbed a page", "green"); break;
                        case "matches_update":
                            notif(name + ": new match(es) available", "orange"); break;
                        case "stats_update":
                            notif(name + ": player profile stats updated", "orange"); break;
                        case "points_update":
                            notif(name + ": stats updated", "orange"); break;
                    }
                    msg.ack();
                }, {"ack": "client"});
            },
            (err) => notif("error connecting to socket: " + JSON.stringify(err), "red"));

            $("#update-form").submit((e) => {
                e.preventDefault();
                const ign = $("#update-name").val(),
                    force = $("#update-force").is(":checked"),
                    brawls = $("#update-brawl").is(":checked");

                if (force) {
                    $.post("/api/player/" + ign + "/search");
                } else {
                    if (!brawls)
                        $.post("/api/player/" + ign + "/update");
                    else
                        $.post("/api/player/" + ign + "/update-brawl");
                }
            });
            $("#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();
                const ign = $("#crunch-name").val();
                $.post("/api/player/" + ign + "/crunch");
            });
            $("#crunchglobal-form").submit((e) => {
                const force = $("#crunch-force").is(":checked");
                e.preventDefault();
                if (force)
                    $.post("/api/recrunch");
                else
                    $.post("/api/crunch");
            });
        </script>
    </body>
</html>