From 286b2f2f1f4d468929c191e833b46977ff3f8696 Mon Sep 17 00:00:00 2001 From: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com> Date: Sun, 8 Jan 2023 23:38:08 +0100 Subject: [PATCH] Also emit subscription events from close handler --- src/WebSocketContext.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/WebSocketContext.h b/src/WebSocketContext.h index f5d0196..63f570f 100644 --- a/src/WebSocketContext.h +++ b/src/WebSocketContext.h @@ -258,6 +258,13 @@ private: /* Emit close event */ auto *webSocketContextData = (WebSocketContextData *) us_socket_context_ext(SSL, us_socket_context(SSL, (us_socket_t *) s)); + /* At this point we iterate all currently held subscriptions and emit an event for all of them */ + if (webSocketData->subscriber && webSocketContextData->subscriptionHandler) { + for (Topic *t : webSocketData->subscriber->topics) { + webSocketContextData->subscriptionHandler(this, t->name, (int) t->size() - 1, (int) t->size()); + } + } + /* Make sure to unsubscribe from any pub/sub node at exit */ webSocketContextData->topicTree->freeSubscriber(webSocketData->subscriber); webSocketData->subscriber = nullptr;