diff --git a/_examples/xmpp_component/xmpp_component.go b/_examples/xmpp_component/xmpp_component.go index ad209ca..7b9174c 100644 --- a/_examples/xmpp_component/xmpp_component.go +++ b/_examples/xmpp_component/xmpp_component.go @@ -34,6 +34,11 @@ func main() { switch p := packet.(type) { case xmpp.IQ: switch inner := p.Payload[0].(type) { + case *xmpp.DiscoInfo: + fmt.Println("DiscoInfo") + if p.Type == "get" { + discoResult(component, p.PacketAttrs, inner) + } case *xmpp.DiscoItems: fmt.Println("DiscoItems") if p.Type == "get" { @@ -62,6 +67,29 @@ func main() { } } +func discoResult(c *xmpp.Component, attrs xmpp.PacketAttrs, info *xmpp.DiscoInfo) { + iq := xmpp.NewIQ("result", attrs.To, attrs.From, attrs.Id, "en") + var identity xmpp.Identity + if info.Node == "" { + identity = xmpp.Identity{ + Name: c.Name, + Category: c.Category, + Type: c.Type, + } + } + + payload := xmpp.DiscoInfo{ + Identity: identity, + Features: []xmpp.Feature{ + {Var: xmpp.NSDiscoInfo}, + {Var: xmpp.NSDiscoItems}, + }, + } + iq.AddPayload(&payload) + + _ = c.Send(iq) +} + func discoItems(c *xmpp.Component, attrs xmpp.PacketAttrs, items *xmpp.DiscoItems) { iq := xmpp.NewIQ("result", attrs.To, attrs.From, attrs.Id, "en") diff --git a/component.go b/component.go index 6c4e1d9..966d4ed 100644 --- a/component.go +++ b/component.go @@ -141,16 +141,6 @@ func (c *Component) recv() (err error) { close(c.RecvChannel) c.streamError(p.Error.Local, p.Text) return errors.New("stream error: " + p.Error.Local) - case IQ: - switch inner := p.Payload[0].(type) { - // Our component module handle disco info but can let component implementation - // handle disco items queries - case *DiscoInfo: - if p.Type == "get" { - c.discoResult(p.PacketAttrs, inner) - } - } - break } c.RecvChannel <- val } @@ -247,3 +237,9 @@ func (c *Component) discoResult(attrs PacketAttrs, info *DiscoInfo) { _ = c.Send(iq) } + +/* +TODO: Add support for discovery management directly in component +TODO: Support multiple identities on disco info +TODO: Support returning features on disco info +*/