refactor(radio): separate directory and playback components

This commit is contained in:
Sameh Khamis committed 2026-09-13 17:28:35 -07:00
1 parent ba7fda74d7
commit 41b3cc1705
30 files changed
+4488 -2795

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
import { DIRECTORY_ENDPOINT, RADIO_UUID_RE } from './policy.js';
/** Supply directory metadata and click reporting; audio stays with the broadcaster. */
export function createRadioSource({
fetchImpl = (...args) => globalThis.fetch(...args),
} = {}) {
return {
async getDirectory({ signal } = {}) {
signal?.throwIfAborted();
const response = await fetchImpl(DIRECTORY_ENDPOINT, { signal });
if (!response.ok)
throw new Error(`Radio directory returned ${response.status}`);
const body = await response.json();
signal?.throwIfAborted();
return body;
},
async recordClick(id, { signal } = {}) {
if (typeof id !== 'string' || !RADIO_UUID_RE.test(id))
throw new Error('Invalid radio station id');
signal?.throwIfAborted();
const response = await fetchImpl(
`/api/radio/click/${encodeURIComponent(id)}`,
{
method: 'POST',
signal,
},
);
signal?.throwIfAborted();
if (!response.ok)
throw new Error(`Radio click returned ${response.status}`);
},
};
}