fixed API and stopping delay
This commit is contained in:
@@ -27,6 +27,7 @@ import {
|
||||
getRoomState, setRoomState
|
||||
} from './rooms.js';
|
||||
import { getStation } from './stations.js';
|
||||
import { notifyCompanion } from './companion.js';
|
||||
|
||||
const DEBUG = !!process.env.ORADIO_DEBUG_SYNC;
|
||||
function dlog(...args) { if (DEBUG) console.log('[ws]', ...args); }
|
||||
@@ -124,6 +125,7 @@ export function dispatchRoomCommand(room, msg, { except = null } = {}) {
|
||||
|
||||
if (msg.action === 'play' && Number.isFinite(msg.stationId)) {
|
||||
const newStation = Number(msg.stationId);
|
||||
notifyCompanion(newStation);
|
||||
const sameAndPlaying = cur.playing && cur.station_id === newStation && cur.started_at;
|
||||
const patch = { station_id: newStation, playing: true };
|
||||
if (!displayPresent) {
|
||||
@@ -134,8 +136,10 @@ export function dispatchRoomCommand(room, msg, { except = null } = {}) {
|
||||
setRoomState(room.id, patch);
|
||||
} else if (msg.action === 'pause') {
|
||||
setRoomState(room.id, { playing: false });
|
||||
notifyCompanion(null);
|
||||
} else if (msg.action === 'stop') {
|
||||
setRoomState(room.id, { playing: false, started_at: null });
|
||||
notifyCompanion(null);
|
||||
} else if (msg.action === 'volume' && typeof msg.value === 'number') {
|
||||
setRoomState(room.id, { volume: Math.max(0, Math.min(1, msg.value)) });
|
||||
} else {
|
||||
@@ -291,6 +295,10 @@ function handleClientMessage(ws, msg) {
|
||||
const next = setRoomState(ws.room.id, patch);
|
||||
// Station change invalidates any cached master position.
|
||||
if (prev.station_id !== next.station_id) lastSyncPos.delete(slug);
|
||||
// Notify Companion whenever the effective now-playing state changes.
|
||||
if (prev.station_id !== next.station_id || prev.playing !== next.playing) {
|
||||
notifyCompanion(next.playing && next.station_id ? next.station_id : null);
|
||||
}
|
||||
const station = next.station_id ? getStation(next.station_id) : null;
|
||||
broadcastToRoom(slug, { type: 'state', ...next, station, server_now: Date.now() });
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user