comparison 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
comparison
equal deleted inserted replaced
4111:a8ac5e1e5848 4112:bc60875cb3b8
30 from wokkel import disco, iwokkel 30 from wokkel import disco, iwokkel
31 from zope.interface import implementer 31 from zope.interface import implementer
32 32
33 from libervia.backend.core import exceptions 33 from libervia.backend.core import exceptions
34 from libervia.backend.core.constants import Const as C 34 from libervia.backend.core.constants import Const as C
35 from libervia.backend.core.core_types import SatXMPPEntity
35 from libervia.backend.core.i18n import D_, _ 36 from libervia.backend.core.i18n import D_, _
36 from libervia.backend.core.log import getLogger 37 from libervia.backend.core.log import getLogger
38 from libervia.backend.tools import xml_tools
37 from libervia.backend.tools import utils 39 from libervia.backend.tools import utils
38 from libervia.backend.tools import stream 40 from libervia.backend.tools import stream
39 from libervia.backend.tools.common import date_utils 41 from libervia.backend.tools.common import date_utils
40 from libervia.backend.tools.common import regex 42 from libervia.backend.tools.common import regex
43
44 from .plugin_xep_0166 import BaseApplicationHandler
41 45
42 46
43 log = getLogger(__name__) 47 log = getLogger(__name__)
44 48
45 NS_JINGLE_FT = "urn:xmpp:jingle:apps:file-transfer:5" 49 NS_JINGLE_FT = "urn:xmpp:jingle:apps:file-transfer:5"
58 62
59 EXTRA_ALLOWED = {"path", "namespace", "file_desc", "file_hash", "hash_algo"} 63 EXTRA_ALLOWED = {"path", "namespace", "file_desc", "file_hash", "hash_algo"}
60 Range = namedtuple("Range", ("offset", "length")) 64 Range = namedtuple("Range", ("offset", "length"))
61 65
62 66
63 class XEP_0234: 67 class XEP_0234(BaseApplicationHandler):
64 # TODO: assure everything is closed when file is sent or session terminate is received 68 # TODO: assure everything is closed when file is sent or session terminate is received
65 # TODO: call self._f.unregister when unloading order will be managing (i.e. when 69 # TODO: call self._f.unregister when unloading order will be managing (i.e. when
66 # dependencies will be unloaded at the end) 70 # dependencies will be unloaded at the end)
67 Range = Range # we copy the class here, so it can be used by other plugins 71 Range = Range # we copy the class here, so it can be used by other plugins
68 name = PLUGIN_INFO[C.PI_NAME] 72 name = PLUGIN_INFO[C.PI_NAME]
404 ], 408 ],
405 ) 409 )
406 return await progress_id_d 410 return await progress_id_d
407 411
408 # jingle callbacks 412 # jingle callbacks
413
414 async def jingle_preflight(
415 self,
416 client: SatXMPPEntity,
417 session: dict,
418 description_elt: domish.Element
419 ) -> None:
420 """Perform preflight checks for an incoming call session.
421
422 Check if the calls is audio only or audio/video, then, prompts the user for
423 confirmation.
424
425 @param client: The client instance.
426 @param session: Jingle session.
427 @param description_elt: The description element. It's parent attribute is used to
428 determine check siblings to see if it's an audio only or audio/video call.
429
430 @raises exceptions.CancelError: If the user doesn't accept the incoming call.
431 """
432 session_id = session["id"]
433 peer_jid = session["peer_jid"]
434 # FIXME: has been moved from XEP-0353, but it doesn't handle correctly file
435 # transfer (metadata are not used). We must check with other clients what is
436 # actually send, and if XEP-0353 is used, and do a better integration.
437
438 if client.roster and peer_jid.userhostJID() not in client.roster:
439 confirm_msg = D_(
440 "Somebody not in your contact list ({peer_jid}) wants to do a "
441 '"{human_name}" session with you, this would leak your presence and '
442 "possibly you IP (internet localisation), do you accept?"
443 ).format(peer_jid=peer_jid, human_name=self.human_name)
444 confirm_title = D_("File sent from an unknown contact")
445 action_type = C.META_TYPE_NOT_IN_ROSTER_LEAK
446 else:
447 confirm_msg = D_(
448 "{peer_jid} wants to send a file ro you, do you accept?"
449 ).format(peer_jid=peer_jid)
450 confirm_title = D_("File Proposed")
451 action_type = C.META_TYPE_FILE
452 accepted = await xml_tools.defer_confirm(
453 self.host,
454 confirm_msg,
455 confirm_title,
456 profile=client.profile,
457 action_extra={
458 "type": action_type,
459 "session_id": session_id,
460 "from_jid": peer_jid.full(),
461 },
462 )
463 if accepted:
464 session["file_accepted"] = True
465 return accepted
466
467 async def jingle_preflight_cancel(
468 self,
469 client: SatXMPPEntity,
470 session: dict,
471 cancel_error: exceptions.CancelError
472 ) -> None:
473 pass
409 474
410 def jingle_description_elt( 475 def jingle_description_elt(
411 self, client, session, content_name, filepath, name, extra, progress_id_d 476 self, client, session, content_name, filepath, name, extra, progress_id_d
412 ): 477 ):
413 return domish.Element((NS_JINGLE_FT, "description")) 478 return domish.Element((NS_JINGLE_FT, "description"))