#pragma once #include #include #include #include #include #include #include #include namespace Echoion::Core { // Serialize any reflectable DTO to a JSON string (correct escaping). template [[nodiscard]] std::string toJson(const T& dto) { return Void::Json::serialize(Void::Json::to_json(dto)); } } // namespace Echoion::Core // Reflectable DTOs for the RPC responses and event-broadcast payloads. These // are serialized with Void::Json (reflection) instead of hand-built strings, // so member names are the JSON keys and values are always correctly escaped. namespace Echoion::Core::Dto { // ── RPC request payloads (parsed) ─────────────────────────────────────── struct AuthRequest { std::optional nickname; std::optional token; }; struct SeekRequest { std::int64_t position = 0; // milliseconds }; struct VolumeRequest { float volume = 0.5f; // normalised 0.0 - 1.0 }; struct SkipRequest { std::uint32_t count = 1; }; struct QueueTrackRequest { std::string query; }; struct QueueIdRequest { std::uint64_t queueId = 0; }; struct MoveRequest { std::uint64_t queueId = 0; std::uint32_t newPosition = 0; }; struct SearchRequest { std::string query; }; struct TrackIdRequest { std::string id; }; struct PlaylistIdRequest { std::string playlistId; }; struct SavePlaylistRequest { std::string name; std::string description; }; struct ManageUsersRequest { std::string action; // "list" | "remove" | "clearAll" std::optional uid; }; struct UrlRequest { std::string url; }; struct AnnounceRequest { std::string text; }; // ── RPC handler responses ─────────────────────────────────────────────── struct Track { std::string id; std::string title; std::string artist; std::string album; std::optional duration; // milliseconds int source = 0; std::optional thumbnailUrl; std::optional url; // originalUrl (play-by-url) // Provider-generated shortened link when available; the web UI prefers // it for "open original link" (falls back to url). std::optional shortenedUrl; }; [[nodiscard]] inline Track toTrack(const Api::TrackInfo& t) { return Track{.id = t.id, .title = t.title, .artist = t.artist, .album = t.album, .duration = t.duration ? std::optional( t.duration->count()) : std::nullopt, .source = static_cast(t.source), .thumbnailUrl = t.thumbnailUrl, .url = t.originalUrl.empty() ? std::nullopt : std::optional(t.originalUrl), .shortenedUrl = t.shortenedUrl && !t.shortenedUrl->empty() ? t.shortenedUrl : std::nullopt}; } // Inverse of toTrack (client-supplied tracks, e.g. AddFavorite). [[nodiscard]] inline Api::TrackInfo fromTrack(const Track& t) { Api::TrackInfo info; info.id = t.id; info.title = t.title; info.artist = t.artist; info.album = t.album; if (t.duration) { info.duration = std::chrono::milliseconds(*t.duration); } info.source = static_cast(t.source); info.thumbnailUrl = t.thumbnailUrl; info.originalUrl = t.url.value_or(""); return info; } struct QueueItem { std::uint64_t queueId = 0; Track track; bool isPlaying = false; }; struct QueueResponse { std::vector queue; }; struct CurrentTrackResponse { std::optional track; }; struct Status { bool isPlaying = false; bool isPaused = false; float volume = 0.0f; bool repeat = false; bool shuffle = false; // Radio mode: auto-enqueue related tracks when the queue runs dry. bool autoplay = false; // Vote-skip state for the current track (additive fields). std::uint32_t skipVotes = 0; std::uint32_t skipVotesNeeded = 0; bool skipVoted = false; }; struct Success { bool success = true; }; struct SuccessMessage { bool success = true; std::string message; }; struct SuccessVolume { bool success = true; float volume = 0.0f; }; struct Capabilities { bool plugins = false; bool webExtensions = false; }; struct PluginCallRequest { std::string plugin; std::string method; std::string params; }; struct PluginExtensions { std::vector assets; }; struct Autoplay { bool autoplay = false; }; // Per-user preferences stored in the kv store; `language` shares the // "lang:" key with the !lang chat command so the web switcher and // the bot stay in sync. struct UserPrefs { std::string language; }; struct QueuedResponse { bool success = true; std::uint64_t queueId = 0; }; struct SearchResults { std::vector tracks; }; struct PlaylistBrief { std::string id; std::string name; std::string description; std::uint32_t trackCount = 0; }; struct PlaylistList { std::vector playlists; }; struct PlaylistContents { std::string id; std::string name; std::string description; std::vector tracks; }; struct HistoryRequest { std::uint32_t limit = 20; }; struct HistoryResponse { std::vector tracks; }; struct StatsResponse { std::uint64_t totalPlays = 0; std::uint64_t totalTracks = 0; std::uint64_t totalPlaytimeMs = 0; std::optional mostPlayedTitle; std::uint64_t mostPlayedCount = 0; }; struct ServerInfo { std::string version; std::int64_t uptimeSeconds = 0; std::uint32_t connectedClients = 0; std::uint32_t subscribers = 0; std::uint32_t queueLength = 0; std::uint32_t onlineSubscribers = 0; // Nicknames behind onlineSubscribers, so non-admin clients can // render a "listening now" list without the admin user API. std::vector onlineSubscriberNames; // TeamSpeak uids parallel to onlineSubscriberNames (same order), so // the web UI can fetch each listener's avatar at /avatar/. std::vector onlineSubscriberUids; }; struct AuditEntryDto { std::uint64_t clientId = 0; int method = 0; std::int64_t timestamp = 0; // unix seconds }; struct AuditLogResponse { std::vector entries; }; struct SubscriberDto { std::string uid; std::string nickname; bool online = false; }; struct UsersResponse { std::vector users; }; // Authenticate success. isAdmin/isDj/uid/nickname are additive — older // clients that only read `message` keep working. struct AuthSuccess { bool success = true; std::string message; bool isAdmin = false; bool isDj = false; std::string uid; std::string nickname; // Set by address-based autologin so the client can persist the // session token it never typed; empty for normal token auth. std::string token; }; struct AddFavoriteRequest { Track track; }; struct FavoritesResponse { std::vector tracks; }; // GetLyrics response: plain text plus, when available, time-synced lines // (ms offset from track start) so the web UI can highlight the active line. struct LyricsLineDto { std::int64_t ms = 0; std::string text; }; struct LyricsResponse { bool found = false; std::string plain; std::vector synced; std::string source; // "lrclib" when resolved std::string title; std::string artist; }; struct VoteSkipResponse { std::uint32_t votes = 0; std::uint32_t needed = 0; bool voted = false; bool skipped = false; }; struct RequesterDto { std::string uid; std::string nickname; std::uint64_t count = 0; }; struct AggregateStatsResponse { std::uint64_t tracksToday = 0; std::uint64_t listeningMsToday = 0; std::uint64_t queueAdditionsToday = 0; std::uint64_t skipsToday = 0; std::uint64_t playsTotal = 0; std::uint64_t skipsTotal = 0; std::vector topRequesters; std::uint64_t youtubeCount = 0; std::uint64_t yandexCount = 0; std::uint64_t otherCount = 0; }; // ── Event-broadcast payloads ──────────────────────────────────────────── struct TrackBrief { std::string id; std::string title; std::string artist; }; struct PlaybackStarted { TrackBrief track; std::int64_t position = 0; }; struct Position { std::int64_t position = 0; }; struct PositionProgress { std::int64_t position = 0; std::int64_t duration = 0; float progress = 0.0f; }; struct Volume { float volume = 0.0f; }; struct Shuffle { bool shuffle = false; }; struct Repeat { bool repeat = false; }; struct TrackQueued { std::uint64_t queueId = 0; std::string title; std::string artist; std::uint32_t position = 0; std::uint32_t queueLength = 0; }; struct TrackRemoved { std::uint64_t queueId = 0; std::uint32_t queueLength = 0; }; struct QueueReordered { std::uint64_t queueId = 0; std::uint32_t oldPosition = 0; std::uint32_t newPosition = 0; }; struct PlaylistId { std::string playlistId; }; struct PlaylistTrackLoaded { std::string playlistId; std::uint32_t loaded = 0; std::uint32_t total = 0; }; struct PlaylistLoadCompleted { std::string playlistId; std::uint32_t totalTracks = 0; bool success = false; }; struct User { std::string uid; std::string nickname; }; struct ClientId { std::uint64_t clientId = 0; }; // Plugin-event track payload (duration in seconds, matching the legacy // broadcastEvent shape). struct EventTrack { std::string id; std::string title; std::string artist; std::int64_t duration = 0; }; } // namespace Echoion::Core::Dto