comparison libervia/backend/plugins/plugin_xep_0096.py @ 4231:e11b13418ba6

plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation: Implement XEP-0343: Signaling WebRTC Data Channels in Jingle. The current version of the XEP (0.3.1) has no implementation and contains some flaws. After discussing this on xsf@, Daniel (from Conversations) mentioned that they had a sprint with Larma (from Dino) to work on another version and provided me with this link: https://gist.github.com/iNPUTmice/6c56f3e948cca517c5fb129016d99e74 . I have used it for my implementation. This implementation reuses work done on Jingle A/V call (notably XEP-0176 and XEP-0167 plugins), with adaptations. When used, XEP-0234 will not handle the file itself as it normally does. This is because WebRTC has several implementations (browser for web interface, GStreamer for others), and file/data must be handled directly by the frontend. This is particularly important for web frontends, as the file is not sent from the backend but from the end-user's browser device. Among the changes, there are: - XEP-0343 implementation. - `file_send` bridge method now use serialised dict as output. - New `BaseTransportHandler.is_usable` method which get content data and returns a boolean (default to `True`) to tell if this transport can actually be used in this context (when we are initiator). Used in webRTC case to see if call data are available. - Support of `application` media type, and everything necessary to handle data channels. - Better confirmation message, with file name, size and description when available. - When file is accepted in preflight, it is specified in following `action_new` signal for actual file transfer. This way, frontend can avoid the display or 2 confirmation messages. - XEP-0166: when not specified, default `content` name is now its index number instead of a UUID. This follows the behaviour of browsers. - XEP-0353: better handling of events such as call taken by another device. - various other updates. rel 441
author Goffi <goffi@goffi.org>
date Sat, 06 Apr 2024 12:57:23 +0200
parents 4b842c1fb686
children
comparison
equal deleted inserted replaced
4230:314d3c02bb67 4231:e11b13418ba6
24 from twisted.internet import defer 24 from twisted.internet import defer
25 from libervia.backend.core.i18n import _, D_ 25 from libervia.backend.core.i18n import _, D_
26 from libervia.backend.core.constants import Const as C 26 from libervia.backend.core.constants import Const as C
27 from libervia.backend.core.log import getLogger 27 from libervia.backend.core.log import getLogger
28 from libervia.backend.core import exceptions 28 from libervia.backend.core import exceptions
29 from libervia.backend.core.xmpp import SatXMPPEntity
29 from libervia.backend.tools import xml_tools 30 from libervia.backend.tools import xml_tools
30 from libervia.backend.tools import stream 31 from libervia.backend.tools import stream
31 32
32 log = getLogger(__name__) 33 log = getLogger(__name__)
33 34
289 client = self.host.get_client(profile) 290 client = self.host.get_client(profile)
290 return self.file_send( 291 return self.file_send(
291 client, jid.JID(peer_jid_s), filepath, name or None, desc or None 292 client, jid.JID(peer_jid_s), filepath, name or None, desc or None
292 ) 293 )
293 294
294 def file_send(self, client, peer_jid, filepath, name=None, desc=None, extra=None): 295 def file_send(
295 """Send a file using XEP-0096 296 self,
296 297 client: SatXMPPEntity,
297 @param peer_jid(jid.JID): recipient 298 peer_jid: jid.JID,
298 @param filepath(str): absolute path to the file to send 299 filepath: str,
299 @param name(unicode): name of the file to send 300 name: str|None = None,
301 desc: str|None = None,
302 extra: dict|None = None
303 ) -> dict:
304 """Send a file using XEP-0096.
305
306 @param peer_jid: recipient
307 @param filepath: absolute path to the file to send
308 @param name: name of the file to send
300 name must not contain "/" characters 309 name must not contain "/" characters
301 @param desc: description of the file 310 @param desc: description of the file
302 @param extra: not used here 311 @param extra: not used here
303 @return: an unique id to identify the transfer 312 @return: a dict with the key "progress" containing an unique id to identify the
313 transfer
304 """ 314 """
305 feature_elt = self.host.plugins["XEP-0020"].propose_features( 315 feature_elt = self.host.plugins["XEP-0020"].propose_features(
306 {"stream-method": self.managed_stream_m}, namespace=None 316 {"stream-method": self.managed_stream_m}, namespace=None
307 ) 317 )
308 318
323 sid, offer_d = self._si.propose_stream( 333 sid, offer_d = self._si.propose_stream(
324 client, peer_jid, SI_PROFILE, feature_elt, file_transfer_elts 334 client, peer_jid, SI_PROFILE, feature_elt, file_transfer_elts
325 ) 335 )
326 args = [filepath, sid, size, client] 336 args = [filepath, sid, size, client]
327 offer_d.addCallbacks(self._file_cb, self._file_eb, args, None, args) 337 offer_d.addCallbacks(self._file_cb, self._file_eb, args, None, args)
328 return sid 338 return {"progress": sid}
329 339
330 def _file_cb(self, result_tuple, filepath, sid, size, client): 340 def _file_cb(self, result_tuple, filepath, sid, size, client):
331 iq_elt, si_elt = result_tuple 341 iq_elt, si_elt = result_tuple
332 342
333 try: 343 try: