Skip to main content

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 (chained setTimeout, first run 10 min after boot), and the checkPoolHealth() self-healing monitor (every POOL_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) runs daypartChanged() and calls rotateBatch() 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-genscheduleBulletinAutoGen() builds a spoken Arabic NEWS bulletin at boot +30s and every BULLETIN_HOURS (default 1h) and resyncs the rotation (see Bulletin engine).
  • ReactionsGET/POST /api/reactions tracks station-wide emoji counts, persisted to models/reactions.json; the chat-server proxy forwards it for the public page + app.
  • Hosts the imaging generators/api/imaging/* (sweepers/IDs/stingers via imaging-engine.js) and the fun-jingles.js CLI; every generator resyncs the scheduler and pushes the rotation.
  • Supervised by the LOKLOK_ServerGuard SYSTEM scheduled task (2-minute ticks) — node server.js is relaunched automatically if nothing listens on :5000, surviving console close and logoff.

Modules mounted at boot

ModuleFileMounted routesPurpose
Social platformsocial-platform.js/api/social/*Listener-submitted audio → validate/R128 → ranked scheduler overlay
Live managerlive-manager.js/api/station/live/*Rank live streams, restream the winner into the remote harbor :8006
Station controlstation-control.js/api/station/*Full agent control: rotation, mood, genres, dayparts, singers, content
MCP radiomcp-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

PackageUse
express (v5)HTTP server & routing
socket.ioRealtime events
yt-dlp-execDownload bridging
fluent-ffmpegAudio processing
synapticNeural scheduler
node-cronScheduled jobs
chokidarFile watching
web-pushPush notifications
@google/generative-aiGemini integration
uuidIdentifiers

Dev vs. prod

  • Dev: runs on port 5000 on 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.