Radio: estaciones en vivo mientras entrenás
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Música tiene una sección **Radio**: estaciones en vivo por género (Workout/Rave, Techno/House, R&B/Soul, Latina, Hip-Hop, Reggae, Chill, Jazz, Rock, Electrónica), sin publicidad primero —SomaFM y Radio Paradise— y detrás el directorio público de radio-browser. Nada de esto suma dependencias: la lista la arma api/radio.js. Tres decisiones que no se ven en la pantalla y son las que hacen que funcione: - **El audio no pasa por el servidor.** La api entrega la lista y después no ve un byte: el teléfono habla con la estación. Sin ancho de banda, sin disco, sin copias. - **La URL del stream viene resuelta en la lista**, porque iOS sólo deja arrancar audio dentro del gesto del toque: cualquier cosa asíncrona entre el dedo y el play() es un botón que no hace nada, sin error en ninguna parte. - **El `<audio>` vive fuera de React** (lib/radio-player.js): un elemento dentro de un componente se desmonta con él, y eso es la música cortándose al cambiar de pantalla — justo lo que no puede pasar en medio de una serie. Barra arriba de la barra de pestañas con pausa (deja la estación donde estaba) y parar; Media Session pone estación, pista y controles en la pantalla bloqueada, y las canciones siguen con el teléfono en el bolsillo. Qué suena lo dicen SomaFM y Radio Paradise y nadie más: en el resto la barra muestra la estación en vez de inventar una pista. api/test/server-radio.test.js guarda las dos puertas (sesión obligatoria, `src`+`id` reconstruidos en vez de confiar en el objeto del cliente); RadioBar.test.jsx y el caso de la fila en Music.test.jsx guardan lo demás. También: radio.js en el COPY del Dockerfile —importar un archivo que no está copiado es un contenedor que arranca en ERR_MODULE_NOT_FOUND—, /api/radio y /api/radio/now (con /api/music/lookup, que faltaba) en la especificación, y docs/RADIO.md.
This commit is contained in:
1 parent
e1d28f971d
commit
48cf976635
22 files changed
+1662
-15
No files matched your search
+118
@@ -0,0 +1,118 @@
|
||||
# Radio
|
||||
|
||||
Live stations, for the hour you're in the gym. Open **Música → Radio**, pick a genre, press a
|
||||
station, and it plays while you train — across screens, with the screen locked and the phone in your
|
||||
pocket.
|
||||
|
||||
It is radio, not a music library: you don't pick the song, and nobody has to. That is the whole
|
||||
reason it exists next to the Apple Music playlists on the same screen — one is what you listen to on
|
||||
purpose, the other is what plays while you count reps.
|
||||
|
||||
## What is playing
|
||||
|
||||
Chips pick a genre. Ten of them: **Workout / Rave, Techno / House, R&B / Soul, Latina, Hip-Hop,
|
||||
Reggae, Chill, Jazz, Rock, Electrónica**. Each one is a list of **SomaFM** channels (curated by hand
|
||||
— a machine cannot know that *Seven Inch Soul* is the R&B one), the **Radio Paradise** mixes that
|
||||
fit, and the **radio-browser** tags that fill in the rest.
|
||||
|
||||
The ad-free ones come first in every genre: SomaFM is a listener-supported, commercial-free network
|
||||
of 46 channels, and Radio Paradise is four hand-mixed ones. Both publish their stream as a playlist
|
||||
`.pls`, which `api/radio.js` reads rather than guessing a bitrate into a URL — that is what makes the
|
||||
same code work for every channel, including the ones added after this was written.
|
||||
|
||||
Behind them is [radio-browser](https://www.radio-browser.info), a public, community-run directory of
|
||||
tens of thousands of stations. It is filtered hard: **HTTPS only** (a page served over HTTPS cannot
|
||||
play an `http://` stream at all — the browser blocks it as mixed content, so offering one would be
|
||||
offering a station that silently does nothing), `hidebroken=true`, ordered by how many people
|
||||
actually listen to it.
|
||||
|
||||
## Where the audio goes
|
||||
|
||||
**From the station to your phone. Never through this server.**
|
||||
|
||||
The api hands out the list — each station with its stream URL already resolved — and after that it
|
||||
sees nothing: no traffic, no disk, no byte of audio. On a small VPS that is the difference between a
|
||||
feature and a bandwidth bill, and it is also why nothing here ever downloads, records or keeps a
|
||||
copy of anything.
|
||||
|
||||
Two kinds of request *do* reach out from the server, and both are for the list and its caption:
|
||||
|
||||
| Call | To | Why |
|
||||
|---|---|---|
|
||||
| channel list + `.pls` | somafm.com | to resolve a channel into a stream URL |
|
||||
| `bytagexact` search | all.api.radio-browser.info | the directory's stations per genre |
|
||||
| `now_playing` | api.radioparadise.com | the cover and the track for the bar |
|
||||
|
||||
All of them are cached for ten minutes, so opening the screen twice is one round of requests. Every
|
||||
outgoing call goes through one function with a **host allowlist** (`RADIO_HOSTS`) — the api container
|
||||
sits on the owner's own network, so the set of hosts it will talk to is a security boundary, not a
|
||||
convenience.
|
||||
|
||||
So the server does see something: which genre chip was pressed, and — only for the two sources that
|
||||
publish what they play — which station the bar is asking about, once every 45 seconds while it
|
||||
plays. Nothing is written down: those are requests, not records, and there is no table, log or file
|
||||
where listening would accumulate. (The request log in the admin dashboard is the activity log, and it
|
||||
carries sign-ins and admin actions, not this.)
|
||||
|
||||
## Why the stream URL arrives in the list
|
||||
|
||||
iOS only lets audio start **inside the gesture** that asked for it. Anything asynchronous between the
|
||||
finger and the `play()` — a `fetch`, a state update, a re-render — is a press that does nothing, with
|
||||
no error anywhere. So the list arrives complete: by the time a station has been drawn on the screen,
|
||||
its stream URL is already in the object the row holds, and the press calls `play()` synchronously.
|
||||
|
||||
The `<audio>` element lives in `frontend/src/lib/radio-player.js`, **outside React**, as a
|
||||
module-level singleton. An element owned by a component is unmounted when the component is, which is
|
||||
how a player stops the moment you change screens — and changing screens mid-session is the normal
|
||||
case here, not the edge case.
|
||||
|
||||
## The bar, and the lock screen
|
||||
|
||||
While something is playing, a bar sits above the tab bar (the same place and the same glass as the
|
||||
rest timer, on purpose — a second floating bar with its own look reads as a second app):
|
||||
|
||||
- the station, and what it says it is playing
|
||||
- **pause** — keeps the station, so the same one is still there after the rest
|
||||
- **stop** — takes the bar and the station away
|
||||
|
||||
**Media Session** is what puts the station, the track and the controls on the lock screen and in the
|
||||
car, and it is what makes "screen off, phone in pocket" work: the audio is played by the browser
|
||||
underneath the page, not by the page's timers. Those timers — the 45-second poll for what is playing —
|
||||
are suspended while the screen is locked, so the caption simply stops moving until you look again. It
|
||||
is a caption; the music is unaffected.
|
||||
|
||||
On the **native Android/iOS shells** the same rules apply, with one addition: keeping audio alive
|
||||
under a locked screen in a WebView needs `UIBackgroundModes: audio` (iOS) and a foreground service
|
||||
(Android) in the shell's own config. Neither is set today — that is described in
|
||||
[docs/MOBILE.md](docs/MOBILE.md), and it only affects the packaged builds, not the PWA.
|
||||
|
||||
## Saving a station
|
||||
|
||||
The star on a row saves the station to your profile (`music.stations`), and saved ones are pinned
|
||||
above the list. They are stored with the rest of your profile's client state — they contain nothing
|
||||
about your listening, just the station you liked.
|
||||
|
||||
## What this deliberately is not
|
||||
|
||||
- **Not a YouTube/Spotify front end.** Ripping streams or playing someone else's catalogue through
|
||||
an unofficial API breaks those services' terms and this project's licence is AGPL; the honest
|
||||
version of "radio" is radio.
|
||||
- **Not a proxy.** No endpoint here relays audio. Every `/api/radio` response is JSON, and the
|
||||
routes are session-gated so the list cannot be borrowed by somebody else's page.
|
||||
- **Not a downloader.** There is no record button and no cache of audio anywhere.
|
||||
- **Not HLS.** Stations that only stream HLS are skipped: playing them in a browser needs `hls.js`,
|
||||
and a dependency-light project does not take a media stack on for a feature whose whole point is
|
||||
that it makes no new dependency necessary.
|
||||
|
||||
## Credits and licences
|
||||
|
||||
- [SomaFM](https://somafm.com) — listener-supported, commercial-free; the channels used here are
|
||||
theirs, and their stream URLs are resolved through their own public `.pls`.
|
||||
- [Radio Paradise](https://radioparadise.com) — listener-supported, and the `now_playing` endpoint
|
||||
that gives the bar its cover art.
|
||||
- [radio-browser](https://www.radio-browser.info) — the directory itself is **AGPL-3.0**, same
|
||||
family as this project, and it is the reason the long tail of stations is reachable at all.
|
||||
|
||||
These are third-party services this app does not control: a station that goes off the air disappears
|
||||
from the list on the next refresh, and a genre that comes back thin is the directory having a bad
|
||||
day, not the app.
|
||||
Reference in new issue
Block a user