diff --git a/CMakeLists.txt b/CMakeLists.txt index bc2152e..d6315a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,11 @@ target_include_directories(EchoionApiPlugin INTERFACE $ $ ) -target_link_libraries(EchoionApiPlugin INTERFACE Echoion::ApiBase) +target_link_libraries(EchoionApiPlugin INTERFACE + Echoion::ApiBase + Echoion::ApiTrack + Void::Plugin +) # 6. Config Types (depends on Network, Audio) add_library(EchoionApiConfig INTERFACE) @@ -163,7 +167,7 @@ target_include_directories(EchoionApiOpaque INTERFACE ) target_link_libraries(EchoionApiOpaque INTERFACE Echoion::ApiBase) -# 12a. PluginInterface only (minimal - for Plugin to implement) +# 12a. Host interface used by Core and EchoionStandalone add_library(EchoionApiPluginInterface INTERFACE) add_library(Echoion::ApiPluginInterface ALIAS EchoionApiPluginInterface) target_include_directories(EchoionApiPluginInterface INTERFACE @@ -180,7 +184,7 @@ target_link_libraries(EchoionApiPluginInterface INTERFACE Echoion::ApiOpaque ) -# 12b. CoreInterface (decoupled - for Plugin to call Core) +# 12b. CoreInterface (decoupled host boundary) add_library(EchoionApiCoreInterface INTERFACE) add_library(Echoion::ApiCoreInterface ALIAS EchoionApiCoreInterface) target_include_directories(EchoionApiCoreInterface INTERFACE @@ -194,7 +198,7 @@ target_link_libraries(EchoionApiCoreInterface INTERFACE Echoion::ApiOpaque ) -# 12c. Legacy Interfaces (both) +# 12c. Combined host interfaces add_library(EchoionApiInterfaces INTERFACE) add_library(Echoion::ApiInterfaces ALIAS EchoionApiInterfaces) target_link_libraries(EchoionApiInterfaces INTERFACE diff --git a/REORGANIZE.md b/REORGANIZE.md index 090b384..997d6a5 100644 --- a/REORGANIZE.md +++ b/REORGANIZE.md @@ -69,7 +69,7 @@ EchoionApi/include/echoion/api/ ## Include Path Changes -### For Plugin (minimal): +### For a host adapter (minimal): **Before:** ```cpp @@ -83,7 +83,8 @@ EchoionApi/include/echoion/api/ #include ``` -The CMake target `Echoion::ApiPlugin` will add the correct include paths. +The CMake target `Echoion::ApiPlugin` provides the event and host DTO include +paths retained for source compatibility. ### For Core: @@ -101,9 +102,9 @@ The CMake target `Echoion::ApiEventBus` adds `eventbus/` to the include path. ## CMake Usage -### Plugin only needs: +### Standalone host needs: ```cmake -target_link_libraries(EchoionPlugin PRIVATE +target_link_libraries(EchoionStandalone PRIVATE Echoion::ApiBase Echoion::ApiPlugin Echoion::ApiInterfaces diff --git a/include/echoion/api.hpp b/include/echoion/api.hpp index 4df75d0..9d1cf50 100644 --- a/include/echoion/api.hpp +++ b/include/echoion/api.hpp @@ -12,6 +12,7 @@ #include "api/network/NetworkInterface.hpp" #include "api/network/NetworkTypes.hpp" #include "api/plugin/PluginTypes.hpp" +#include "api/plugin/ExtensionPlugin.hpp" #include "api/rpc/RpcTypes.hpp" #include "api/track/TrackTypes.hpp" #include "api/youtube/YouTubeTypes.hpp" diff --git a/include/echoion/api/config/ConfigManager.hpp b/include/echoion/api/config/ConfigManager.hpp index 21fac0a..f4d0a71 100644 --- a/include/echoion/api/config/ConfigManager.hpp +++ b/include/echoion/api/config/ConfigManager.hpp @@ -1,5 +1,4 @@ #pragma once -#ifndef PLUGIN #include "ConfigTypes.hpp" #include #include @@ -93,5 +92,3 @@ namespace Echoion::Api }; } // namespace Echoion::Api - -#endif diff --git a/include/echoion/api/config/ConfigTypes.hpp b/include/echoion/api/config/ConfigTypes.hpp index 75489f4..7ae867a 100644 --- a/include/echoion/api/config/ConfigTypes.hpp +++ b/include/echoion/api/config/ConfigTypes.hpp @@ -1,5 +1,4 @@ #pragma once -#ifndef PLUGIN #include "AudioTypes.hpp" #include "NetworkTypes.hpp" #include "Types.hpp" @@ -29,8 +28,8 @@ namespace Echoion::Api struct BotConfig { std::string botName = "Echoion"; std::string commandPrefix = "!"; - // Default bot language ("en" or "ru"). Applies to users who have not - // picked a per-user language. Anything else normalises to "en". + // Default bot language ("en" or "ru"). Applies to users who have + // not picked a per-user language. Anything else normalises to "en". std::string language = "en"; float defaultVolume = 0.5f; uint32_t maxQueueSize = 100; @@ -61,9 +60,9 @@ namespace Echoion::Api std::string rpcBindAddress = "127.0.0.1"; }; - // Browser web interface (EchoionWeb). Serves the static UI and hosts the - // independent sync-watch WebSocket. Bot control from the browser goes - // directly to the RPC server (network.rpcPort), not through this server. + // Browser web interface (EchoionWeb). Serves the public dashboard and + // same-origin RPC bridge. Watch Together is deployed independently and + // linked through watchUrl. struct WebConfig { bool enabled = false; uint16_t port = 8080; @@ -76,6 +75,9 @@ namespace Echoion::Api // "https://bot.example.com"). Presentation only — !help links to // it when set; serving is unaffected. std::string publicUrl; + // External VoidWatch deployment. Echoion only presents this link + // and redirects the retired local /watch entrypoint to it. + std::string watchUrl; // Allow the Now Playing view to show the current song's video // (muted, synced). Users can still disable it locally; this is // the server-wide off switch, surfaced through /config.json. @@ -86,9 +88,9 @@ namespace Echoion::Api // innertube YouTube path and Yandex Music first, then falls back to // (optionally proxied) yt-dlp last. struct SourcesConfig { - std::vector order = { - "innertube", "yandex", "direct-url", - "ytdlp-direct", "ytdlp-proxied"}; + std::vector order = {"innertube", "yandex", + "direct-url", "ytdlp-direct", + "ytdlp-proxied"}; // How long a failing source is skipped before being retried. std::chrono::milliseconds failureCooldown = std::chrono::milliseconds(300000); // 5m @@ -132,9 +134,9 @@ namespace Echoion::Api std::chrono::milliseconds(3600000); bool enableAuditLog = true; std::optional apiKey; - // Reserved, not currently honored: the web UI, /rpc bridge and /ws - // are all same-origin behind the web server, so no CORS headers are - // emitted anywhere. + // Reserved, not currently honored: the web UI and /rpc bridge are + // same-origin behind the web server, so no CORS headers are + // emitted. bool allowCors = false; std::vector corsOrigins; }; @@ -175,11 +177,11 @@ namespace Echoion::Api // across plays and restarts). bool cacheEnabled = true; std::string cacheMaxSize = "1GB"; - uint32_t cacheTTL = 86400; // seconds + uint32_t cacheTTL = 86400; // seconds uint32_t tempCleanupInterval = 3600; // seconds }; - // ServerConfig for Plugin interface (mirrors PluginTypes.hpp version) + // Connection settings passed across the Echoion host interface. struct ServerConfig { std::string address; uint16_t port = 0; @@ -217,4 +219,3 @@ namespace Echoion::Api }; } // namespace Echoion::Api -#endif diff --git a/include/echoion/api/database/Database.hpp b/include/echoion/api/database/Database.hpp index be14732..e0e1828 100644 --- a/include/echoion/api/database/Database.hpp +++ b/include/echoion/api/database/Database.hpp @@ -229,31 +229,11 @@ namespace Echoion::Api Api::Result setKv(const std::string& key, const std::string& value); - // ===== Custom emojis (web UI image emotes) ===== - // Admin-managed image emotes referenced by :name: shortcodes in - // watch chat/reactions. `data` is base64-encoded image bytes. - struct CustomEmoji { - std::string name; - std::string mime; - std::string dataBase64; - std::string addedBy; - }; - [[nodiscard]] Api::Result> - getCustomEmojis(); - // Image (mime + base64 data) for one emoji name, or nullopt. - [[nodiscard]] Api::Result> - getCustomEmoji(const std::string& name); - Api::Result addCustomEmoji(const std::string& name, - const std::string& mime, - const std::string& dataBase64, - const std::string& addedBy); - Api::Result removeCustomEmoji(const std::string& name); - // ===== Cached avatars (web UI) ===== // TeamSpeak avatar images persisted by uid so the web UI can show // them even when the client is offline or out of the bot's view // (the live TS avatar cache only holds in-view clients). `data` is - // base64-encoded image bytes, like custom emojis. + // base64-encoded image bytes. struct CachedAvatar { std::string uid; std::string mime; diff --git a/include/echoion/api/interfaces/CoreInterface.hpp b/include/echoion/api/interfaces/CoreInterface.hpp index 4bfb724..a44b992 100644 --- a/include/echoion/api/interfaces/CoreInterface.hpp +++ b/include/echoion/api/interfaces/CoreInterface.hpp @@ -21,7 +21,7 @@ namespace Echoion::Api struct QueueEntry; struct PlaylistInfo; - // Minimal PlaybackState for Plugin + // Minimal playback state for the host boundary. struct PlaybackSummary { std::optional currentTrack; bool isPlaying = false; @@ -42,7 +42,7 @@ namespace Echoion::Api using CoreCreateFunc = std::function; using CoreDestroyFunc = std::function; - // Core interface that the Plugin will use to communicate with the Core + // Core interface used by the standalone host to communicate with Core. // MINIMAL VERSION - breaks dependencies on Core-specific types class ICoreInterface { @@ -51,7 +51,7 @@ namespace Echoion::Api virtual ~ICoreInterface() = default; // Lifecycle - // Plugin passes config file path, Core loads config internally + // The host passes a config path; Core loads it internally. virtual Result initialize(const std::filesystem::path& configPath) = 0; virtual Result shutdown() = 0; diff --git a/include/echoion/api/interfaces/PluginInterface.hpp b/include/echoion/api/interfaces/PluginInterface.hpp index 1be9787..808d673 100644 --- a/include/echoion/api/interfaces/PluginInterface.hpp +++ b/include/echoion/api/interfaces/PluginInterface.hpp @@ -71,7 +71,7 @@ namespace Echoion::Api // call returns the path). Downloads run asynchronously. [[nodiscard]] virtual Result> requestClientAvatar(uint64_t /*clientId*/, - const std::string& /*destDir*/) + const std::string& /*destDir*/) { return std::optional{}; } @@ -79,12 +79,92 @@ namespace Echoion::Api uint64_t channelId) = 0; virtual Result kickClient(uint64_t clientId, const std::string& reason) = 0; + virtual Result + kickClientFromChannel(uint64_t /*clientId*/, + const std::string& /*reason*/) + { + return fail(ErrorCode::NotSupported, + "channel kick is not supported by this host"); + } + virtual Result banClient(uint64_t /*clientId*/, + uint64_t /*durationSeconds*/, + const std::string& /*reason*/) + { + return fail(ErrorCode::NotSupported, + "bans are not supported by this host"); + } + [[nodiscard]] virtual Result> getBans() + { + return fail(ErrorCode::NotSupported, + "ban listing is not supported by this host"); + } + virtual Result unban(uint64_t /*banId*/) + { + return fail(ErrorCode::NotSupported, + "unban is not supported by this host"); + } // Channel operations [[nodiscard]] virtual Result> getChannels() const = 0; [[nodiscard]] virtual Result> getChannel(uint64_t channelId) const = 0; + virtual Result + createChannel(const ChannelCreateOptions& /*options*/) + { + return fail(ErrorCode::NotSupported, + "channel creation is not supported by this host"); + } + virtual Result + editChannel(uint64_t /*channelId*/, + const ChannelEditOptions& /*options*/) + { + return fail(ErrorCode::NotSupported, + "channel editing is not supported by this host"); + } + virtual Result reorderChannel(uint64_t /*channelId*/, + uint64_t /*parentId*/, + uint64_t /*orderAfterId*/) + { + return fail(ErrorCode::NotSupported, + "channel reordering is not supported by this host"); + } + virtual Result deleteChannel(uint64_t /*channelId*/, + bool /*force*/) + { + return fail(ErrorCode::NotSupported, + "channel deletion is not supported by this host"); + } + + // Server-group administration. Membership changes use TeamSpeak's + // stable client database id, not the connection-scoped client id. + [[nodiscard]] virtual Result> + getServerGroups() + { + return fail(ErrorCode::NotSupported, + "server groups are not supported by this host"); + } + virtual Result + addClientToServerGroup(uint64_t /*groupId*/, + uint64_t /*clientDatabaseId*/) + { + return fail( + ErrorCode::NotSupported, + "server-group membership is not supported by this host"); + } + virtual Result + removeClientFromServerGroup(uint64_t /*groupId*/, + uint64_t /*clientDatabaseId*/) + { + return fail( + ErrorCode::NotSupported, + "server-group membership is not supported by this host"); + } + [[nodiscard]] virtual Result getTeamSpeakServerInfo() + { + return fail(ErrorCode::NotSupported, + "server information is not supported by this host"); + } // Messaging virtual Result @@ -102,40 +182,6 @@ namespace Echoion::Api virtual Result setWhisperList(const std::vector& clientIds) = 0; - // Independent audio timelines. A TeamSpeak connection has one voice - // sequence, so hosts implement each stream with its own connection and - // encoder. The default methods preserve compatibility for hosts that only - // support the primary stream. - using AudioStreamId = uint64_t; - struct AudioStreamOptions { - std::string name; - ServerConfig server; - std::vector recipients; - }; - [[nodiscard]] virtual Result - createAudioStream(const AudioStreamOptions&) - { - return fail(ErrorCode::NotSupported, - "independent audio streams are not supported by this host"); - } - virtual Result destroyAudioStream(AudioStreamId) - { - return fail(ErrorCode::NotSupported, - "independent audio streams are not supported by this host"); - } - virtual Result sendAudioDataToStream( - AudioStreamId, const std::span&) - { - return fail(ErrorCode::NotSupported, - "independent audio streams are not supported by this host"); - } - virtual Result setAudioStreamRecipients( - AudioStreamId, const std::vector&) - { - return fail(ErrorCode::NotSupported, - "independent audio streams are not supported by this host"); - } - // Server connection // ServerConfig is defined in PluginTypes.hpp (self-contained) virtual Result diff --git a/include/echoion/api/plugin/ExtensionPlugin.hpp b/include/echoion/api/plugin/ExtensionPlugin.hpp new file mode 100644 index 0000000..0a6f88c --- /dev/null +++ b/include/echoion/api/plugin/ExtensionPlugin.hpp @@ -0,0 +1,111 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace Echoion::Api +{ + struct ExtensionCommand { + std::string name; + std::vector aliases; + std::string description; + std::string usage; + std::uint8_t category = 5; + bool adminOnly = false; + }; + + struct ExtensionRpc { + std::string name; + bool adminOnly = false; + }; + + struct ExtensionMediaSource { + std::string name; + bool supportsSearch = false; + }; + + struct ExtensionWebAsset { + std::string id; + std::string javascript; + std::string css; + }; + + struct ExtensionCommandRequest { + std::string command; + std::string arguments; + std::uint64_t clientId = 0; + std::string invokerName; + }; + + struct ExtensionRpcRequest { + std::string method; + std::string params; + std::uint64_t clientId = 0; + }; + + struct ExtensionStream { + std::string url; + bool localFile = false; + }; + + // Native, trusted Echoion extension contract. Calls are always made while + // the host holds a Void::Plugin::PluginHandle, so a hot reload cannot + // unmap code that is still executing. + class IExtensionPlugin : public Void::Plugin::IPlugin + { + public: + [[nodiscard]] virtual std::vector commands() const + { + return {}; + } + [[nodiscard]] virtual std::vector rpcMethods() const + { + return {}; + } + [[nodiscard]] virtual std::vector mediaSources() const + { + return {}; + } + [[nodiscard]] virtual std::vector webAssets() const + { + return {}; + } + virtual Result executeCommand( + const ExtensionCommandRequest&) + { + return fail(ErrorCode::NotSupported, "extension command is not supported"); + } + virtual Result callRpc(const ExtensionRpcRequest&) + { + return fail(ErrorCode::NotSupported, "extension RPC is not supported"); + } + virtual void onEvent(const PluginEvent&) {} + [[nodiscard]] virtual bool canHandleMedia( + std::string_view, const std::string&) const + { + return false; + } + virtual Result searchMedia( + std::string_view, std::string_view) + { + return fail(ErrorCode::NotSupported, "extension search is not supported"); + } + virtual Result resolveMedia( + std::string_view, const std::string&) + { + return fail(ErrorCode::NotSupported, "extension resolve is not supported"); + } + virtual Result streamMedia( + std::string_view, const TrackInfo&) + { + return fail(ErrorCode::NotSupported, "extension stream is not supported"); + } + }; +} diff --git a/include/echoion/api/plugin/PluginTypes.hpp b/include/echoion/api/plugin/PluginTypes.hpp index 2765e91..2b9003c 100644 --- a/include/echoion/api/plugin/PluginTypes.hpp +++ b/include/echoion/api/plugin/PluginTypes.hpp @@ -1,7 +1,5 @@ #pragma once -#ifndef PLUGIN #include -#endif #include #include #include @@ -41,10 +39,14 @@ namespace Echoion::Api ConfigurationChanged, // Appended: fired once the TeamSpeak connection is fully established // (client list available), so the core can resolve online subscribers. - ConnectionEstablished + ConnectionEstablished, + // Appended for the authoritative TeamSpeak directory cache. Hosts may + // emit either event after refreshing their local topology mirror. + ClientUpdated, + ChannelUpdated }; - // Minimal track info for Plugin (no internal types) + // Minimal track info for the host boundary (no internal types) struct TrackSummary { std::string id; std::string title; @@ -69,12 +71,15 @@ namespace Echoion::Api struct ClientInfo { uint64_t id = 0; + std::optional databaseId; std::string nickname; std::optional uniqueIdentifier; uint64_t channelId = 0; bool isTalking = false; bool isMuted = false; bool isDeafened = false; + bool isAway = false; + bool isQuery = false; std::vector serverGroups; }; @@ -84,11 +89,48 @@ namespace Echoion::Api std::optional parentId; uint64_t order = 0; bool isDefault = false; + bool isPermanent = false; + bool isSemiPermanent = false; bool hasPassword = false; uint32_t maxClients = 0; uint32_t currentClients = 0; }; + struct ChannelCreateOptions { + std::string name; + std::optional parentId; + std::optional orderAfterId; + std::optional topic; + std::optional description; + std::optional password; + uint32_t maxClients = 0; + bool permanent = true; + }; + + struct ChannelEditOptions { + std::optional name; + std::optional topic; + std::optional description; + std::optional password; + std::optional maxClients; + std::optional permanent; + }; + + struct ServerGroupInfo { + uint64_t id = 0; + std::string name; + bool isDefault = false; + }; + + struct BanInfo { + uint64_t id = 0; + std::optional uniqueIdentifier; + std::optional nickname; + std::string reason; + uint64_t createdAt = 0; + uint64_t durationSeconds = 0; // 0 means permanent + }; + struct ServerInfo { uint64_t id = 0; std::string name; @@ -98,22 +140,6 @@ namespace Echoion::Api uint64_t defaultChannelId = 0; }; -// ServerConfig is needed for Plugin's connectToServer() -// This is a minimal version without dependencies on AudioTypes, etc. -// Available to both Core and Plugin -#ifdef PLUGIN - struct ServerConfig { - std::string address; - uint16_t port = 0; - std::string serverPassword; - std::string nickname; - std::optional defaultChannelId; - std::optional channelPassword; - std::vector adminGroups; - std::vector djGroups; - std::vector bannedGroups; - }; -#endif // ===== Callback Types ===== using EventCallback = std::function; diff --git a/include/echoion/api/rpc/RpcTypes.hpp b/include/echoion/api/rpc/RpcTypes.hpp index f50df28..8b6a290 100644 --- a/include/echoion/api/rpc/RpcTypes.hpp +++ b/include/echoion/api/rpc/RpcTypes.hpp @@ -68,15 +68,15 @@ namespace Echoion::Api // Library (appended) GetPlaylist, // playlist contents by id - GetHistory, // recently played tracks - GetStats, // playback statistics + GetHistory, // recently played tracks + GetStats, // playback statistics // Web UI (appended) - GetFavorites, // authenticated user's favorites - AddFavorite, // add a track to favorites - RemoveFavorite, // remove by track url - VoteSkip, // vote to skip the current track - Announce, // admin: broadcast an announcement + GetFavorites, // authenticated user's favorites + AddFavorite, // add a track to favorites + RemoveFavorite, // remove by track url + VoteSkip, // vote to skip the current track + Announce, // admin: broadcast an announcement GetAggregateStats, // server-wide dashboard statistics // Web UI round 2 (appended) @@ -90,29 +90,34 @@ namespace Echoion::Api SetUserPrefs, // update per-user preferences; keys shared with the // chat commands (e.g. !lang) so both stay in sync - // Web UI round 4 (appended): custom emojis for watch chat/reactions - GetCustomEmojis, // list custom emoji names (+ mime) - AddCustomEmoji, // admin: add/replace a custom emoji (base64 image) - RemoveCustomEmoji, // admin: delete a custom emoji - + // Values 49-51 are reserved for retired browser features. // Web UI round 5 (appended): lyrics for the current track (lrclib) - GetLyrics, // plain + time-synced lyrics for the now-playing track + GetLyrics = 52, // plain + time-synced lyrics for the now-playing track - // Independent named TeamSpeak listening rooms. - ListListeningRooms, - CreateListeningRoom, - DeleteListeningRoom, - JoinListeningRoom, - LeaveListeningRoom, - PlayInListeningRoom, - PauseListeningRoom, - ResumeListeningRoom, - StopListeningRoom, - GetListeningRoomQueue, - SkipListeningRoom, - RemoveFromListeningRoomQueue, - MoveInListeningRoomQueue, - ClearListeningRoomQueue + // Values 53-66 belonged to the removed experimental TeamSpeak + // listening-room API. Keep later values stable for stored audit rows. + GetCapabilities = 67, + GetPluginExtensions, + PluginCall, + + // Values 70-72 are reserved for retired browser features. + // TeamSpeak directory and administration; 53-66 stay reserved. + GetTeamSpeakDirectory = 73, + MoveTeamSpeakClient, + KickTeamSpeakClient, + BanTeamSpeakClient, + GetTeamSpeakBans, + UnbanTeamSpeakClient, + CreateTeamSpeakChannel, + EditTeamSpeakChannel, + ReorderTeamSpeakChannel, + DeleteTeamSpeakChannel, + GetTeamSpeakServerGroups, + AddTeamSpeakServerGroupMember, + RemoveTeamSpeakServerGroupMember, + SendTeamSpeakPrivateMessage, + SendTeamSpeakChannelMessage, + SendTeamSpeakServerMessage }; struct RpcRequest {