diff --git a/src/AsyncEventSource.cpp b/src/AsyncEventSource.cpp index 7085972..d0912a0 100644 --- a/src/AsyncEventSource.cpp +++ b/src/AsyncEventSource.cpp @@ -243,6 +243,17 @@ void AsyncEventSource::send(const char *message, const char *event, uint32_t id, } } +size_t AsyncEventSource::count(){ + size_t i = 0; + AsyncEventSourceClient * c = _clients; + while(c != NULL){ + if(c->connected()) + i++; + c = c->next; + } + return i; +} + bool AsyncEventSource::canHandle(AsyncWebServerRequest *request){ if(request->method() != HTTP_GET || !request->url().equals(_url)) return false; diff --git a/src/AsyncEventSource.h b/src/AsyncEventSource.h index 2dd30ea..94c1e85 100644 --- a/src/AsyncEventSource.h +++ b/src/AsyncEventSource.h @@ -66,6 +66,7 @@ class AsyncEventSource: public AsyncWebHandler { void close(); void onConnect(ArEventHandlerFunction cb); void send(const char *message, const char *event=NULL, uint32_t id=0, uint32_t reconnect=0); + size_t count(); //number clinets connected //system callbacks (do not call) void _addClient(AsyncEventSourceClient * client);