-
Notifications
You must be signed in to change notification settings - Fork 36
/
index.html
147 lines (146 loc) · 4.42 KB
/
index.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
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
138
139
140
141
142
143
144
145
146
147
<!doctype html>
<html>
<head>
<title>BabelPod</title>
<meta name="viewport" content="width=device-width; initial-scale=1.5" />
<style>
body {
font-family: Helvetica;
font-size: 14px;
margin: 0px;
}
h1 {
font-size: 1.8em;
background-color: grey;
color: white;
padding: 4px;
margin: 0px 0px 10px 0px;
width: 100%;
}
label {
font-size: 1.3em;
font-weight: bold;
margin: 4px;
}
select {
display: block;
width: 98%;
max-width: 496px;
font-family: inherit;
font-size: 1em;
margin-bottom: 10px;
margin-left: 4px;
}
input.slider {
max-width: 425px;
width: 100%;
}
.flexbox {
display: flex;
align-items: center;
width: 98%;
max-width: 500px;
}
</style>
</head>
<body>
<h1>BabelPod</h1>
<label>Input</label>
<select id="input" size="4">
<option value="void">None</option>
</select>
<label>Output</label>
<select id="output" size="4">
<option value="void">None</option>
</select>
<div class="flexbox">
<label>Volume</label>
<input type="range" min="1" max="100" value="50" class="slider" id="outputVolume" list="ticks">
<datalist id="ticks">
<option value="0" label="0%">
<option value="10">
<option value="20">
<option value="30">
<option value="40">
<option value="50" label="50%">
<option value="60">
<option value="70">
<option value="80">
<option value="90">
<option value="100" label="100%">
</datalist>
</div>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
var currentInput = "void";
var currentOutput = "void";
socket.on('switched_input', function(newInput){
console.log('switched_input', newInput);
if (currentInput !== newInput){
currentInput = newInput;
var inputEl = document.getElementById('input');
inputEl.value = newInput;
};
});
socket.on('switched_output', function(newOutput){
console.log('switched_output', newOutput);
if (currentOutput !== newOutput){
currentOutput = newOutput;
var outputEl = document.getElementById('output');
outputEl.value = newOutput;
}
});
socket.on('changed_output_volume', function(volume){
console.log('changed_output_volume', volume);
var outputVolumeEl = document.getElementById('outputVolume');
outputVolumeEl.value = volume;
});
socket.on('available_inputs', function(inputs){
console.log('available_inputs', inputs);
var inputEl = document.getElementById('input');
// remove current values
while (inputEl.firstChild) {
inputEl.removeChild(inputEl.firstChild);
}
for (var input of inputs){
var newOption = document.createElement('option');
newOption.innerText = input.name;
newOption.setAttribute('value', input.id);
inputEl.appendChild(newOption);
if (input.id === currentInput) {
inputEl.value = input.id;
}
}
});
socket.on('available_outputs', function(outputs){
console.log('available_outputs', outputs);
var outputEl = document.getElementById('output');
// remove current values
while (outputEl.firstChild) {
outputEl.removeChild(outputEl.firstChild);
}
for (var output of outputs){
var newOption = document.createElement('option');
newOption.innerText = output.name;
newOption.setAttribute('value', output.id);
outputEl.appendChild(newOption);
if (output.id === currentOutput) {
outputEl.value = output.id;
}
}
});
document.addEventListener('change', async ev => {
if(ev.target.id === 'input') {
socket.emit('switch_input', ev.target.value);
}
if(ev.target.id === 'output') {
socket.emit('switch_output', ev.target.value);
}
if(ev.target.id === 'outputVolume') {
socket.emit('change_output_volume', ev.target.value);
}
});
</script>
</body>
</html>