diff --git a/src/WebSocket.h b/src/WebSocket.h index 8d37557..ee05b8b 100644 --- a/src/WebSocket.h +++ b/src/WebSocket.h @@ -198,6 +198,17 @@ public: return webSocketContextData->topicTree.unsubscribe(topic, webSocketData->subscriber); } + /* Unsubscribe from all topics you might be subscribed to */ + void unsubscribeAll() { + WebSocketContextData *webSocketContextData = (WebSocketContextData *) us_socket_context_ext(SSL, + (us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this) + ); + + WebSocketData *webSocketData = (WebSocketData *) us_socket_ext(SSL, (us_socket_t *) this); + + webSocketContextData->topicTree.unsubscribeAll(webSocketData->subscriber); + } + /* Publish a message to a topic according to MQTT rules and syntax */ void publish(std::string_view topic, std::string_view message, OpCode opCode = OpCode::TEXT, bool compress = false) { WebSocketContextData *webSocketContextData = (WebSocketContextData *) us_socket_context_ext(SSL,