First implementation of auto_reconnect, poezio-side
This commit is contained in:
parent
2fd71cd637
commit
df569d4e66
3 changed files with 21 additions and 1 deletions
|
@ -58,7 +58,6 @@ class Connection(slixmpp.ClientXMPP):
|
|||
self['feature_mechanisms'].unencrypted_scram = False
|
||||
|
||||
self.core = None
|
||||
self.auto_reconnect = config.get('auto_reconnect', False)
|
||||
self.reconnect_max_attempts = 0
|
||||
self.auto_authorize = None
|
||||
# prosody defaults, lowest is AES128-SHA, it should be a minimum
|
||||
|
|
|
@ -110,6 +110,13 @@ class Core(object):
|
|||
|
||||
self.size = SizeManager(self, windows.Win)
|
||||
|
||||
# Set to True whenever we consider that we have been disconnected
|
||||
# from the server because of a legitimate reason (bad credentials,
|
||||
# or explicit disconnect from the user for example), in that case we
|
||||
# should not try to auto-reconnect, even if auto_reconnect is true
|
||||
# in the user config.
|
||||
self.legitimate_disconnect = False
|
||||
|
||||
# global commands, available from all tabs
|
||||
# a command is tuple of the form:
|
||||
# (the function executing the command. Takes a string as argument,
|
||||
|
@ -190,6 +197,7 @@ class Core(object):
|
|||
self.key_func.update(key_func)
|
||||
|
||||
# Add handlers
|
||||
self.xmpp.add_event_handler('connecting', self.on_connecting)
|
||||
self.xmpp.add_event_handler('connected', self.on_connected)
|
||||
self.xmpp.add_event_handler('connection_failed', self.on_failed_connection)
|
||||
self.xmpp.add_event_handler('disconnected', self.on_disconnected)
|
||||
|
@ -793,6 +801,7 @@ class Core(object):
|
|||
Disconnect from remote server and correctly set the states of all
|
||||
parts of the client (for example, set the MucTabs as not joined, etc)
|
||||
"""
|
||||
self.legitimate_disconnect = True
|
||||
msg = msg or ''
|
||||
for tab in self.get_tabs(tabs.MucTab):
|
||||
tab.command_part(msg)
|
||||
|
@ -1900,6 +1909,7 @@ class Core(object):
|
|||
on_failed_all_auth = handlers.on_failed_all_auth
|
||||
on_no_auth = handlers.on_no_auth
|
||||
on_connected = handlers.on_connected
|
||||
on_connecting = handlers.on_connecting
|
||||
on_session_start = handlers.on_session_start
|
||||
on_status_codes = handlers.on_status_codes
|
||||
on_groupchat_subject = handlers.on_groupchat_subject
|
||||
|
|
|
@ -828,6 +828,9 @@ def on_disconnected(self, event):
|
|||
for tab in self.get_tabs(tabs.MucTab):
|
||||
tab.disconnect()
|
||||
self.information(_("Disconnected from server."), _('Error'))
|
||||
if not self.legitimate_disconnect and config.get('auto_reconnect', False):
|
||||
self.information(_("Auto-reconnecting."), _('Info'))
|
||||
self.xmpp.connect()
|
||||
|
||||
def on_failed_all_auth(self, event):
|
||||
"""
|
||||
|
@ -835,6 +838,7 @@ def on_failed_all_auth(self, event):
|
|||
"""
|
||||
self.information(_("Authentication failed (bad credentials?)."),
|
||||
_('Error'))
|
||||
self.legitimate_disconnect = True
|
||||
|
||||
def on_no_auth(self, event):
|
||||
"""
|
||||
|
@ -842,6 +846,7 @@ def on_no_auth(self, event):
|
|||
"""
|
||||
self.information(_("Authentication failed, no login method available."),
|
||||
_('Error'))
|
||||
self.legitimate_disconnect = True
|
||||
|
||||
def on_connected(self, event):
|
||||
"""
|
||||
|
@ -849,6 +854,12 @@ def on_connected(self, event):
|
|||
"""
|
||||
self.information(_("Connected to server."), 'Info')
|
||||
|
||||
def on_connecting(self, event):
|
||||
"""
|
||||
Just before we try to connect to the server
|
||||
"""
|
||||
self.legitimate_disconnect = False
|
||||
|
||||
def on_session_start(self, event):
|
||||
"""
|
||||
Called when we are connected and authenticated
|
||||
|
|
Loading…
Reference in a new issue