aboutsummaryrefslogtreecommitdiffstats
path: root/termcast_server/index.html
blob: 373587feb868c22701edf1c95a3113727587ad6c (plain) (blame)
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
<!DOCTYPE html>
<html>
<head>
    <style>
.menu {
    display: none;
}

.term {
    display: none;
    font-family: monospace;
}

.term .td {
    width: 1em;
}
    </style>
    <script>
var url = location.origin.replace(/^http/, 'ws') + "/-/";
socket = new WebSocket(url);
socket.onopen = function (e) {
    socket.send(JSON.stringify({"type": "request_streamer_list"}));
};
socket.onmessage = function (e) {
    console.log(e.data);
    var data = JSON.parse(e.data);
    var type = data.type;

    if (type == "streamer_list") {
        document.querySelector('.term').style.setProperty('display', 'none');
        var menudiv = document.querySelector('.menu');
        var menu = '<ul>';
        data.streamers.forEach(function (streamer) {
            menu += '<li><a href="#" onclick=' + "'socket.send(JSON.stringify({\"type\": \"start_watching\", \"who\": \"" + streamer.id + "\"}))'" + '>' + streamer.name + '</a></li>';
        });
        menu += '</ul>';
        menudiv.innerHTML = menu;
        menudiv.style.setProperty('display', 'block');
    }
    else if (type == "update_screen") {
        document.querySelector('.menu').style.setProperty('display', 'none');
        var termdiv = document.querySelector('.term');
        term = '<table class="screen">';
        data.screen.forEach(function (row) {
            term += '<tr>';
            row.forEach(function (cell) {
                term += '<td>' + cell.contents + '</td>';
            });
            term += '</td>';
        });
        term += '</table>';
        termdiv.innerHTML = term;
        termdiv.style.setProperty('display', 'block');
    }
    else if (type == "streamer_disconnect") {
        socket.send(JSON.stringify({"type": "request_streamer_list"}));
    }
};
    </script>
</head>
<body>
    <div class="menu"></div>
    <div class="term"></div>
</body>
</html>