Server (server.js)
server.js is the control plane — the HTTP + Socket.io server that every web
frontend connects to. It runs on the local node and is the public-facing service
at api.mediahubnetwork.net.
What it does
- Serves the classic web frontends and static assets.
- Socket.io — realtime channel for now-playing, chat, studio injection, voting, and system events.
- HTTP API — programmatic endpoints for the frontends and tooling.
- Integration glue — WhatsApp and web-push notifications, vote handling, and relays to the broadcast engine.
- Runs the hands-free content engine: hosts
content-pipeline.js, the 6-hour auto-refresh (chainedsetTimeout, first run 10 min after boot), and thecheckPoolHealth()self-healing monitor (everyPOOL_CHECK_MINUTES) that tops any deck that dropped below its floor back up from the archive. - Daypart watchdog — a 60-second probe (
[M3U] Daypart watchdog fired) runsdaypartChanged()and callsrotateBatch()within a minute of any daypart boundary crossing, so a rotation built under one profile can never keep airing into the next (see Daypart-stamped rotation). - Hourly bulletin auto-gen —
scheduleBulletinAutoGen()builds a spoken Arabic NEWS bulletin at boot +30s and everyBULLETIN_HOURS(default 1h) and resyncs the rotation (see Bulletin engine). - Reactions —
GET/POST /api/reactionstracks station-wide emoji counts, persisted tomodels/reactions.json; the chat-server proxy forwards it for the public page + app. - Hosts the imaging generators —
/api/imaging/*(sweepers/IDs/stingers viaimaging-engine.js) and thefun-jingles.jsCLI; every generator resyncs the scheduler and pushes the rotation. - Supervised by the
LOKLOK_ServerGuardSYSTEM scheduled task (2-minute ticks) —node server.jsis relaunched automatically if nothing listens on:5000, surviving console close and logoff.
Modules mounted at boot
| Module | File | Mounted routes | Purpose |
|---|---|---|---|
| Social platform | social-platform.js | /api/social/* | Listener-submitted audio → validate/R128 → ranked scheduler overlay |
| Live manager | live-manager.js | /api/station/live/* | Rank live streams, restream the winner into the remote harbor :8006 |
| Station control | station-control.js | /api/station/* | Full agent control: rotation, mood, genres, dayparts, singers, content |
| MCP radio | mcp-radio.js | — (stdio server) | Model Context Protocol server for any AI agent over /api/station/* |
Persisted settings live in station-config.json (via station-config.js) so
scheduler overrides, singer catalogs, queries, and the live stream registry
survive restarts.
Dependencies used
| Package | Use |
|---|---|
express (v5) | HTTP server & routing |
socket.io | Realtime events |
yt-dlp-exec | Download bridging |
fluent-ffmpeg | Audio processing |
synaptic | Neural scheduler |
node-cron | Scheduled jobs |
chokidar | File watching |
web-push | Push notifications |
@google/generative-ai | Gemini integration |
uuid | Identifiers |
Dev vs. prod
- Dev: runs on port
5000on the local node. - Prod: exposed publicly via
api.mediahubnetwork.net.
The frontends expect the Socket.io server at the same origin they are served from; see Web Frontends for how each page consumes events.
Related
- Socket events — every event name and payload.
- API endpoints — the HTTP surface.
- Station control — the
/api/station/*agent API. - Live manager — channel-live ranking + restream.
- Notifications — WhatsApp + push.
- Radio engine — the broadcast bridge it talks to.