comparison sat/plugins/plugin_xep_0353.py @ 4044:3900626bc100

plugin XEP-0166: refactoring, and various improvments: - add models for transport and applications handlers and linked data - split models into separate file - some type hints - some documentation comments - add actions to prepare confirmation, useful to do initial parsing of all contents - application arg/kwargs and some transport data can be initialised during Jingle `initiate` call, this is notably useful when a call is made with transport data (this is the call for A/V calls where codecs and ICE candidate can be specified when starting a call) - session data can be specified during Jingle `initiate` call - new `store_in_session` argument in `_parse_elements`, which can be used to avoid race-condition when a context element (<decription> or <transport>) is being parsed for an action while an other action happens (like `transport-info`) - don't sed `sid` in `transport_elt` during a `transport-info` action anymore in `build_action`: this is specific to Jingle File Transfer and has been moved there rel 419
author Goffi <goffi@goffi.org>
date Mon, 15 May 2023 16:23:11 +0200
parents 877145b4ba01
children c23cad65ae99
comparison
equal deleted inserted replaced
4043:9641ce286e07 4044:3900626bc100
103 # according to XEP-0353 §3.1 103 # according to XEP-0353 §3.1
104 await client.presence.available(peer_jid) 104 await client.presence.available(peer_jid)
105 105
106 mess_data = self.build_message_data(client, peer_jid, "propose", session['id']) 106 mess_data = self.build_message_data(client, peer_jid, "propose", session['id'])
107 for content in contents: 107 for content in contents:
108 application, app_args, app_kwargs, content_name = self._j.get_content_data( 108 content_data = self._j.get_content_data(
109 content) 109 content)
110 try: 110 try:
111 jingle_description_elt = application.handler.jingle_description_elt 111 jingle_description_elt = (
112 content_data.application.handler.jingle_description_elt
113 )
112 except AttributeError: 114 except AttributeError:
113 log.debug(f"no jingle_description_elt set for {application.handler}") 115 log.debug(
116 "no jingle_description_elt set for "
117 f"{content_data.application.handler}"
118 )
114 description_elt = domish.Element((content["app_ns"], "description")) 119 description_elt = domish.Element((content["app_ns"], "description"))
115 else: 120 else:
116 description_elt = await utils.as_deferred( 121 description_elt = await utils.as_deferred(
117 jingle_description_elt, 122 jingle_description_elt,
118 client, session, content_name, *app_args, **app_kwargs 123 client, session, content_data.content_name, *content_data.app_args,
124 **content_data.app_kwargs
119 ) 125 )
120 mess_data["xml"].propose.addChild(description_elt) 126 mess_data["xml"].propose.addChild(description_elt)
121 response_d = defer.Deferred() 127 response_d = defer.Deferred()
122 # we wait for 2 min before cancelling the session init 128 # we wait for 2 min before cancelling the session init
123 response_d.addTimeout(2*60, reactor) 129 # response_d.addTimeout(2*60, reactor)
130 # FIXME: let's application decide timeout?
131 response_d.addTimeout(2, reactor)
124 client._xep_0353_pending_sessions[session['id']] = response_d 132 client._xep_0353_pending_sessions[session['id']] = response_d
125 await client.send_message_data(mess_data) 133 await client.send_message_data(mess_data)
126 try: 134 try:
127 accepting_jid = await response_d 135 accepting_jid = await response_d
128 except defer.TimeoutError: 136 except defer.TimeoutError:
156 peer_jid = jid.JID(message_elt["from"]) 164 peer_jid = jid.JID(message_elt["from"])
157 session_id = elt["id"] 165 session_id = elt["id"]
158 if peer_jid.userhostJID() not in client.roster: 166 if peer_jid.userhostJID() not in client.roster:
159 app_ns = elt.description.uri 167 app_ns = elt.description.uri
160 try: 168 try:
161 application = self._j.getApplication(app_ns) 169 application = self._j.get_application(app_ns)
162 human_name = getattr(application.handler, "human_name", application.name) 170 human_name = getattr(application.handler, "human_name", application.name)
163 except (exceptions.NotFound, AttributeError): 171 except (exceptions.NotFound, AttributeError):
164 if app_ns.startswith("urn:xmpp:jingle:apps:"): 172 if app_ns.startswith("urn:xmpp:jingle:apps:"):
165 human_name = app_ns[21:].split(":", 1)[0].replace('-', ' ').title() 173 human_name = app_ns[21:].split(":", 1)[0].replace('-', ' ').title()
166 else: 174 else:
191 # we don't sent anything to sender, to avoid leaking presence 199 # we don't sent anything to sender, to avoid leaking presence
192 return False 200 return False
193 else: 201 else:
194 await client.presence.available(peer_jid) 202 await client.presence.available(peer_jid)
195 session_id = elt["id"] 203 session_id = elt["id"]
204 # FIXME: accept is not used anymore in new specification, check it and remove it
196 mess_data = self.build_message_data( 205 mess_data = self.build_message_data(
197 client, client.jid.userhostJID(), "accept", session_id) 206 client, client.jid.userhostJID(), "accept", session_id)
198 await client.send_message_data(mess_data) 207 await client.send_message_data(mess_data)
199 mess_data = self.build_message_data( 208 mess_data = self.build_message_data(
200 client, peer_jid, "proceed", session_id) 209 client, peer_jid, "proceed", session_id)