feat(streaming): introduce WebSocket Streaming API bridging event bus
ApiServer: add AsyncWebSocket at /ws; accept JSON {event, payload} (string or object) and dispatch via ctx.fire; mirror all local events to clients using NodeContext::onAny.\nNodeContext: add onAny subscriber API.\nNeoPatternService: add api/neopattern/color event to set solid color.\nCluster: centralize cluster/broadcast sending in core; services delegate.\nAPI: add generic /api/node/event and /api/cluster/event endpoints in respective services.\nTests: add ws-color-client, ws-cluster-broadcast-color, http-cluster-broadcast-color.\nDocs: add StreamingAPI.md; update README and test/README.\nFixes: robust WS JSON parsing on ESP8266 and payload handling.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <AsyncWebSocket.h>
|
||||
#include <Updater.h>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
@@ -39,6 +40,7 @@ public:
|
||||
|
||||
private:
|
||||
AsyncWebServer server;
|
||||
AsyncWebSocket ws{ "/ws" };
|
||||
NodeContext& ctx;
|
||||
TaskManager& taskManager;
|
||||
std::vector<std::reference_wrapper<Service>> services;
|
||||
@@ -48,4 +50,7 @@ private:
|
||||
void registerEndpoint(const String& uri, int method,
|
||||
const std::vector<ParamSpec>& params,
|
||||
const String& serviceName);
|
||||
|
||||
// WebSocket helpers
|
||||
void setupWebSocket();
|
||||
};
|
||||
|
||||
@@ -23,7 +23,10 @@ public:
|
||||
|
||||
using EventCallback = std::function<void(void*)>;
|
||||
std::map<std::string, std::vector<EventCallback>> eventRegistry;
|
||||
using AnyEventCallback = std::function<void(const std::string&, void*)>;
|
||||
std::vector<AnyEventCallback> anyEventSubscribers;
|
||||
|
||||
void on(const std::string& event, EventCallback cb);
|
||||
void fire(const std::string& event, void* data);
|
||||
void onAny(AnyEventCallback cb);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user