Blasta/blasta/xmpp/instance.py

46 lines
1.9 KiB
Python
Raw Normal View History

#!/usr/bin/python
# -*- coding: utf-8 -*-
2025-03-10 10:35:21 +02:00
from blasta.utilities.logger import UtilitiesLogger
from slixmpp import ClientXMPP
2025-03-10 10:35:21 +02:00
import sys
logger = UtilitiesLogger(__name__)
class XmppInstance(ClientXMPP):
2025-03-10 10:35:21 +02:00
def __init__(self, jid, password):
2025-03-10 10:35:21 +02:00
function_name = sys._getframe().f_code.co_name
logger.debug(f'{function_name},{jid},Start')
super().__init__(jid, password)
2025-03-10 10:35:21 +02:00
self.add_event_handler("connection_failed", self.on_connection_failed)
self.add_event_handler("failed_auth", self.on_failed_auth)
self.add_event_handler("session_start", self.on_session_start)
self.register_plugin('xep_0004') # XEP-0004: Data Forms
self.register_plugin('xep_0030') # XEP-0030: Service Discovery
self.register_plugin('xep_0059') # XEP-0059: Result Set Management
self.register_plugin('xep_0060') # XEP-0060: Publish-Subscribe
self.register_plugin('xep_0078') # XEP-0078: Non-SASL Authentication
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.connect()
self.connection_accepted = False
2025-03-10 10:35:21 +02:00
def on_connection_failed(self, event):
function_name = sys._getframe().f_code.co_name
logger.debug(f'{function_name},{event},Start')
self.connection_accepted = False
logger.debug(f'{function_name},{event},Finish')
2025-03-10 10:35:21 +02:00
def on_failed_auth(self, event):
function_name = sys._getframe().f_code.co_name
logger.debug(f'{function_name},{event},Start')
self.connection_accepted = False
logger.debug(f'{function_name},{event},Finish')
def on_session_start(self, event):
2025-03-10 10:35:21 +02:00
function_name = sys._getframe().f_code.co_name
logger.debug(f'{function_name},{event},Start')
self.connection_accepted = True
2025-03-10 10:35:21 +02:00
logger.debug(f'{function_name},{event},Finish')