99#include < QHostInfo>
1010
1111#include < api/HyperAPI.h>
12+ #include < utils/GlobalSignals.h>
1213
1314// default param %1 is 'HyperHDR', do not edit templates here
1415const static QString TEMPLATE_HYPERHDRAPI = QStringLiteral(" %1/JsonAPI" );
@@ -114,6 +115,8 @@ void mqtt::connected()
114115{
115116 Debug (_log, " Connected" );
116117
118+ connect (GlobalSignals::getInstance (), &GlobalSignals::SignalMqttSubscribe, this , &mqtt::handleSignalMqttSubscribe);
119+
117120 if (_retryTimer != nullptr )
118121 {
119122 Debug (_log, " Removing retry timer" );
@@ -122,12 +125,26 @@ void mqtt::connected()
122125 _retryTimer = nullptr ;
123126 }
124127
125- if (_clientInstance != nullptr )
128+ if (_clientInstance != nullptr && !_disableApiAccess )
126129 {
127130 _clientInstance->subscribe (HYPERHDRAPI, 2 );
128131 }
129132}
130133
134+ void mqtt::handleSignalMqttSubscribe (bool subscribe, QString topic)
135+ {
136+ if (_clientInstance == nullptr )
137+ return ;
138+
139+ if (subscribe)
140+ {
141+ _clientInstance->subscribe (topic, 2 );
142+ }
143+ else
144+ {
145+ _clientInstance->unsubscribe (topic);
146+ }
147+ }
131148
132149void mqtt::error (const QMQTT::ClientError error)
133150{
@@ -307,4 +324,8 @@ void mqtt::received(const QMQTT::Message& message)
307324 }
308325 _clientInstance->publish (result);
309326 }
327+ else
328+ {
329+ emit GlobalSignals::getInstance ()->SignalMqttReceived (topic, payload);
330+ }
310331}
0 commit comments