summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMathieu Pasquet <mathieui@mathieui.net>2013-10-06 18:03:24 +0200
committerMathieu Pasquet <mathieui@mathieui.net>2013-10-06 18:03:24 +0200
commit91fe1f5c592be64dce2180c97d956b3942cac241 (patch)
tree2b052f6b47f003b44f4d081add7b6f264031505d /plugins
parent9c775da5f7942a370d381109d0ad7bd6e9367478 (diff)
downloadpoezio-91fe1f5c592be64dce2180c97d956b3942cac241.tar.gz
poezio-91fe1f5c592be64dce2180c97d956b3942cac241.tar.bz2
poezio-91fe1f5c592be64dce2180c97d956b3942cac241.tar.xz
poezio-91fe1f5c592be64dce2180c97d956b3942cac241.zip
Fix #2356 (ping is blocking)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ping.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/plugins/ping.py b/plugins/ping.py
index fd64ea2f..8d478e24 100644
--- a/plugins/ping.py
+++ b/plugins/ping.py
@@ -35,6 +35,7 @@ from roster import roster
from common import safeJID
import common
import tabs
+import time
class Plugin(BasePlugin):
@@ -43,33 +44,35 @@ class Plugin(BasePlugin):
self.core.xmpp.plugin['xep_0115'].update_caps()
self.api.add_command('ping', self.command_ping,
usage='<jid>',
- help='Send a XMPP ping to jid (see XEP-0199).',
+ help='Send an XMPP ping to jid (see XEP-0199).',
short='Send a ping',
completion=self.completion_ping)
self.api.add_tab_command(tabs.MucTab, 'ping', self.command_muc_ping,
usage='<jid|nick>',
- help='Send a XMPP ping to jid or nick (see XEP-0199).',
+ help='Send an XMPP ping to jid or nick (see XEP-0199).',
short='Send a ping.',
completion=self.completion_muc_ping)
for _class in (tabs.PrivateTab, tabs.ConversationTab):
self.api.add_tab_command(_class, 'ping', self.command_private_ping,
usage='[jid]',
- help='Send a XMPP ping to the current interlocutor or the given JID.',
+ help='Send an XMPP ping to the current interlocutor or the given JID.',
short='Send a ping',
completion=self.completion_ping)
def command_ping(self, arg):
if not arg:
- return
+ return self.core.command_help('ping')
jid = safeJID(arg)
- try:
- delay = self.core.xmpp.plugin['xep_0199'].ping(jid=jid, timeout=5)
- except:
- delay = None
- if delay is not None:
- self.api.information('%s responded to ping after %s s' % (jid, round(delay, 4)), 'Info')
- else:
- self.api.information('%s did not respond to ping' % jid, 'Info')
+ start = time.time()
+ def callback(iq):
+ delay = time.time() - start
+ self.api.information("coucou %s %s" % (iq, type(iq)))
+ if iq['type'] == 'error' and iq['error']['condition'] in ('remote-server-timeout', 'remote-server-not-found'):
+ self.api.information('%s did not respond to ping' % jid, 'Info')
+ else:
+ self.api.information('%s responded to ping after %s s' % (jid, round(delay, 4)), 'Info')
+
+ self.core.xmpp.plugin['xep_0199'].send_ping(jid=jid, callback=callback)
def completion_muc_ping(self, the_input):
users = [user.nick for user in self.api.current_tab().users]