comparison sat/plugins/plugin_xep_0353.py @ 3517:8508fab9bcc2

plugin XEP-0353: don't use Jingle Message Initiation for components: Jingle Message Initiation is currently not useful for components, and the message workflow is different in Libervia between clients and components (as a result, `messageReceived` trigger is never called, and the session proposal is never answered).
author Goffi <goffi@goffi.org>
date Sat, 01 May 2021 18:30:01 +0200
parents be6d91572633
children 867a15f05476
comparison
equal deleted inserted replaced
3516:e47aa1fb7b24 3517:8508fab9bcc2
36 36
37 PLUGIN_INFO = { 37 PLUGIN_INFO = {
38 C.PI_NAME: "Jingle Message Initiation", 38 C.PI_NAME: "Jingle Message Initiation",
39 C.PI_IMPORT_NAME: "XEP-0353", 39 C.PI_IMPORT_NAME: "XEP-0353",
40 C.PI_TYPE: "XEP", 40 C.PI_TYPE: "XEP",
41 C.PI_MODES: C.PLUG_MODE_BOTH, 41 C.PI_MODES: C.PLUG_MODE_CLIENT,
42 C.PI_PROTOCOLS: ["XEP-0353"], 42 C.PI_PROTOCOLS: ["XEP-0353"],
43 C.PI_DEPENDENCIES: ["XEP-0166"], 43 C.PI_DEPENDENCIES: ["XEP-0166"],
44 C.PI_MAIN: "XEP_0353", 44 C.PI_MAIN: "XEP_0353",
45 C.PI_HANDLER: "yes", 45 C.PI_HANDLER: "yes",
46 C.PI_DESCRIPTION: _("""Implementation of Jingle Message Initiation"""), 46 C.PI_DESCRIPTION: _("""Implementation of Jingle Message Initiation"""),
47 } 47 }
48 48
49 49
50 class XEP_0353(object): 50 class XEP_0353:
51 51
52 def __init__(self, host): 52 def __init__(self, host):
53 log.info(_("plugin {name} initialization").format(name=PLUGIN_INFO[C.PI_NAME])) 53 log.info(_("plugin {name} initialization").format(name=PLUGIN_INFO[C.PI_NAME]))
54 self.host = host 54 self.host = host
55 host.registerNamespace("jingle-message", NS_JINGLE_MESSAGE) 55 host.registerNamespace("jingle-message", NS_JINGLE_MESSAGE)
78 verb_elt = mess_data["xml"].addElement((NS_JINGLE_MESSAGE, verb)) 78 verb_elt = mess_data["xml"].addElement((NS_JINGLE_MESSAGE, verb))
79 verb_elt["id"] = session_id 79 verb_elt["id"] = session_id
80 return mess_data 80 return mess_data
81 81
82 async def _onInitiateTrigger(self, client, session, contents): 82 async def _onInitiateTrigger(self, client, session, contents):
83 # FIXME: check that at least one resource of the peer_jid can handle the feature
83 peer_jid = session['peer_jid'] 84 peer_jid = session['peer_jid']
84 if peer_jid.resource: 85 if peer_jid.resource:
86 return True
87
88 infos = await self.host.memory.disco.getInfos(client, peer_jid)
89 categories = {c for c, __ in infos.identities}
90 if "component" in categories:
91 # we don't use message initiation with components
85 return True 92 return True
86 93
87 if peer_jid.userhostJID() not in client.roster: 94 if peer_jid.userhostJID() not in client.roster:
88 # if the contact is not in our roster, we need to send a directed presence 95 # if the contact is not in our roster, we need to send a directed presence
89 # according to XEP-0353 §3.1 96 # according to XEP-0353 §3.1