fixed API and stopping delay
This commit is contained in:
22
server/companion.js
Normal file
22
server/companion.js
Normal 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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user