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

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

.term table {
    border-collapse: collapse;
}

.term td {
    padding: 0px;
}
    </style>
    <script>
var colors = [
    "#000000",
    "#ff0000",
    "#00ff00",
    "#ffff00",
    "#0000ff",
    "#ff00ff",
    "#00ffff",
    "#ffffff",
];
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';
                if (cell.fgcolor || cell.bgcolor) {
                    term += ' style="';
                    if (cell.fgcolor) {
                        term += 'color: ' + colors[cell.fgcolor] + ';';
                    }
                    if (cell.bgcolor) {
                        term += 'background-color: ' + colors[cell.bgcolor] + ';';
                    }
                    term += '"';
                }
                term += '>';
                if (cell.contents == " ") {
                    term += "&nbsp;";
                }
                else {
                    term += cell.contents;
                }
                term += '</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>