Add clix module to send XMPP pings to JIDs

Sun, 10 Feb 2013 14:09:20 +0100

author
"Georg Lukas <georg@op-co.de>"
date
Sun, 10 Feb 2013 14:09:20 +0100
changeset 104
16cdeb9cd879
parent 98
5ad042476235
child 105
82c21f1d6f46

Add clix module to send XMPP pings to JIDs

Signed-off-by: Georg Lukas <georg@op-co.de>

clix/ping.lua file | annotate | diff | comparison | revisions
squishy file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clix/ping.lua	Sun Feb 10 14:09:20 2013 +0100
@@ -0,0 +1,24 @@
+return function (opts, arg)
+	if opts.short_help then
+		print("Measure the round-trip latency time of a given JID");
+		return;
+	end
+	if #arg == 0 or opts.help then
+		return 0;
+	end
+	local conn;
+	local function on_reply(time, jid, reply)
+		if time then
+			print(string.format("%s latency: %1.3fs", jid, time));
+		else
+			print("Error requesting ping ("..(reply.condition or "unknown")..")"..(reply.text and (": "..reply.text) or ""));
+		end
+		conn:close();
+	end
+	local function on_connect(_conn)
+		conn = _conn;
+		conn:add_plugin("ping");
+		conn:ping(arg[1], on_reply);
+	end
+	clix_connect(opts, on_connect);
+end
--- a/squishy	Mon Aug 27 00:13:02 2012 +0200
+++ b/squishy	Sun Feb 10 14:09:20 2013 +0100
@@ -2,6 +2,7 @@
 	"send";
 	"receive";
 	"version";
+	"ping";
 	"bounce";
 	"mirror";
 	"raw";

mercurial