Skip to main content

Channel Status

Overview

The channel status module tracks live stream status per platform for each account. It stores whether a channel is online, along with metadata such as stream title, category, viewer count, and stream start time. Status is updated by platform workers (Twitch, YouTube, Kick, Trovo) and includes a manual Spotify connect feature for controlling the Spotify polling worker independently of stream status.

Architecture

Platform Workers (Twitch/YouTube/Kick/Trovo)
|
+--> db::channel_status::set_online / set_offline / update_stream_data
|
v
channel_status table (PostgreSQL)
^
|
Dashboard UI
|
v
Next.js API Proxy
|
v
GraphQL (ChannelStatusQuery / ChannelStatusMutation)
|
+--> db::channel_status::get_status
+--> services::channel_status (manual connect via Redis)

Status Updates

Platform workers poll for stream status changes and update the database:

  • Going online -- set_online() upserts a row with is_online = TRUE and metadata (title, category, viewer count, start time).
  • Going offline -- set_offline() sets is_online = FALSE and clears started_at.
  • Data updates -- update_stream_data() updates viewer count, title, and category for channels that are already online.

Spotify Manual Connect

The Spotify worker normally polls only when a channel is online. The manual connect feature allows users to start Spotify polling independently, using a Redis key with a 30-minute TTL. This is useful for pre-stream setup or listening sessions without going live.

  • Start -- Sets a Redis key and publishes a synthetic status change event via Redis pub/sub.
  • Stop -- Deletes the Redis key and publishes a status change event.
  • Query -- Returns whether manual connect is active and the remaining seconds.

API

GraphQL Queries

QueryArgsReturnsPermission
channelStatus--[ChannelStatus]spotify:read
spotifyManualStatus--SpotifyManualStatusspotify:read
  • channelStatus returns all platform statuses for the active account.
  • spotifyManualStatus checks the Redis TTL key and returns active status with remaining seconds.

GraphQL Mutations

MutationArgsReturnsPermission
startSpotifyManual--SpotifyManualStatusspotify:worker
stopSpotifyManual--Booleanspotify:worker

REST Endpoints

All paths live under /v1.

MethodPathPermissionDescription
GET/v1/channel-statusspotify:readAll platform statuses for the active account
GET/v1/spotify/manual-connectspotify:readManual-connect status + remaining seconds
POST/v1/spotify/manual-connectspotify:workerStart manual Spotify polling (30 min TTL)
DELETE/v1/spotify/manual-connectspotify:workerStop manual Spotify polling

GraphQL Types

type ChannelStatus {
platform: String!
isOnline: Boolean!
streamTitle: String
category: String
viewerCount: Int
startedAt: DateTime
updatedAt: DateTime!
}

type SpotifyManualStatus {
active: Boolean!
remainingSeconds: Int
}

Permissions

PermissionDescription
spotify:readView channel status and Spotify manual connect status
spotify:workerStart/stop Spotify manual connect

Included in: Owner, Administrator, Moderator roles have spotify:read. Owner and Administrator have spotify:worker.

Database

Table: channel_status

ColumnTypeDescription
account_idUUID (PK, FK)Account ID
platformTEXT (PK)Platform identifier
is_onlineBOOLEANWhether the channel is currently live
stream_titleTEXTCurrent stream title
categoryTEXTCurrent stream category/game
viewer_countINTCurrent viewer count
started_atTIMESTAMPTZWhen the stream started
updated_atTIMESTAMPTZLast status update

Primary key: (account_id, platform) -- one status row per platform per account, using upsert on conflict.

DB Functions

FunctionDescription
set_onlineUpsert with is_online = TRUE and metadata
set_offlineSet is_online = FALSE, clear started_at
get_statusGet all statuses for an account, ordered by platform
is_any_onlineCheck if any platform is online (DB fallback)
update_stream_dataUpdate viewer count, title, category for online channels
get_all_online_accountsBoot recovery: all accounts with online channels, grouped

Redis Keys

KeyTTLDescription
lumio:spotify_manual:{account_id}30 minManual Spotify connect active flag

Key Files

FilePurpose
apps/api/src/graphql/channel_status.rsGraphQL queries and mutations
apps/api/src/db/channel_status.rsDatabase operations
apps/api/src/services/channel_status.rsManual connect logic (Redis TTL, pub/sub)