Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0085.py @ 1547:0632d96f08ad
plugin XEP-0085: fixed bad use of threads resulting in delay and crash when stopping the backend.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Nov 2015 22:02:41 +0100 |
parents | 069ad98b360d |
children | 075a63180eab |
comparison
equal
deleted
inserted
replaced
1546:62d6310e7c04 | 1547:0632d96f08ad |
---|---|
27 from twisted.words.protocols.jabber.jid import JID | 27 from twisted.words.protocols.jabber.jid import JID |
28 try: | 28 try: |
29 from twisted.words.protocols.xmlstream import XMPPHandler | 29 from twisted.words.protocols.xmlstream import XMPPHandler |
30 except ImportError: | 30 except ImportError: |
31 from wokkel.subprotocols import XMPPHandler | 31 from wokkel.subprotocols import XMPPHandler |
32 from threading import Timer | |
33 from twisted.words.xish import domish | 32 from twisted.words.xish import domish |
33 from twisted.internet import reactor | |
34 | 34 |
35 NS_XMPP_CLIENT = "jabber:client" | 35 NS_XMPP_CLIENT = "jabber:client" |
36 NS_CHAT_STATES = "http://jabber.org/protocol/chatstates" | 36 NS_CHAT_STATES = "http://jabber.org/protocol/chatstates" |
37 CHAT_STATES = ["active", "inactive", "gone", "composing", "paused"] | 37 CHAT_STATES = ["active", "inactive", "gone", "composing", "paused"] |
38 MESSAGE_TYPES = ["chat", "groupchat"] | 38 MESSAGE_TYPES = ["chat", "groupchat"] |
322 # no message has been sent/received since the notifications | 322 # no message has been sent/received since the notifications |
323 # have been enabled, it's better to wait for a first one | 323 # have been enabled, it's better to wait for a first one |
324 pass | 324 pass |
325 | 325 |
326 | 326 |
327 class ChatStateMachine: | 327 class ChatStateMachine(object): |
328 """ | 328 """ |
329 This class represents a chat state, between one profile and | 329 This class represents a chat state, between one profile and |
330 one target contact. A timer is used to move from one state | 330 one target contact. A timer is used to move from one state |
331 to the other. The initialization is done through the "active" | 331 to the other. The initialization is done through the "active" |
332 state which is internally set when a message is sent. The state | 332 state which is internally set when a message is sent. The state |
370 self.host.generateMessageXML(mess_data) | 370 self.host.generateMessageXML(mess_data) |
371 mess_data['xml'].addElement(state, NS_CHAT_STATES) | 371 mess_data['xml'].addElement(state, NS_CHAT_STATES) |
372 client.xmlstream.send(mess_data['xml']) | 372 client.xmlstream.send(mess_data['xml']) |
373 | 373 |
374 self.state = state | 374 self.state = state |
375 if self.timer is not None: | |
376 self.timer.cancel() | |
377 | 375 |
378 if transition["next_state"] and transition["delay"] > 0: | 376 if transition["next_state"] and transition["delay"] > 0: |
379 self.timer = Timer(transition["delay"], self._onEvent, [transition["next_state"]]) | 377 self.timer = reactor.callLater(transition["delay"], self._onEvent, transition["next_state"]) |
380 self.timer.start() | |
381 | 378 |
382 | 379 |
383 class XEP_0085_handler(XMPPHandler): | 380 class XEP_0085_handler(XMPPHandler): |
384 implements(iwokkel.IDisco) | 381 implements(iwokkel.IDisco) |
385 | 382 |