Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0261.py @ 2562:26edcf3a30eb
core, setup: huge cleaning:
- moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention
- move twisted directory to root
- removed all hacks from setup.py, and added missing dependencies, it is now clean
- use https URL for website in setup.py
- removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed
- renamed sat.sh to sat and fixed its installation
- added python_requires to specify Python version needed
- replaced glib2reactor which use deprecated code by gtk3reactor
sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Apr 2018 19:44:50 +0200 |
parents | src/plugins/plugin_xep_0261.py@67cc54b01a12 |
children | 56f94936df1e |
comparison
equal
deleted
inserted
replaced
2561:bd30dc3ffe5a | 2562:26edcf3a30eb |
---|---|
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT plugin for Jingle (XEP-0261) | |
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from sat.core.i18n import _ | |
21 from sat.core.constants import Const as C | |
22 from sat.core.log import getLogger | |
23 log = getLogger(__name__) | |
24 from wokkel import disco, iwokkel | |
25 from zope.interface import implements | |
26 from twisted.words.xish import domish | |
27 import uuid | |
28 | |
29 try: | |
30 from twisted.words.protocols.xmlstream import XMPPHandler | |
31 except ImportError: | |
32 from wokkel.subprotocols import XMPPHandler | |
33 | |
34 | |
35 NS_JINGLE_IBB = 'urn:xmpp:jingle:transports:ibb:1' | |
36 | |
37 PLUGIN_INFO = { | |
38 C.PI_NAME: "Jingle In-Band Bytestreams", | |
39 C.PI_IMPORT_NAME: "XEP-0261", | |
40 C.PI_TYPE: "XEP", | |
41 C.PI_MODES: C.PLUG_MODE_BOTH, | |
42 C.PI_PROTOCOLS: ["XEP-0261"], | |
43 C.PI_DEPENDENCIES: ["XEP-0166", "XEP-0047"], | |
44 C.PI_MAIN: "XEP_0261", | |
45 C.PI_HANDLER: "yes", | |
46 C.PI_DESCRIPTION: _("""Implementation of Jingle In-Band Bytestreams""") | |
47 } | |
48 | |
49 | |
50 class XEP_0261(object): | |
51 NAMESPACE = NS_JINGLE_IBB # used by XEP-0260 plugin for transport-replace | |
52 | |
53 def __init__(self, host): | |
54 log.info(_("plugin Jingle In-Band Bytestreams")) | |
55 self.host = host | |
56 self._j = host.plugins["XEP-0166"] # shortcut to access jingle | |
57 self._ibb = host.plugins["XEP-0047"] # and in-band bytestream | |
58 self._j.registerTransport(NS_JINGLE_IBB, self._j.TRANSPORT_STREAMING, self, -10000) # must be the lowest priority | |
59 | |
60 def getHandler(self, client): | |
61 return XEP_0261_handler() | |
62 | |
63 def jingleSessionInit(self, client, session, content_name): | |
64 transport_elt = domish.Element((NS_JINGLE_IBB, "transport")) | |
65 content_data = session['contents'][content_name] | |
66 transport_data = content_data['transport_data'] | |
67 transport_data['block_size'] = self._ibb.BLOCK_SIZE | |
68 transport_elt['block-size'] = unicode(transport_data['block_size']) | |
69 transport_elt['sid'] = transport_data['sid'] = unicode(uuid.uuid4()) | |
70 return transport_elt | |
71 | |
72 def jingleHandler(self, client, action, session, content_name, transport_elt): | |
73 content_data = session['contents'][content_name] | |
74 transport_data = content_data['transport_data'] | |
75 if action in (self._j.A_SESSION_ACCEPT, | |
76 self._j.A_ACCEPTED_ACK, | |
77 self._j.A_TRANSPORT_ACCEPT): | |
78 pass | |
79 elif action in (self._j.A_SESSION_INITIATE, self._j.A_TRANSPORT_REPLACE): | |
80 transport_data['sid'] = transport_elt['sid'] | |
81 elif action in (self._j.A_START, self._j.A_PREPARE_RESPONDER): | |
82 peer_jid = session['peer_jid'] | |
83 sid = transport_data['sid'] | |
84 stream_object = content_data['stream_object'] | |
85 if action == self._j.A_START: | |
86 block_size = transport_data['block_size'] | |
87 d = self._ibb.startStream(client, stream_object, peer_jid, sid, block_size) | |
88 d.chainDeferred(content_data['finished_d']) | |
89 else: | |
90 d = self._ibb.createSession(client, stream_object, peer_jid, sid) | |
91 d.chainDeferred(content_data['finished_d']) | |
92 else: | |
93 log.warning(u"FIXME: unmanaged action {}".format(action)) | |
94 return transport_elt | |
95 | |
96 | |
97 class XEP_0261_handler(XMPPHandler): | |
98 implements(iwokkel.IDisco) | |
99 | |
100 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): | |
101 return [disco.DiscoFeature(NS_JINGLE_IBB)] | |
102 | |
103 def getDiscoItems(self, requestor, target, nodeIdentifier=''): | |
104 return [] |