~samwhited/xmpp

d25440afa4ee89475ed7ecafd2e8881a67ccf281 — Sam Whited 10 months ago f4b24b0 disco
ping: add service disco support

Signed-off-by: Sam Whited <sam@samwhited.com>
1 files changed, 12 insertions(+), 0 deletions(-)

M ping/ping.go
M ping/ping.go => ping/ping.go +12 -0
@@ 11,6 11,7 @@ import (

	"mellium.im/xmlstream"
	"mellium.im/xmpp"
	"mellium.im/xmpp/disco"
	"mellium.im/xmpp/jid"
	"mellium.im/xmpp/mux"
	"mellium.im/xmpp/stanza"


@@ 24,9 25,20 @@ func Handle() mux.Option {
	return mux.IQ(stanza.GetIQ, xml.Name{Local: "ping", Space: NS}, Handler{})
}

// Disco returns an option that registers ping support with a service discovery
// registry.
func Disco() disco.Option {
	return disco.Feature(NS)
}

// Handler responds to ping requests.
type Handler struct{}

// Disco is a disco.Option that registers ping support.
func (h Handler) Disco(r *disco.Registry) {
	Disco()(r)
}

// HandleIQ implements mux.IQHandler.
func (h Handler) HandleIQ(iq stanza.IQ, t xmlstream.TokenReadEncoder, start *xml.StartElement) error {
	if iq.Type != stanza.GetIQ || start.Name.Local != "ping" || start.Name.Space != NS {