examples/lm/ping.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Thu, 17 Mar 2016 23:17:00 +0200
changeset 151 5d90caa7fb2c
parent 68 742878c74b8e
permissions -rw-r--r--
Switch global name from 'main' to 'mcabber' (v0.0.5)


-- XMPP PING (XEP-0199)

-- library

local lm = require 'lm'
local iq = require 'lm.iq'

--

local F = { }

function F.send ( conn, to, success, fail )
	iq.send ( conn, to, 'get',
		{
			ping = { xmlns = 'urn:xmpp:ping' },
		}, success, fail )
end

function F.iq_handler ( conn, mess )
	local mtype, smtype = mess:type ()
	if smtype == 'get' then
		local p = mess:child ( 'ping' )
		if p and p:attribute ( 'xmlns' ) == 'urn:xmpp:ping' then
			conn:send ( lm.message.create { mtype = 'iq-result', to = mess:attribute ( 'from' ), id = mess:attribute ( 'id' ) } )
			return true
		end
	end
	return false
end

return F

-- vim: se ts=4: --