Skip to main content

Live Ingest — mobile WebRTC "Go Live"

Listeners can take the whole channel live from a phone browser. The chain is:

The WHIP/WHEP server (whip_server.py)

Python (aiohttp + aiortc) service, venv whip-venv/, port 8089, launched by start_whip.sh and kept alive by watch_whip.sh (cron */5).

RouteMethodPurpose
/whip-infoGETSTUN/TURN servers + live flag (used by LiveManager to probe)
/whip/POSTCreate an ingest (browser posts an audio SDP offer)
/whip/{id}PATCHDTLS renegotiation / ICE restart
/whip/{id}DELETETear down an ingest
/whep/GETMinimal WHEP echo (subscribe back to the ingest)
/go-liveGETServes the mobile "Go Live" page

Key details:

  • TURN credentials are minted client-side with HMAC-SHA1 using the coturn static-auth-secret pattern (turn.mediahubnetwork.net:3478, +5349 TLS, +tcp). The secret is read from TURN_SECRET env.
  • Audio only: video tracks are ignored. Audio frames are decoded and written to the FIFO as raw PCM (16-bit LE, 48 kHz, mono).
  • The FIFO writer opens in a background task so the server starts even before ffmpeg (the reader) is attached.
  • Engine registration: when the first audio track arrives, the server re-registers the source with the Windows engine (POST http://10.40.3.174:5000/api/station/live/register) with url="pipe:/home/sms/radio/whep_live.wav", ingest="webrtc". Re-registering every time is safe because LiveManager dedupes pipe/WebRTC sources on url+title+ingest — it survives engine restarts too.
  • When the last track ends, it stops the engine live state and kills the harbor reader.

The go-live.html page

whip_server.py serves /go-live from /home/sms/radio/go-live.html. On mobile:

  1. Fetches /whip-info for STUN/TURN.
  2. getUserMedia({ audio }) (echo cancellation + noise suppression on).
  3. Creates a WebRTC peer with max-bundle, a ctrl data channel, and a live level meter.
  4. POSTs the audio offer SDP (plain text) to /whip/, applies the answer.
  5. Stop broadcasting closes the peer and tears everything down.

Where this meets LiveManager

The WHIP ingest is just another entry in the LiveManager ranking (votes + listeners + freshness). When the engine is asked to go live, _probeHarbor checks http://10.10.8.230:8089/whip-info (live: true) to confirm the remote feed is actually flowing before declaring the channel live. See Live Manager.

See also