Mercurial > libervia-backend
diff libervia/backend/plugins/plugin_xep_0234.py @ 4112:bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
- XEP-0166: add `jingle_preflight` and `jingle_preflight_cancel` methods to prepare a
jingle session, principally used by XEP-0353 to create and cancel a session
- XEP-0167: preflight methods implementation, workflow split in more methods/signals to
handle UI and call events (e.g.: retract or reject a call)
- XEP-0234: implementation of preflight methods as they are now mandatory
- XEP-0353: handle various events using the new preflight methods
rel 423
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 09 Aug 2023 00:07:37 +0200 |
parents | 4b842c1fb686 |
children | 0da563780ffc |
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_xep_0234.py Tue Aug 08 23:59:24 2023 +0200 +++ b/libervia/backend/plugins/plugin_xep_0234.py Wed Aug 09 00:07:37 2023 +0200 @@ -32,13 +32,17 @@ from libervia.backend.core import exceptions from libervia.backend.core.constants import Const as C +from libervia.backend.core.core_types import SatXMPPEntity from libervia.backend.core.i18n import D_, _ from libervia.backend.core.log import getLogger +from libervia.backend.tools import xml_tools from libervia.backend.tools import utils from libervia.backend.tools import stream from libervia.backend.tools.common import date_utils from libervia.backend.tools.common import regex +from .plugin_xep_0166 import BaseApplicationHandler + log = getLogger(__name__) @@ -60,7 +64,7 @@ Range = namedtuple("Range", ("offset", "length")) -class XEP_0234: +class XEP_0234(BaseApplicationHandler): # TODO: assure everything is closed when file is sent or session terminate is received # TODO: call self._f.unregister when unloading order will be managing (i.e. when # dependencies will be unloaded at the end) @@ -407,6 +411,67 @@ # jingle callbacks + async def jingle_preflight( + self, + client: SatXMPPEntity, + session: dict, + description_elt: domish.Element + ) -> None: + """Perform preflight checks for an incoming call session. + + Check if the calls is audio only or audio/video, then, prompts the user for + confirmation. + + @param client: The client instance. + @param session: Jingle session. + @param description_elt: The description element. It's parent attribute is used to + determine check siblings to see if it's an audio only or audio/video call. + + @raises exceptions.CancelError: If the user doesn't accept the incoming call. + """ + session_id = session["id"] + peer_jid = session["peer_jid"] + # FIXME: has been moved from XEP-0353, but it doesn't handle correctly file + # transfer (metadata are not used). We must check with other clients what is + # actually send, and if XEP-0353 is used, and do a better integration. + + if client.roster and peer_jid.userhostJID() not in client.roster: + confirm_msg = D_( + "Somebody not in your contact list ({peer_jid}) wants to do a " + '"{human_name}" session with you, this would leak your presence and ' + "possibly you IP (internet localisation), do you accept?" + ).format(peer_jid=peer_jid, human_name=self.human_name) + confirm_title = D_("File sent from an unknown contact") + action_type = C.META_TYPE_NOT_IN_ROSTER_LEAK + else: + confirm_msg = D_( + "{peer_jid} wants to send a file ro you, do you accept?" + ).format(peer_jid=peer_jid) + confirm_title = D_("File Proposed") + action_type = C.META_TYPE_FILE + accepted = await xml_tools.defer_confirm( + self.host, + confirm_msg, + confirm_title, + profile=client.profile, + action_extra={ + "type": action_type, + "session_id": session_id, + "from_jid": peer_jid.full(), + }, + ) + if accepted: + session["file_accepted"] = True + return accepted + + async def jingle_preflight_cancel( + self, + client: SatXMPPEntity, + session: dict, + cancel_error: exceptions.CancelError + ) -> None: + pass + def jingle_description_elt( self, client, session, content_name, filepath, name, extra, progress_id_d ):