Software /
code /
verse
Comparison
plugins/ping.lua @ 41:1a1bd8cd4bdb
plugins.ping: Don't handle all errors as successful pongs, call callback with nil time and 3rd parameter a table with error info
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 23 Dec 2009 00:59:35 +0000 |
parent | 36:fc2cd2f36cdd |
child | 147:c95b84ed366b |
comparison
equal
deleted
inserted
replaced
40:afd037420977 | 41:1a1bd8cd4bdb |
---|---|
1 require "util.xstanza"; | |
1 | 2 |
2 local xmlns_ping = "urn:xmpp:ping"; | 3 local xmlns_ping = "urn:xmpp:ping"; |
3 | 4 |
4 function verse.plugins.ping(stream) | 5 function verse.plugins.ping(stream) |
5 function stream:ping(jid, callback) | 6 function stream:ping(jid, callback) |
6 local t = socket.gettime(); | 7 local t = socket.gettime(); |
7 stream:send_iq(verse.iq{ to = jid, type = "get" }:tag("ping", { xmlns = xmlns_ping }), | 8 stream:send_iq(verse.iq{ to = jid, type = "get" }:tag("ping", { xmlns = xmlns_ping }), |
8 function (reply) | 9 function (reply) |
10 if reply.attr.type == "error" then | |
11 local type, condition, text = reply:get_error(); | |
12 if condition ~= "service-unavailable" and condition ~= "feature-not-implemented" then | |
13 callback(nil, jid, { type = type, condition = condition, text = text }); | |
14 return; | |
15 end | |
16 end | |
9 callback(socket.gettime()-t, jid); | 17 callback(socket.gettime()-t, jid); |
10 end); | 18 end); |
11 end | 19 end |
12 return true; | 20 return true; |
13 end | 21 end |