plugins/ping.lua

changeset 457
73d4eb93657b
parent 393
69229fa1d24f
child 490
6b2f31da9610
--- a/plugins/ping.lua	Fri Mar 03 12:10:54 2023 +0000
+++ b/plugins/ping.lua	Thu Mar 16 11:41:52 2023 +0000
@@ -1,12 +1,15 @@
 local verse = require "verse";
 local gettime = require"socket".gettime;
+local new_id = require "util.id".short;
 
 local xmlns_ping = "urn:xmpp:ping";
 
 function verse.plugins.ping(stream)
 	function stream:ping(jid, callback)
 		local t = gettime();
-		stream:send_iq(verse.iq{ to = jid, type = "get" }:tag("ping", { xmlns = xmlns_ping }),
+		local id = new_id();
+		local ping = verse.iq{ id = id, to = jid, type = "get" }:tag("ping", { xmlns = xmlns_ping });
+		stream:send_iq(ping,
 			function (reply)
 				if reply.attr.type == "error" then
 					local type, condition, text = reply:get_error();
@@ -17,6 +20,7 @@
 				end
 				callback(gettime()-t, jid);
 			end);
+		return id;
 	end
 	stream:hook("iq/"..xmlns_ping, function(stanza)
 		return stream:send(verse.reply(stanza));

mercurial