Let component handle discovery for now
This commit is contained in:
parent
909cf753c9
commit
bc2fad6693
|
@ -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")
|
||||
|
||||
|
|
16
component.go
16
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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue