Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0261.py @ 1963:a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
/!\ several features are temporarily disabled, like notifications in frontends
next step in refactoring, with the following changes:
- jp: updated jp message to follow changes in backend/bridge
- jp: added --lang, --subject, --subject_lang, and --type options to jp message + fixed unicode handling for jid
- quick_frontend (QuickApp, QuickChat):
- follow backend changes
- refactored chat, message are now handled in OrderedDict and uid are kept so they can be updated
- Message and Occupant classes handle metadata, so frontend just have to display them
- Primitivus (Chat):
- follow backend/QuickFrontend changes
- info & standard messages are handled in the same MessageWidget class
- improved/simplified handling of messages, removed update() method
- user joined/left messages are merged when next to each other
- a separator is shown when message is received while widget is out of focus, so user can quickly see the new messages
- affiliation/role are shown (in a basic way for now) in occupants panel
- removed "/me" messages handling, as it will be done by a backend plugin
- message language is displayed when available (only one language per message for now)
- fixed :history and :search commands
- core (constants): new constants for messages type, XML namespace, entity type
- core: *Message methods renamed to follow new code sytle (e.g. sendMessageToBridge => messageSendToBridge)
- core (messages handling): fixed handling of language
- core (messages handling): mes_data['from'] and ['to'] are now jid.JID
- core (core.xmpp): reorganised message methods, added getNick() method to client.roster
- plugin text commands: fixed plugin and adapted to new messages behaviour. client is now used in arguments instead of profile
- plugins: added information for cancellation reason in CancelError calls
- plugin XEP-0045: various improvments, but this plugin still need work:
- trigger is used to avoid message already handled by the plugin to be handled a second time
- changed the way to handle history, the last message from DB is checked and we request only messages since this one, in seconds (thanks Poezio folks :))
- subject reception is waited before sending the roomJoined signal, this way we are sure that everything including history is ready
- cmd_* method now follow the new convention with client instead of profile
- roomUserJoined and roomUserLeft messages are removed, the events are now handled with info message with a "ROOM_USER_JOINED" info subtype
- probably other forgotten stuffs :p
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 20 Jun 2016 18:41:53 +0200 |
parents | 2daf7b4c6756 |
children | 1d3f73e065e1 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
1527
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SAT plugin for Jingle (XEP-0261) |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
1527
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from sat.core.i18n import _ |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core.log import getLogger |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 log = getLogger(__name__) |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from wokkel import disco, iwokkel |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from zope.interface import implements |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from twisted.words.xish import domish |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 import uuid |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 try: |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from twisted.words.protocols.xmlstream import XMPPHandler |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 except ImportError: |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from wokkel.subprotocols import XMPPHandler |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 NS_JINGLE_IBB = 'urn:xmpp:jingle:transports:ibb:1' |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 PLUGIN_INFO = { |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 "name": "Jingle In-Band Bytestreams", |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 "import_name": "XEP-0261", |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 "type": "XEP", |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 "protocols": ["XEP-0261"], |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 "dependencies": ["XEP-0166", "XEP-0047"], |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 "main": "XEP_0261", |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 "handler": "yes", |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 "description": _("""Implementation of Jingle In-Band Bytestreams""") |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 } |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 class XEP_0261(object): |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
49 NAMESPACE = NS_JINGLE_IBB # used by XEP-0260 plugin for transport-replace |
1527
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 def __init__(self, host): |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 log.info(_("plugin Jingle In-Band Bytestreams")) |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 self.host = host |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 self._j = host.plugins["XEP-0166"] # shortcut to access jingle |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 self._ibb = host.plugins["XEP-0047"] # and in-band bytestream |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 self._j.registerTransport(NS_JINGLE_IBB, self._j.TRANSPORT_STREAMING, self, -10000) # must be the lowest priority |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 def getHandler(self, profile): |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 return XEP_0261_handler() |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 def jingleSessionInit(self, session, content_name, profile): |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 transport_elt = domish.Element((NS_JINGLE_IBB, "transport")) |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 content_data = session['contents'][content_name] |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1527
diff
changeset
|
64 transport_data = content_data['transport_data'] |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1527
diff
changeset
|
65 transport_data['block_size'] = self._ibb.BLOCK_SIZE |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1527
diff
changeset
|
66 transport_elt['block-size'] = unicode(transport_data['block_size']) |
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1527
diff
changeset
|
67 transport_elt['sid'] = transport_data['sid'] = unicode(uuid.uuid4()) |
1527
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 return transport_elt |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 def jingleHandler(self, action, session, content_name, transport_elt, profile): |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 content_data = session['contents'][content_name] |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1527
diff
changeset
|
72 transport_data = content_data['transport_data'] |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
73 if action in (self._j.A_SESSION_ACCEPT, |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
74 self._j.A_ACCEPTED_ACK, |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
75 self._j.A_TRANSPORT_ACCEPT): |
1527
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 pass |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
77 elif action in (self._j.A_SESSION_INITIATE, self._j.A_TRANSPORT_REPLACE): |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1527
diff
changeset
|
78 transport_data['sid'] = transport_elt['sid'] |
1527
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 elif action in (self._j.A_START, self._j.A_PREPARE_RESPONDER): |
1567
268fda4236ca
plugins XE0166, XEP-0234, XEP-0260, XEP-0261: renamed session key managing other peer's jid to "peer_jid" instead of "to_jid"
Goffi <goffi@goffi.org>
parents:
1556
diff
changeset
|
80 peer_jid = session['peer_jid'] |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1527
diff
changeset
|
81 sid = transport_data['sid'] |
1527
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 file_obj = content_data['file_obj'] |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 if action == self._j.A_START: |
1556
cbfbe028d099
plugin XEP-0166, XEP-0234, XEP-0261:
Goffi <goffi@goffi.org>
parents:
1527
diff
changeset
|
84 block_size = transport_data['block_size'] |
1567
268fda4236ca
plugins XE0166, XEP-0234, XEP-0260, XEP-0261: renamed session key managing other peer's jid to "peer_jid" instead of "to_jid"
Goffi <goffi@goffi.org>
parents:
1556
diff
changeset
|
85 d = self._ibb.startStream(file_obj, peer_jid, sid, block_size, profile) |
1571
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
86 d.chainDeferred(content_data['finished_d']) |
1527
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 else: |
1567
268fda4236ca
plugins XE0166, XEP-0234, XEP-0260, XEP-0261: renamed session key managing other peer's jid to "peer_jid" instead of "to_jid"
Goffi <goffi@goffi.org>
parents:
1556
diff
changeset
|
88 d = self._ibb.createSession(file_obj, peer_jid, sid, profile) |
1571
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
89 d.chainDeferred(content_data['finished_d']) |
1527
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 else: |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 log.warning(u"FIXME: unmanaged action {}".format(action)) |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 return transport_elt |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 class XEP_0261_handler(XMPPHandler): |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 implements(iwokkel.IDisco) |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 return [disco.DiscoFeature(NS_JINGLE_IBB)] |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
bfef1934a8f3
plugin XEP-0261: jingle in-band bystream first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 return [] |