Initial commit
This commit is contained in:
commit
8b8a7f4f9a
17 files changed
+4930
No files matched your search
@@ -0,0 +1,117 @@
|
||||
#pragma once
|
||||
|
||||
#include <echoion/api.hpp>
|
||||
#include <dylib.hpp>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <queue>
|
||||
#include <condition_variable>
|
||||
|
||||
// TeamSpeak SDK headers
|
||||
#include "ts3_functions.h"
|
||||
|
||||
namespace Echoion::Plugin {
|
||||
|
||||
// Audio device configuration
|
||||
struct AudioDeviceConfig {
|
||||
static constexpr const char* DEVICE_ID = "echoion_audio_device";
|
||||
static constexpr const char* DEVICE_NAME = "Echoion Music Bot Audio";
|
||||
static constexpr int SAMPLE_RATE = 192000; // Match reference implementation
|
||||
static constexpr int CHANNELS = 2;
|
||||
static constexpr int SAMPLE_SIZE = sizeof(int16_t);
|
||||
};
|
||||
|
||||
// Plugin implementation of IPluginInterface for the Core to use
|
||||
class PluginInterface : public Api::IPluginInterface {
|
||||
public:
|
||||
PluginInterface();
|
||||
~PluginInterface() override;
|
||||
|
||||
// Initialize with TeamSpeak functions
|
||||
Api::Result<void> initialize(TS3Functions* ts3Functions);
|
||||
|
||||
// IPluginInterface implementation
|
||||
Api::Result<void> initialize() override;
|
||||
Api::Result<void> shutdown() override;
|
||||
|
||||
// Client operations
|
||||
[[nodiscard]] Api::Result<std::vector<Api::ClientInfo>> getClients() const override;
|
||||
[[nodiscard]] Api::Result<std::optional<Api::ClientInfo>> getClient(uint64_t clientId) const override;
|
||||
Api::Result<void> moveClient(uint64_t clientId, uint64_t channelId) override;
|
||||
Api::Result<void> kickClient(uint64_t clientId, const std::string& reason) override;
|
||||
|
||||
// Channel operations
|
||||
[[nodiscard]] Api::Result<std::vector<Api::ChannelInfo>> getChannels() const override;
|
||||
[[nodiscard]] Api::Result<std::optional<Api::ChannelInfo>> getChannel(uint64_t channelId) const override;
|
||||
|
||||
// Messaging
|
||||
Api::Result<void> sendTextMessage(uint64_t targetId, const std::string& message) override;
|
||||
Api::Result<void> sendChannelMessage(uint64_t channelId, const std::string& message) override;
|
||||
Api::Result<void> sendServerMessage(const std::string& message) override;
|
||||
|
||||
// Audio
|
||||
Api::Result<void> sendAudioData(const std::span<const uint8_t>& data) override;
|
||||
Api::Result<void> setWhisperList(const std::vector<uint64_t>& clientIds) override;
|
||||
|
||||
// Event subscription
|
||||
void registerEventCallback(const Api::EventCallback& callback) override;
|
||||
void unregisterEventCallback(const Api::EventCallback& callback) override;
|
||||
|
||||
// TeamSpeak event handlers (called by TeamSpeak SDK)
|
||||
void onClientConnected(uint64_t serverConnectionHandlerId, uint64_t clientId);
|
||||
void onClientDisconnected(uint64_t serverConnectionHandlerId, uint64_t clientId);
|
||||
void onClientMoved(uint64_t serverConnectionHandlerId, uint64_t clientId, uint64_t newChannelId);
|
||||
void onTextMessageReceived(uint64_t serverConnectionHandlerId, uint64_t targetMode,
|
||||
uint64_t fromId, const std::string& message);
|
||||
void onVoiceDataReceived(uint64_t serverConnectionHandlerId, uint64_t clientId,
|
||||
const std::span<const uint8_t>& data);
|
||||
|
||||
// Server connection management (IPluginInterface implementation)
|
||||
Api::Result<void> connectToServer(const Api::ServerConfig& config) override;
|
||||
Api::Result<void> disconnectFromServer() override;
|
||||
[[nodiscard]] bool isConnected() const override;
|
||||
Api::Result<void> reconnect() override;
|
||||
|
||||
// Audio device management
|
||||
Api::Result<void> registerAudioDevice();
|
||||
Api::Result<void> unregisterAudioDevice();
|
||||
Api::Result<void> openAudioDevice();
|
||||
[[nodiscard]] bool isAudioDeviceRegistered() const { return audioDeviceRegistered_; }
|
||||
Api::Result<void> closeAudioDevice();
|
||||
[[nodiscard]] bool isAudioDeviceOpen() const;
|
||||
|
||||
// Set server connection handler
|
||||
void setServerConnectionHandlerId(uint64_t handlerId);
|
||||
[[nodiscard]] uint64_t getServerConnectionHandlerId() const;
|
||||
|
||||
// Audio data submission (for internal use)
|
||||
void submitAudioData(const std::span<const int16_t> samples);
|
||||
|
||||
private:
|
||||
void broadcastEvent(const Api::PluginEvent& event);
|
||||
std::string getClientName(uint64_t clientId) const;
|
||||
std::string getChannelName(uint64_t channelId) const;
|
||||
|
||||
TS3Functions* ts3Functions_ = nullptr;
|
||||
uint64_t serverConnectionHandlerId_ = 0;
|
||||
std::atomic<bool> initialized_{false};
|
||||
std::atomic<bool> audioDeviceRegistered_{false};
|
||||
std::atomic<bool> audioDeviceOpen_{false};
|
||||
|
||||
std::vector<Api::EventCallback> eventCallbacks_;
|
||||
mutable std::mutex eventMutex_;
|
||||
|
||||
// Audio data queue
|
||||
std::queue<std::vector<int16_t>> audioQueue_;
|
||||
std::mutex audioMutex_;
|
||||
std::condition_variable audioCv_;
|
||||
std::atomic<bool> stopAudioThread_{false};
|
||||
std::jthread audioThread_;
|
||||
|
||||
// Connection info
|
||||
Api::ServerConfig currentServerConfig_;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Plugin
|
||||
Reference in new issue
Block a user