comparison src/plugins/plugin_xep_0261.py @ 2489:e2a7bb875957

plugin pipe/stream, file transfert: refactoring and improvments: this is a big patch as things had to be changed at the same time. - changed methods using profile argument to use client instead - move SatFile in a new tools.stream module, has it should be part of core, not a plugin - new IStreamProducer interface, to handler starting a pull producer - new FileStreamObject which create a stream producer/consumer from a SatFile - plugin pipe is no more using unix named pipe, as it complicate the thing, special care need to be taken to not block, and it's generally not necessary. Instead a socket is now used, so the plugin has been renomed to jingle stream. - bad connection/error should be better handler in jingle stream plugin, and code should not block anymore - jp pipe commands have been updated accordingly fix bug 237
author Goffi <goffi@goffi.org>
date Thu, 08 Feb 2018 00:37:42 +0100
parents 0046283a285d
children 67cc54b01a12
comparison
equal deleted inserted replaced
2488:78c7992a26ed 2489:e2a7bb875957
57 self._j.registerTransport(NS_JINGLE_IBB, self._j.TRANSPORT_STREAMING, self, -10000) # must be the lowest priority 57 self._j.registerTransport(NS_JINGLE_IBB, self._j.TRANSPORT_STREAMING, self, -10000) # must be the lowest priority
58 58
59 def getHandler(self, client): 59 def getHandler(self, client):
60 return XEP_0261_handler() 60 return XEP_0261_handler()
61 61
62 def jingleSessionInit(self, session, content_name, profile): 62 def jingleSessionInit(self, client, session, content_name):
63 transport_elt = domish.Element((NS_JINGLE_IBB, "transport")) 63 transport_elt = domish.Element((NS_JINGLE_IBB, "transport"))
64 content_data = session['contents'][content_name] 64 content_data = session['contents'][content_name]
65 transport_data = content_data['transport_data'] 65 transport_data = content_data['transport_data']
66 transport_data['block_size'] = self._ibb.BLOCK_SIZE 66 transport_data['block_size'] = self._ibb.BLOCK_SIZE
67 transport_elt['block-size'] = unicode(transport_data['block_size']) 67 transport_elt['block-size'] = unicode(transport_data['block_size'])
68 transport_elt['sid'] = transport_data['sid'] = unicode(uuid.uuid4()) 68 transport_elt['sid'] = transport_data['sid'] = unicode(uuid.uuid4())
69 return transport_elt 69 return transport_elt
70 70
71 def jingleHandler(self, action, session, content_name, transport_elt, profile): 71 def jingleHandler(self, client, action, session, content_name, transport_elt):
72 content_data = session['contents'][content_name] 72 content_data = session['contents'][content_name]
73 transport_data = content_data['transport_data'] 73 transport_data = content_data['transport_data']
74 if action in (self._j.A_SESSION_ACCEPT, 74 if action in (self._j.A_SESSION_ACCEPT,
75 self._j.A_ACCEPTED_ACK, 75 self._j.A_ACCEPTED_ACK,
76 self._j.A_TRANSPORT_ACCEPT): 76 self._j.A_TRANSPORT_ACCEPT):
78 elif action in (self._j.A_SESSION_INITIATE, self._j.A_TRANSPORT_REPLACE): 78 elif action in (self._j.A_SESSION_INITIATE, self._j.A_TRANSPORT_REPLACE):
79 transport_data['sid'] = transport_elt['sid'] 79 transport_data['sid'] = transport_elt['sid']
80 elif action in (self._j.A_START, self._j.A_PREPARE_RESPONDER): 80 elif action in (self._j.A_START, self._j.A_PREPARE_RESPONDER):
81 peer_jid = session['peer_jid'] 81 peer_jid = session['peer_jid']
82 sid = transport_data['sid'] 82 sid = transport_data['sid']
83 file_obj = content_data['file_obj'] 83 stream_object = content_data['stream_object']
84 if action == self._j.A_START: 84 if action == self._j.A_START:
85 block_size = transport_data['block_size'] 85 block_size = transport_data['block_size']
86 d = self._ibb.startStream(file_obj, peer_jid, sid, block_size, profile) 86 d = self._ibb.startStream(client, stream_object, peer_jid, sid, block_size)
87 d.chainDeferred(content_data['finished_d']) 87 d.chainDeferred(content_data['finished_d'])
88 else: 88 else:
89 d = self._ibb.createSession(file_obj, peer_jid, sid, profile) 89 d = self._ibb.createSession(client, stream_object, peer_jid, sid)
90 d.chainDeferred(content_data['finished_d']) 90 d.chainDeferred(content_data['finished_d'])
91 else: 91 else:
92 log.warning(u"FIXME: unmanaged action {}".format(action)) 92 log.warning(u"FIXME: unmanaged action {}".format(action))
93 return transport_elt 93 return transport_elt
94 94