Improve connectivity handling (Thank you. mathieui).
This commit is contained in:
parent
3fa7aa9b40
commit
a6ef961a55
2 changed files with 13 additions and 12 deletions
blasta
|
@ -1274,20 +1274,21 @@ class HttpInstance:
|
||||||
response: Response,
|
response: Response,
|
||||||
jabber_id: str = Form(...),
|
jabber_id: str = Form(...),
|
||||||
password: str = Form(...)):
|
password: str = Form(...)):
|
||||||
|
request_url_path = request.url.path
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug(f'{function_name},{jabber_id},Start')
|
logger.debug(f'{function_name},{request_url_path},Start')
|
||||||
if not UtilitiesHttp.is_jid_matches_to_session(accounts, sessions, request):
|
if not UtilitiesHttp.is_jid_matches_to_session(accounts, sessions, request):
|
||||||
# Store a variable in the request's state
|
# Store a variable in the request's state
|
||||||
request.app.state.jabber_id = jabber_id
|
request.app.state.jabber_id = jabber_id
|
||||||
session_key = str(random.random())
|
session_key = str(random.random())
|
||||||
request.app.state.session_key = session_key
|
request.app.state.session_key = session_key
|
||||||
accounts[jabber_id] = XmppInstance(jabber_id + '/blasta', password)
|
accounts[jabber_id] = XmppInstance(jabber_id + '/blasta', password)
|
||||||
breakpoint()
|
if accounts[jabber_id].is_connected:
|
||||||
# accounts[jabber_id].authenticated
|
|
||||||
# dir(accounts[jabber_id])
|
|
||||||
# accounts[jabber_id].failed_auth
|
|
||||||
# accounts[jabber_id].event_when_connected
|
|
||||||
sessions[jabber_id] = session_key
|
sessions[jabber_id] = session_key
|
||||||
|
else:
|
||||||
|
del accounts[jabber_id]
|
||||||
|
jabber_id = None
|
||||||
|
|
||||||
# Check if the user and password are present and valid
|
# Check if the user and password are present and valid
|
||||||
# If not valid, return "Could not connect to JID"
|
# If not valid, return "Could not connect to JID"
|
||||||
|
|
||||||
|
@ -1348,7 +1349,7 @@ class HttpInstance:
|
||||||
message = 'Blasta system message » Authorization has failed.'
|
message = 'Blasta system message » Authorization has failed.'
|
||||||
description = 'Connection has failed'
|
description = 'Connection has failed'
|
||||||
path = 'error'
|
path = 'error'
|
||||||
logger.error(f'{function_name},{request_url_path},{description}')
|
logger.error(f'{function_name},{jabber_id},{description}')
|
||||||
response = result_post(request, jabber_id, description, message, path)
|
response = result_post(request, jabber_id, description, message, path)
|
||||||
logger.debug(f'{function_name},{request_url_path},Finish')
|
logger.debug(f'{function_name},{request_url_path},Finish')
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -24,22 +24,22 @@ class XmppInstance(ClientXMPP):
|
||||||
self.register_plugin('xep_0163') # XEP-0163: Personal Eventing Protocol
|
self.register_plugin('xep_0163') # XEP-0163: Personal Eventing Protocol
|
||||||
self.register_plugin('xep_0223') # XEP-0223: Persistent Storage of Private Data via PubSub
|
self.register_plugin('xep_0223') # XEP-0223: Persistent Storage of Private Data via PubSub
|
||||||
self.connect()
|
self.connect()
|
||||||
self.connection_accepted = False
|
self.is_connected = False
|
||||||
|
|
||||||
def on_connection_failed(self, event):
|
def on_connection_failed(self, event):
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug(f'{function_name},{event},Start')
|
logger.debug(f'{function_name},{event},Start')
|
||||||
self.connection_accepted = False
|
self.is_connected = False
|
||||||
logger.debug(f'{function_name},{event},Finish')
|
logger.debug(f'{function_name},{event},Finish')
|
||||||
|
|
||||||
def on_failed_auth(self, event):
|
def on_failed_auth(self, event):
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug(f'{function_name},{event},Start')
|
logger.debug(f'{function_name},{event},Start')
|
||||||
self.connection_accepted = False
|
self.is_connected = False
|
||||||
logger.debug(f'{function_name},{event},Finish')
|
logger.debug(f'{function_name},{event},Finish')
|
||||||
|
|
||||||
def on_session_start(self, event):
|
def on_session_start(self, event):
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug(f'{function_name},{event},Start')
|
logger.debug(f'{function_name},{event},Start')
|
||||||
self.connection_accepted = True
|
self.is_connected = True
|
||||||
logger.debug(f'{function_name},{event},Finish')
|
logger.debug(f'{function_name},{event},Finish')
|
||||||
|
|
Loading…
Add table
Reference in a new issue