mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 13:52:15 +01:00
The /ws endpoint runs next to the old socket on port 8080. The handshake checks the token under security, the device sends hello, then a sync of the schema (unless the client has it), header, rooms, shades, groups, repeaters and status, paced by the client's next. Events go out with the old ones: shadeState or the whole shade on a config change, groups, rooms, removals, orders, repeaters, shadeCommand, memory, wifi, ethernet, and the frames and frequencyScan feeds. The table of types, fields, errors and feeds is defined once and is sent as the schema. The writer, item writers, sync and client frame parser are pure and natively tested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.6 KiB
C++
49 lines
1.6 KiB
C++
#include <ESPAsyncWebServer.h>
|
|
#include "WResp.h"
|
|
#ifndef sockets_h
|
|
#define sockets_h
|
|
|
|
#define SOCK_MAX_ROOMS 1
|
|
#define ROOM_EMIT_FRAME 0
|
|
// The buffer every socket event is formatted into. An event that doesn't
|
|
// fit is logged and not sent, so the largest one has to fit: see remoteFrame
|
|
// in Transceiver.cpp.
|
|
#define MAX_SOCK_RESPONSE 4096
|
|
// That buffer, which protocol 2 events and sync frames are formatted into too.
|
|
// loop() only, and only between an event's start and its send.
|
|
char *socketFrameBuffer();
|
|
|
|
struct room_t {
|
|
uint8_t clients[5] = {255, 255, 255, 255, 255};
|
|
uint8_t activeClients();
|
|
bool isJoined(uint8_t num);
|
|
bool join(uint8_t num);
|
|
bool leave(uint8_t num);
|
|
void clear();
|
|
};
|
|
class SocketEmitter {
|
|
protected:
|
|
uint8_t newclients = 0;
|
|
uint8_t newClients[5] = {255,255,255,255,255};
|
|
// loop()'s task, recorded by begin(). Only it may send; see emitAllowed().
|
|
TaskHandle_t _owner = nullptr;
|
|
// What beginEmit() hands any other task, so the event goes nowhere.
|
|
JsonSockEvent _discard;
|
|
bool onLoopTask() const;
|
|
void delayInit(uint8_t num);
|
|
public:
|
|
JsonSockEvent json;
|
|
room_t rooms[SOCK_MAX_ROOMS];
|
|
uint8_t activeClients(uint8_t room);
|
|
void initClients();
|
|
void startup();
|
|
void begin();
|
|
void loop();
|
|
void end();
|
|
void disconnect();
|
|
JsonSockEvent * beginEmit(const char *evt);
|
|
void endEmit(uint8_t num = 255);
|
|
void endEmitRoom(uint8_t num);
|
|
static void wsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len);
|
|
};
|
|
#endif
|