7da6ea37e7
- Added AudioEngine integration to BluetoothManager for audio handling. - Implemented auto-reconnect functionality with enabling/disabling options. - Introduced methods for managing audio state and HFP events. - Updated BluetoothManager's internal state management for better audio handling. refactor: Update A252ConfigStore to improve pin validation logic - Renamed critical_pins to required_pins for clarity. - Added optional legacy line-enable pin validation. - Improved error handling for pin conflicts and invalid ranges. fix: Adjust default volume and slic_line configuration in A252ConfigStore - Set default slic_line to -1 to indicate retirement. - Increased default audio volume from 80 to 90. feat: Implement audio amplifier control in main application - Added commands to enable/disable audio amplifier via GPIO. - Integrated audio amplifier control into the setup process. fix: Improve ESP-NOW and WiFi coexistence policies - Enforced modem sleep for better coexistence between WiFi and Bluetooth. - Added checks to ensure proper WiFi mode before enforcing coexistence. feat: Enhance TelephonyService with DTMF and pulse dialing support - Added DTMF capture and processing capabilities. - Implemented rotary pulse dialing logic with state management. - Introduced callbacks for dialing and answering actions. feat: Add real-time event publishing to WebServerManager - Enabled real-time status updates via SSE. - Improved status caching and thread safety with critical sections. fix: General code cleanup and optimizations across modules - Refactored various methods for better readability and maintainability. - Improved error handling and logging for better debugging.
59 lines
2.0 KiB
C++
59 lines
2.0 KiB
C++
#ifndef WEB_WEB_SERVER_MANAGER_H
|
|
#define WEB_WEB_SERVER_MANAGER_H
|
|
|
|
#include <Arduino.h>
|
|
#include <ArduinoJson.h>
|
|
#include <ESPAsyncWebServer.h>
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
#include <functional>
|
|
|
|
#include "core/CommandDispatcher.h"
|
|
|
|
class WebServerManager {
|
|
public:
|
|
explicit WebServerManager(uint16_t port = 80);
|
|
void begin();
|
|
void handle();
|
|
|
|
void setAuthCredentials(const String& user, const String& pass, bool persist_to_nvs = false);
|
|
void setAuthEnabled(bool enabled);
|
|
bool isAuthEnabled() const;
|
|
void setRateLimitMs(uint32_t rate_limit_ms);
|
|
|
|
void setStatusCallback(std::function<void(JsonObject)> callback);
|
|
void setCommandExecutor(std::function<DispatchResponse(const String&)> callback);
|
|
|
|
private:
|
|
AsyncWebServer server_;
|
|
AsyncEventSource events_;
|
|
uint32_t rate_limit_ms_;
|
|
uint32_t last_status_push_ms_;
|
|
String status_cache_json_;
|
|
bool status_cache_ready_;
|
|
portMUX_TYPE status_cache_mux_;
|
|
bool auth_enabled_;
|
|
String auth_user_;
|
|
String auth_pass_;
|
|
std::function<void(JsonObject)> status_callback_;
|
|
std::function<DispatchResponse(const String&)> command_executor_;
|
|
|
|
void registerRoutes();
|
|
bool authenticateRequest(AsyncWebServerRequest* request) const;
|
|
static bool extractJsonBody(AsyncWebServerRequest* request, JsonDocument& doc);
|
|
static String toJsonString(const JsonDocument& doc);
|
|
static bool isValidInput(const String& value, size_t max_len);
|
|
static bool isEffectCommand(const String& command_line);
|
|
String snapshotStatusCache(bool* ready = nullptr);
|
|
void refreshStatusCache();
|
|
void publishRealtimeEvent(const char* event_name, const String& payload_json);
|
|
void publishRealtimeStatus();
|
|
void publishDispatchEvent(const String& command_line, const DispatchResponse& res);
|
|
void handleDispatch(AsyncWebServerRequest* request,
|
|
const String& command_line,
|
|
uint16_t success_code = 200,
|
|
uint16_t error_code = 400);
|
|
};
|
|
|
|
#endif // WEB_WEB_SERVER_MANAGER_H
|