comparison sat/plugins/plugin_xep_0047.py @ 3392:0957ea9137b8

plugin XEP-0047: fixed file reading and content encoding
author Goffi <goffi@goffi.org>
date Thu, 12 Nov 2020 14:53:15 +0100
parents 559a625a236b
children be6d91572633
comparison
equal deleted inserted replaced
3391:e898a43b5bea 3392:0957ea9137b8
325 @param session_data(dict): data of this streaming session 325 @param session_data(dict): data of this streaming session
326 @param client: %(doc_client)s 326 @param client: %(doc_client)s
327 """ 327 """
328 session_data["timer"].reset(TIMEOUT) 328 session_data["timer"].reset(TIMEOUT)
329 329
330 buffer_ = session_data["stream_object"].read(session_data["block_size"]) 330 # FIXME: producer/consumer mechanism is not used properly here
331 buffer_ = session_data["stream_object"].file_obj.read(session_data["block_size"])
331 if buffer_: 332 if buffer_:
332 next_iq_elt = client.IQ() 333 next_iq_elt = client.IQ()
333 next_iq_elt["from"] = session_data["local_jid"].full() 334 next_iq_elt["from"] = session_data["local_jid"].full()
334 next_iq_elt["to"] = session_data["to"].full() 335 next_iq_elt["to"] = session_data["to"].full()
335 data_elt = next_iq_elt.addElement((NS_IBB, "data")) 336 data_elt = next_iq_elt.addElement((NS_IBB, "data"))
336 seq = session_data["seq"] = (session_data["seq"] + 1) % 65535 337 seq = session_data["seq"] = (session_data["seq"] + 1) % 65535
337 data_elt["seq"] = str(seq) 338 data_elt["seq"] = str(seq)
338 data_elt["sid"] = session_data["id"] 339 data_elt["sid"] = session_data["id"]
339 data_elt.addContent(base64.b64encode(buffer_)) 340 data_elt.addContent(base64.b64encode(buffer_).decode())
340 args = [session_data, client] 341 args = [session_data, client]
341 d = next_iq_elt.send() 342 d = next_iq_elt.send()
342 d.addCallbacks(self._IQDataStreamCb, self._IQDataStreamEb, args, None, args) 343 d.addCallbacks(self._IQDataStreamCb, self._IQDataStreamEb, args, None, args)
343 else: 344 else:
344 self.terminateStream(session_data, client) 345 self.terminateStream(session_data, client)