Files
kuentagym/docs/RADIO.md
T
dsantillan a3e13df279
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
La radio no se dibuja para un invitado ni contra un servidor viejo
Las emisoras las busca el servidor, así que dos situaciones que no son bugs se veían
como uno: sin sesión (el modo invitado nunca habla con la api) y una api más vieja
que la app —se despliegan por separado, y un deploy que reconstruyó `web` y no el
contenedor de la api es una pantalla cuyos pedidos fallan todos.

Ahora la sección lo dice y no pide nada en ninguno de los dos casos. Para poder
distinguirlos, `radio` entra en `features` (`GET /api/config`), que es exactamente
para lo que existe esa lista, y queda documentado en la especificación junto con
`features` entero —que hasta ahora no estaba.

De paso: la fila y la barra caen al marcador de posición cuando el logo o la portada
no cargan, que es el caso de una parte del directorio.
2026-09-23 20:45:21 -04:00

7.7 KiB

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, 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, and it only affects the packaged builds, not the PWA.

When the radio isn't there

Two situations look like a bug and are not, so the screen says which one it is instead of showing a request that failed:

  • Nobody is signed in. Guest mode is client-side only and never talks to the api, and the station list is the server's job — so the section says the radio needs a profile. No request is made.
  • The api is older than the app. They ship separately: web is rebuilt from source on every deploy, while the api's code lives inside its container, so a deploy can leave a new screen on top of an api that has never heard of /api/radio. GET /api/config lists what that api can do (features, and this build answers radio), so "old server" is detectable — the section says so, quietly, rather than offering chips that 404. The same list is what keeps the Salud screen from blaming the data when it is really the container.

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 — listener-supported, commercial-free; the channels used here are theirs, and their stream URLs are resolved through their own public .pls.
  • Radio Paradise — listener-supported, and the now_playing endpoint that gives the bar its cover art.
  • radio-browser — 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.