🚇 Adds hasSubcribers to event socket for early return
This commit is contained in:
@@ -39,6 +39,7 @@ class AnalyticsService {
|
||||
TaskManager *_taskManager;
|
||||
|
||||
void updateAnalytics() {
|
||||
if (!_socket->hasSubscribers(EVENT_ANALYTICS)) return;
|
||||
doc.clear();
|
||||
doc["uptime"] = millis() / 1000;
|
||||
doc["free_heap"] = ESP.getFreeHeap();
|
||||
|
||||
@@ -125,6 +125,8 @@ esp_err_t EventSocket::onFrame(PsychicWebSocketRequest *request, httpd_ws_frame
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool EventSocket::hasSubscribers(const char *event) { return !client_subscriptions[event].empty(); }
|
||||
|
||||
void EventSocket::emit(const char *event, const char *payload, const char *originId, bool onlyToSameOrigin) {
|
||||
int originSubscriptionId = originId[0] ? atoi(originId) : -1;
|
||||
xSemaphoreTake(clientSubscriptionsMutex, portMAX_DELAY);
|
||||
|
||||
@@ -22,6 +22,8 @@ class EventSocket {
|
||||
|
||||
void begin();
|
||||
|
||||
bool hasSubscribers(const char *event);
|
||||
|
||||
void onEvent(String event, EventCallback callback);
|
||||
|
||||
void onSubscribe(String event, SubscribeCallback callback);
|
||||
|
||||
Reference in New Issue
Block a user