[WebApi] rate limit ws cleanup (1/s)

This commit is contained in:
Axel Hinrichs 2022-07-05 23:42:07 +02:00
parent 44ac770c53
commit 401e6739cd
2 changed files with 5 additions and 1 deletions

View File

@ -31,6 +31,7 @@ private:
WebApiSysstatusClass _webApiSysstatus;
WebApiWebappClass _webApiWebapp;
WebApiWsLiveClass _webApiWsLive;
unsigned long lastTimerCall = 0;
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();
// 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)