From 737aa148dada648a9c71d0c380c15f76c594591e 2016-01-18 13:19:18 From: Jan Kaluza Date: 2016-01-18 13:19:18 Subject: [PATCH] Slack: Stop sending pings when disconnected from RTM --- diff --git a/include/transport/WebSocketClient.h b/include/transport/WebSocketClient.h index c078900ee02629e05c37075b8b8f19e7578256f6..bdfa7dbc8cccd3f9758ab2e81421336538e43806 100644 --- a/include/transport/WebSocketClient.h +++ b/include/transport/WebSocketClient.h @@ -61,6 +61,7 @@ class WebSocketClient { boost::signal onPayloadReceived; boost::signal onWebSocketConnected; + boost::signal &error)> onWebSocketDisconnected; private: void handleDNSResult(const std::vector&, boost::optional); diff --git a/libtransport/WebSocketClient.cpp b/libtransport/WebSocketClient.cpp index f21abe27cd52d7785b8508e6a7e78eae43093c34..36c9335ee8c755377454c2196e2c759d0789cce6 100644 --- a/libtransport/WebSocketClient.cpp +++ b/libtransport/WebSocketClient.cpp @@ -218,6 +218,7 @@ void WebSocketClient::handleDisconnected(const boost::optionalstart(); } diff --git a/spectrum/src/frontends/slack/SlackRTM.cpp b/spectrum/src/frontends/slack/SlackRTM.cpp index e7280422c5c890a727e927491fc97b9f18f5507d..98a19205b6d4525d8926ced88c695e21eefe2632 100644 --- a/spectrum/src/frontends/slack/SlackRTM.cpp +++ b/spectrum/src/frontends/slack/SlackRTM.cpp @@ -42,6 +42,7 @@ SlackRTM::SlackRTM(Component *component, StorageBackend *storageBackend, UserInf m_component = component; m_storageBackend = storageBackend; m_counter = 0; + m_started = false; m_client = new WebSocketClient(component); m_client->onPayloadReceived.connect(boost::bind(&SlackRTM::handlePayloadReceived, this, _1)); m_client->onWebSocketConnected.connect(boost::bind(&SlackRTM::handleWebSocketConnected, this)); @@ -192,11 +193,19 @@ void SlackRTM::handleRTMStart(HTTPRequest *req, bool ok, rapidjson::Document &re LOG4CXX_INFO(logger, data); m_client->connectServer(u); - m_pingTimer->start(); } void SlackRTM::handleWebSocketConnected() { - onRTMStarted(); + if (!m_started) { + onRTMStarted(); + m_started = true; + } + + m_pingTimer->start(); +} + +void SlackRTM::handleWebSocketDisconnected(const boost::optional &error) { + m_pingTimer->stop(); } diff --git a/spectrum/src/frontends/slack/SlackRTM.h b/spectrum/src/frontends/slack/SlackRTM.h index c8cc7e25901d8ea35704ac20c099b23f9fdd1269..e244718a3c3dcbbdf9274652de3306a65e6c5508 100644 --- a/spectrum/src/frontends/slack/SlackRTM.h +++ b/spectrum/src/frontends/slack/SlackRTM.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "Swiften/Network/Timer.h" #include "Swiften/Version.h" @@ -92,6 +93,7 @@ class SlackRTM { void handlePayloadReceived(const std::string &payload); void handleRTMStart(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data); void handleWebSocketConnected(); + void handleWebSocketDisconnected(const boost::optional &error); private: std::map m_channels; @@ -108,6 +110,7 @@ class SlackRTM { unsigned long m_counter; Swift::Timer::ref m_pingTimer; SlackAPI *m_api; + bool m_started; }; }