@@ -61,6 +61,7 @@ els('.room').forEach((node) => {
|
||||
toggle: el('[data-role="group"]', node),
|
||||
toggleLabel: el('[data-role="group-label"]', node),
|
||||
play: el('[data-role="play"]', node),
|
||||
next: el('[data-role="next"]', node),
|
||||
steps: els('.step', node),
|
||||
volume: null,
|
||||
playState: null,
|
||||
@@ -80,6 +81,7 @@ els('.room').forEach((node) => {
|
||||
|
||||
room.toggle.addEventListener('click', () => setGrouped(key, !room.grouped));
|
||||
room.play.addEventListener('click', () => togglePlay(key));
|
||||
room.next.addEventListener('click', () => skipTrack(key));
|
||||
});
|
||||
|
||||
function paintRoom(room) {
|
||||
@@ -93,6 +95,12 @@ function paintRoom(room) {
|
||||
room.play.disabled = !room.available || room.playState === null;
|
||||
room.play.setAttribute(
|
||||
'aria-label', `${room.node.querySelector('h2').textContent}: ${playing ? 'pause' : 'play'}`);
|
||||
// Grouped, transport belongs to the AVR's card, not this one -- pressing
|
||||
// either here would still work (it shares the group's transport) but
|
||||
// only invites confusion about which card is actually in charge of it.
|
||||
room.play.hidden = room.grouped;
|
||||
room.next.hidden = !playing || room.grouped;
|
||||
room.next.disabled = !room.available;
|
||||
|
||||
room.toggle.disabled = !room.available;
|
||||
room.toggle.classList.toggle('busy', room.busy);
|
||||
@@ -225,6 +233,18 @@ async function togglePlay(key) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Fire-and-forget: the queue's next track has no local state to reconcile,
|
||||
so there is nothing to optimistically flip the way play/pause does. */
|
||||
async function skipTrack(key) {
|
||||
const room = rooms[key];
|
||||
if (!room.available) return;
|
||||
try {
|
||||
await api('/api/skip', { target: key, direction: 'next' });
|
||||
} catch (error) {
|
||||
toast(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
function applyJoined(joined) {
|
||||
Object.values(rooms).forEach((room) => {
|
||||
room.grouped = joined.includes(room.key);
|
||||
|
||||
Reference in New Issue
Block a user