fixed API and stopping delay

This commit is contained in:
Marco Mooren
2026-05-27 12:54:56 +02:00
parent 470d4e8e76
commit 7b8d78ddaf
22 changed files with 495 additions and 98 deletions

22
server/companion.js Normal file
View File

@@ -0,0 +1,22 @@
// Bitfocus Companion integration.
// Keeps the `currentRadio` custom variable on the Companion instance
// in sync with the currently playing station.
//
// Set COMPANION_URL in your .env to override the default host/port.
// e.g. COMPANION_URL=http://10.99.0.110:8000
const BASE = process.env.COMPANION_URL || 'http://10.99.0.110:8000';
const VARIABLE_PATH = '/api/custom-variable/currentRadio/value';
/**
* Push a new value to Companion's `currentRadio` custom variable.
* @param {number|null} stationId Pass a numeric station id when playing;
* pass null/undefined to clear (stop/pause).
*/
export function notifyCompanion(stationId) {
const value = stationId != null ? String(stationId) : '';
const url = `${BASE}${VARIABLE_PATH}?value=${encodeURIComponent(value)}`;
fetch(url, { method: 'POST' }).catch((err) => {
console.warn('[companion] notify failed:', err.message);
});
}