Files
spore/include/spore/core/NodeContext.h
Patrick Balsiger 3cc5405292 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.
2025-09-28 21:10:26 +02:00

33 lines
918 B
C++

#pragma once
#include <WiFiUdp.h>
#include <map>
#include "spore/types/NodeInfo.h"
#include <functional>
#include <string>
#include <initializer_list>
#include "spore/types/Config.h"
#include "spore/types/ApiTypes.h"
class NodeContext {
public:
NodeContext();
NodeContext(std::initializer_list<std::pair<String, String>> initialLabels);
~NodeContext();
WiFiUDP* udp;
String hostname;
IPAddress localIP;
NodeInfo self;
std::map<String, NodeInfo>* memberList;
Config config;
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);
};