🚇 Adds hasSubcribers to event socket for early return

This commit is contained in:
Rune Harlyk
2024-08-02 15:35:36 +02:00
committed by Rune Harlyk
parent d182e9e925
commit e7f78c52da
3 changed files with 5 additions and 0 deletions
@@ -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);
+2
View File
@@ -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);