-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol.html
78 lines (73 loc) · 2.92 KB
/
control.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css">
<script src="/socket.io/socket.io.js"></script>
<script src="/config.js"></script>
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<style>
.container a { margin: 10px 0; white-space: normal; height: auto; }
.loading { background-color: hsl(48, 100%, 67%) !important; color: hsl(0, 0%, 14%) !important; }
.playing { background-color: hsl(141, 71%, 48%) !important; color: hsl(0, 0%, 98%) !important; }
</style>
</head>
<body>
<section class="section">
<div class="container">
<div class="columns">
<script>
['video', 'audio'].forEach(function(which){
document.write(`<div class="column"><h1>${which}</h1>`);
for (let id in config.buttons[which]) {
document.writeln(`<a id="${id}" class="button is-medium is-block is-link has-background-grey-lighter has-text-grey-darker">`);
document.writeln(config.buttons[which][id].text);
document.writeln('</a>');
}
document.writeln('</div>');
});
</script>
</div>
</div>
</section>
<script>
let socket = io();
function clearPlaying(which)
{
Object.keys(config.buttons[which]).forEach(function (id) {
document.getElementById(id).classList.remove('playing');
});
}
['video', 'audio'].forEach(function(which){
for (let id in config.buttons[which]) {
document.getElementById(id).addEventListener('click', function(e){
e.preventDefault();
this.classList.add('loading');
socket.emit(`${which}-start`, { id, ...config.buttons[which][id] });
});
}
['loaded', 'playing', 'ended'].forEach(function(event){
socket.on(`${which}-${event}`, function(data){
//console.log(`event: ${which}-${event}`);
let classes = document.getElementById(data.id).classList;
switch (event) {
case 'loading':
classes.add('loading');
break;
case 'playing':
classes.remove('loading');
clearPlaying(which);
classes.add('playing');
break;
case 'ended':
clearPlaying(which);
break;
}
});
});
});
</script>
</body>
</html>