Merge pull request #17 from ahinrichs/pr-rate-limit-ws-cleanup

[WebApi] rate limit ws cleanup (1/s)
This commit is contained in:
tbnobody 2022-07-06 19:23:19 +02:00 committed by GitHub
commit 39e6a46665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -31,6 +31,7 @@ private:
WebApiSysstatusClass _webApiSysstatus; WebApiSysstatusClass _webApiSysstatus;
WebApiWebappClass _webApiWebapp; WebApiWebappClass _webApiWebapp;
WebApiWsLiveClass _webApiWsLive; WebApiWsLiveClass _webApiWsLive;
unsigned long lastTimerCall = 0;
void onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len); void onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len);
}; };

View File

@ -47,7 +47,10 @@ void WebApiClass::loop()
_webApiWsLive.loop(); _webApiWsLive.loop();
// see: https://github.com/me-no-dev/ESPAsyncWebServer#limiting-the-number-of-web-socket-clients // see: https://github.com/me-no-dev/ESPAsyncWebServer#limiting-the-number-of-web-socket-clients
_ws.cleanupClients(); if (millis() - lastTimerCall > 1000) {
_ws.cleanupClients();
lastTimerCall = millis();
}
} }
void WebApiClass::onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) void WebApiClass::onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len)