mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-08-05 21:54:38 +02:00
@@ -147,6 +147,8 @@ AsyncMiddlewareFunction complexAuth([](AsyncWebServerRequest* request, ArMiddlew
|
|||||||
|
|
||||||
AuthorizationMiddleware authz([](AsyncWebServerRequest* request) { return request->getAttribute("role") == "staff"; });
|
AuthorizationMiddleware authz([](AsyncWebServerRequest* request) { return request->getAttribute("role") == "staff"; });
|
||||||
|
|
||||||
|
int wsClients = 0;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const char* PARAM_MESSAGE PROGMEM = "message";
|
const char* PARAM_MESSAGE PROGMEM = "message";
|
||||||
@@ -646,10 +648,14 @@ void setup() {
|
|||||||
ws.onEvent([](AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) {
|
ws.onEvent([](AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) {
|
||||||
(void)len;
|
(void)len;
|
||||||
if (type == WS_EVT_CONNECT) {
|
if (type == WS_EVT_CONNECT) {
|
||||||
|
wsClients++;
|
||||||
|
ws.textAll("new client connected");
|
||||||
Serial.println("ws connect");
|
Serial.println("ws connect");
|
||||||
client->setCloseClientOnQueueFull(false);
|
client->setCloseClientOnQueueFull(false);
|
||||||
client->ping();
|
client->ping();
|
||||||
} else if (type == WS_EVT_DISCONNECT) {
|
} else if (type == WS_EVT_DISCONNECT) {
|
||||||
|
wsClients--;
|
||||||
|
ws.textAll("client disconnected");
|
||||||
Serial.println("ws disconnect");
|
Serial.println("ws disconnect");
|
||||||
} else if (type == WS_EVT_ERROR) {
|
} else if (type == WS_EVT_ERROR) {
|
||||||
Serial.println("ws error");
|
Serial.println("ws error");
|
||||||
|
Reference in New Issue
Block a user