Send pings only when we are connected
This commit is contained in:
parent
fe16d52b7b
commit
a404195a0a
2 changed files with 10 additions and 4 deletions
|
@ -97,7 +97,6 @@ class Connection(slixmpp.ClientXMPP):
|
||||||
|
|
||||||
self.register_plugin('xep_0191')
|
self.register_plugin('xep_0191')
|
||||||
self.register_plugin('xep_0199')
|
self.register_plugin('xep_0199')
|
||||||
self.set_keepalive_values()
|
|
||||||
|
|
||||||
if config.get('enable_user_tune', True):
|
if config.get('enable_user_tune', True):
|
||||||
self.register_plugin('xep_0118')
|
self.register_plugin('xep_0118')
|
||||||
|
@ -137,11 +136,14 @@ class Connection(slixmpp.ClientXMPP):
|
||||||
|
|
||||||
def set_keepalive_values(self, option=None, value=None):
|
def set_keepalive_values(self, option=None, value=None):
|
||||||
"""
|
"""
|
||||||
Called at startup, or triggered when one of
|
Called after the XMPP session has been started, or triggered when one of
|
||||||
"connection_timeout_delay" and "connection_check_interval" options
|
"connection_timeout_delay" and "connection_check_interval" options
|
||||||
is changed.
|
is changed. Unload and reload the ping plugin, with the new values.
|
||||||
Unload and reload the ping plugin, with the new values.
|
|
||||||
"""
|
"""
|
||||||
|
if not self.is_connected():
|
||||||
|
# Happens when we change the value with /set while we are not
|
||||||
|
# connected. Do nothing in that case
|
||||||
|
return
|
||||||
ping_interval = config.get('connection_check_interval', 60)
|
ping_interval = config.get('connection_check_interval', 60)
|
||||||
timeout_delay = config.get('connection_timeout_delay', 10)
|
timeout_delay = config.get('connection_timeout_delay', 10)
|
||||||
if timeout_delay <= 0:
|
if timeout_delay <= 0:
|
||||||
|
|
|
@ -822,6 +822,8 @@ def on_disconnected(self, event):
|
||||||
"""
|
"""
|
||||||
When we are disconnected from remote server
|
When we are disconnected from remote server
|
||||||
"""
|
"""
|
||||||
|
# Stop the ping plugin. It would try to send stanza on regular basis
|
||||||
|
self.xmpp.plugin['xep_0199'].disable_keepalive()
|
||||||
roster.modified()
|
roster.modified()
|
||||||
for tab in self.get_tabs(tabs.MucTab):
|
for tab in self.get_tabs(tabs.MucTab):
|
||||||
tab.disconnect()
|
tab.disconnect()
|
||||||
|
@ -892,6 +894,8 @@ def on_session_start(self, event):
|
||||||
if config.get('enable_user_nick', True):
|
if config.get('enable_user_nick', True):
|
||||||
self.xmpp.plugin['xep_0172'].publish_nick(nick=self.own_nick, callback=dumb_callback)
|
self.xmpp.plugin['xep_0172'].publish_nick(nick=self.own_nick, callback=dumb_callback)
|
||||||
self.xmpp.plugin['xep_0115'].update_caps()
|
self.xmpp.plugin['xep_0115'].update_caps()
|
||||||
|
# Start the ping's plugin regular event
|
||||||
|
self.xmpp.set_keepalive_values()
|
||||||
|
|
||||||
### Other handlers ###
|
### Other handlers ###
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue