diff options
Diffstat (limited to 'remoting/jingle_glue')
-rw-r--r-- | remoting/jingle_glue/xmpp_signal_strategy.cc | 15 | ||||
-rw-r--r-- | remoting/jingle_glue/xmpp_signal_strategy.h | 5 |
2 files changed, 20 insertions, 0 deletions
diff --git a/remoting/jingle_glue/xmpp_signal_strategy.cc b/remoting/jingle_glue/xmpp_signal_strategy.cc index 977cc21..1aa7d9c 100644 --- a/remoting/jingle_glue/xmpp_signal_strategy.cc +++ b/remoting/jingle_glue/xmpp_signal_strategy.cc @@ -13,7 +13,13 @@ #include "third_party/libjingle/source/talk/xmpp/saslcookiemechanism.h" namespace { + const char kDefaultResourceName[] = "chromoting"; + +// Use 58 seconds keep-alive interval, in case routers terminate +// connections that are idle for more than a minute. +const int kKeepAliveIntervalSeconds = 50; + } // namespace namespace remoting { @@ -149,6 +155,9 @@ void XmppSignalStrategy::OnConnectionStateChanged( buzz::XmppEngine::State state) { DCHECK(CalledOnValidThread()); if (state == buzz::XmppEngine::STATE_OPEN) { + keep_alive_timer_.Start( + FROM_HERE, base::TimeDelta::FromSeconds(kKeepAliveIntervalSeconds), + this, &XmppSignalStrategy::SendKeepAlive); SetState(CONNECTED); } else if (state == buzz::XmppEngine::STATE_CLOSED) { // Make sure we dump errors to the log. @@ -157,6 +166,8 @@ void XmppSignalStrategy::OnConnectionStateChanged( LOG(INFO) << "XMPP connection was closed: error=" << error << ", subcode=" << subcode; + keep_alive_timer_.Stop(); + // Client is destroyed by the TaskRunner after the client is // closed. Reset the pointer so we don't try to use it later. xmpp_client_ = NULL; @@ -172,6 +183,10 @@ void XmppSignalStrategy::SetState(State new_state) { } } +void XmppSignalStrategy::SendKeepAlive() { + xmpp_client_->SendRaw(" "); +} + // static buzz::PreXmppAuth* XmppSignalStrategy::CreatePreXmppAuth( const buzz::XmppClientSettings& settings) { diff --git a/remoting/jingle_glue/xmpp_signal_strategy.h b/remoting/jingle_glue/xmpp_signal_strategy.h index 361aac8..ec405a4 100644 --- a/remoting/jingle_glue/xmpp_signal_strategy.h +++ b/remoting/jingle_glue/xmpp_signal_strategy.h @@ -16,6 +16,7 @@ #include "base/compiler_specific.h" #include "base/observer_list.h" +#include "base/timer.h" #include "base/threading/non_thread_safe.h" #include "third_party/libjingle/source/talk/base/sigslot.h" #include "third_party/libjingle/source/talk/xmpp/xmppclient.h" @@ -66,6 +67,8 @@ class XmppSignalStrategy : public base::NonThreadSafe, void OnConnectionStateChanged(buzz::XmppEngine::State state); void SetState(State new_state); + void SendKeepAlive(); + JingleThread* thread_; std::string username_; @@ -78,6 +81,8 @@ class XmppSignalStrategy : public base::NonThreadSafe, ObserverList<Listener> listeners_; + base::RepeatingTimer<XmppSignalStrategy> keep_alive_timer_; + DISALLOW_COPY_AND_ASSIGN(XmppSignalStrategy); }; |