Repository navigation
Expand file tree
/
Copy pathcontent.php
More file actions
340 lines (315 loc) · 11.9 KB
/
Copy pathcontent.php
File metadata and controls
340 lines (315 loc) · 11.9 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<?php
/*
* Stream Volume Faders - main control page.
*
* One fader per fppd audio stream:
* - Slot 1 ("Master / Primary") always controls the system's overall
* output volume via the core api/system/volume endpoint.
* - Slots 2-5 map to fppd's StreamSlotManager ("Set Slot Volume" /
* "Media Slot Status" commands), which only exist on GStreamer-backed
* builds. The inline script below probes for them at load and hides
* that row group if the build doesn't support them.
*
* The control script is inlined here (rather than a separate js/*.js file)
* deliberately: FPP's plugin.php serves plugin JS/CSS through its generic
* ?file= route, which never gets the ?ref=<filemtime> cache-buster FPP's
* own bundled assets use - so Apache's "cache everything for a year,
* immutable" default (etc/apache2.site) sticks a plugin script's very
* first version in every visitor's browser forever, immune to reloads.
* This page (?page=content.php) isn't subject to that, so the same pattern
* FPP's own live-control admin pages use (pipewire-audio.php,
* pipewire-routing-matrix.php) - inline <script>, not a cached asset -
* avoids it here too.
*/
?>
<p>
Adjust the volume of each active fppd media stream. The <strong>Master / Primary</strong>
fader controls the system's overall output volume. Stream Slots 2-5 correspond to
additional simultaneous streams started via a <code>Play Media</code> command or a
playlist entry configured with a non-default stream slot.
</p>
<div class="table-responsive">
<table class="table align-middle">
<thead>
<tr>
<th>Stream</th>
<th class="ps-4">Status</th>
<th class="ps-4">Volume</th>
</tr>
</thead>
<tbody>
<tr id="streamVolumeRow_1">
<td class="fw-semibold py-3">Master / Primary</td>
<td class="py-3 ps-4"><span id="streamVolumeStatus_1" class="badge text-bg-success">Active</span></td>
<td class="py-3 ps-4">
<div class="d-flex align-items-center gap-2">
<button type="button" class="btn btn-sm btn-outline-secondary"
id="streamVolumeMuteBtn_1" onclick="StreamVolumeMuteToggle(1)" title="Mute">
<i class="fas fa-volume-up" id="streamVolumeMuteIcon_1"></i>
</button>
<input type="range" class="form-range" min="0" max="100" value="70"
id="streamVolumeSlider_1"
oninput="StreamVolumeSliderInput(1)"
onchange="StreamVolumeSliderChange(1)">
<span id="streamVolumeLabel_1" class="text-nowrap">70%</span>
</div>
</td>
</tr>
</tbody>
<tbody id="streamVolumeExtraSlots">
<?php for ($slot = 2; $slot <= 5; $slot++): ?>
<tr id="streamVolumeRow_<?= $slot ?>">
<td class="fw-semibold py-3">Stream Slot <?= $slot ?></td>
<td class="py-3 ps-4"><span id="streamVolumeStatus_<?= $slot ?>" class="badge text-bg-secondary">Idle</span></td>
<td class="py-3 ps-4">
<div class="d-flex align-items-center gap-2">
<button type="button" class="btn btn-sm btn-outline-secondary"
id="streamVolumeMuteBtn_<?= $slot ?>" onclick="StreamVolumeMuteToggle(<?= $slot ?>)" title="Mute">
<i class="fas fa-volume-up" id="streamVolumeMuteIcon_<?= $slot ?>"></i>
</button>
<input type="range" class="form-range" min="0" max="100" value="70"
id="streamVolumeSlider_<?= $slot ?>"
oninput="StreamVolumeSliderInput(<?= $slot ?>)"
onchange="StreamVolumeSliderChange(<?= $slot ?>)">
<span id="streamVolumeLabel_<?= $slot ?>" class="text-nowrap">70%</span>
</div>
</td>
</tr>
<?php endfor; ?>
</tbody>
</table>
</div>
<div id="streamVolumeNoExtraSlots" class="alert alert-secondary d-none">
Stream Slots 2-5 are not available on this build of fppd (requires a GStreamer-enabled
build). Only the Master / Primary fader above is usable.
</div>
<script type="text/javascript">
(function () {
'use strict';
var POLL_INTERVAL_MS = 2000;
var SLIDER_DEBOUNCE_MS = 150;
var MAX_SLOT = 5;
var STORAGE_PREFIX = 'fppStreamVolume_slot_';
var PREMUTE_STORAGE_PREFIX = 'fppStreamVolume_premute_';
var extraSlotsAvailable = true; // optimistic until the first probe says otherwise
var slotActive = {};
var sliderDragging = {};
var debounceTimers = {};
function loadStoredVolume(slot) {
try {
var v = window.localStorage.getItem(STORAGE_PREFIX + slot);
if (v !== null) {
var n = parseInt(v, 10);
if (!isNaN(n)) {
return Math.min(100, Math.max(0, n));
}
}
} catch (e) {
// localStorage unavailable (private browsing, etc) - fall through to default
}
return 70;
}
function storeVolume(slot, value) {
try {
window.localStorage.setItem(STORAGE_PREFIX + slot, value);
} catch (e) {
// ignore - nothing to persist to, slider still works for this session
}
}
// Remembers the last non-zero volume seen for a slot, so the Mute button
// has something sensible to restore to on Unmute.
function loadPreMuteVolume(slot) {
try {
var v = window.localStorage.getItem(PREMUTE_STORAGE_PREFIX + slot);
if (v !== null) {
var n = parseInt(v, 10);
if (!isNaN(n) && n > 0) {
return Math.min(100, n);
}
}
} catch (e) {
// localStorage unavailable - fall through to default
}
return 70;
}
function storePreMuteVolume(slot, value) {
if (value <= 0) {
return;
}
try {
window.localStorage.setItem(PREMUTE_STORAGE_PREFIX + slot, value);
} catch (e) {
// ignore
}
}
function updateMuteButton(slot, value) {
var btn = document.getElementById('streamVolumeMuteBtn_' + slot);
var icon = document.getElementById('streamVolumeMuteIcon_' + slot);
if (!btn || !icon) {
return;
}
var muted = value <= 0;
btn.className = 'btn btn-sm ' + (muted ? 'btn-danger' : 'btn-outline-secondary');
btn.title = muted ? 'Unmute' : 'Mute';
icon.className = 'fas ' + (muted ? 'fa-volume-mute' : 'fa-volume-up');
}
function setSliderValue(slot, value) {
var input = document.getElementById('streamVolumeSlider_' + slot);
var label = document.getElementById('streamVolumeLabel_' + slot);
if (input) {
input.value = value;
}
if (label) {
label.textContent = value + '%';
}
updateMuteButton(slot, value);
}
function setSlotStatus(slot, active, filename) {
slotActive[slot] = active;
var badge = document.getElementById('streamVolumeStatus_' + slot);
if (!badge) {
return;
}
if (active) {
badge.textContent = filename ? filename : 'Active';
badge.className = 'badge text-bg-success';
} else {
badge.textContent = 'Idle';
badge.className = 'badge text-bg-secondary';
}
}
function applySlotVolume(slot, value) {
if (slot === 1) {
fetch('api/system/volume', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ volume: value })
}).catch(function () {
// transient network error - next poll/drag will resync
});
return;
}
// GET form of api/command/{command}/{args...}; a non-2xx response just
// means the slot is currently idle (Set Slot Volume no-ops on it) -
// the stored value gets pushed automatically once it goes active.
fetch('api/command/Set%20Slot%20Volume/' + slot + '/' + value).catch(function () {
// transient network error - ignore
});
}
function onSliderInput(slot) {
var input = document.getElementById('streamVolumeSlider_' + slot);
var value = parseInt(input.value, 10);
setSliderValue(slot, value);
storeVolume(slot, value);
storePreMuteVolume(slot, value);
sliderDragging[slot] = true;
if (debounceTimers[slot]) {
clearTimeout(debounceTimers[slot]);
}
debounceTimers[slot] = setTimeout(function () {
applySlotVolume(slot, value);
}, SLIDER_DEBOUNCE_MS);
}
function onSliderChange(slot) {
var input = document.getElementById('streamVolumeSlider_' + slot);
var value = parseInt(input.value, 10);
if (debounceTimers[slot]) {
clearTimeout(debounceTimers[slot]);
}
applySlotVolume(slot, value);
// Give the just-sent request a moment before letting the poller
// overwrite the slider again.
setTimeout(function () {
sliderDragging[slot] = false;
}, SLIDER_DEBOUNCE_MS + 50);
}
function onMuteToggle(slot) {
var input = document.getElementById('streamVolumeSlider_' + slot);
var current = parseInt(input.value, 10);
var newValue;
if (current > 0) {
storePreMuteVolume(slot, current);
newValue = 0;
} else {
newValue = loadPreMuteVolume(slot);
}
setSliderValue(slot, newValue);
storeVolume(slot, newValue);
applySlotVolume(slot, newValue);
}
function refreshMasterVolume() {
if (sliderDragging[1]) {
return;
}
fetch('api/system/volume')
.then(function (r) {
return r.json();
})
.then(function (data) {
if (typeof data.volume === 'number' && !sliderDragging[1]) {
setSliderValue(1, data.volume);
}
})
.catch(function () {
// fppd not reachable right now - leave the last known value showing
});
}
function showExtraSlots(available) {
if (available === extraSlotsAvailable) {
return;
}
extraSlotsAvailable = available;
var group = document.getElementById('streamVolumeExtraSlots');
var notice = document.getElementById('streamVolumeNoExtraSlots');
if (group) {
group.classList.toggle('d-none', !available);
}
if (notice) {
notice.classList.toggle('d-none', available);
}
}
function refreshSlotStatuses() {
fetch('api/command/Media%20Slot%20Status')
.then(function (resp) {
if (!resp.ok) {
throw new Error('Media Slot Status not available');
}
return resp.text();
})
.then(function (text) {
showExtraSlots(true);
var slots = JSON.parse(text);
slots.forEach(function (s) {
var slot = s.slot;
if (slot === 1 || slot > MAX_SLOT) {
return;
}
var wasActive = !!slotActive[slot];
var isActive = s.status === 'playing';
setSlotStatus(slot, isActive, s.mediaFilename);
if (isActive && !wasActive && !sliderDragging[slot]) {
applySlotVolume(slot, loadStoredVolume(slot));
}
});
})
.catch(function () {
showExtraSlots(false);
});
}
function poll() {
refreshMasterVolume();
refreshSlotStatuses();
}
function init() {
for (var slot = 2; slot <= MAX_SLOT; slot++) {
setSliderValue(slot, loadStoredVolume(slot));
}
poll();
setInterval(poll, POLL_INTERVAL_MS);
}
init();
window.StreamVolumeSliderInput = onSliderInput;
window.StreamVolumeSliderChange = onSliderChange;
window.StreamVolumeMuteToggle = onMuteToggle;
})();
</script>