This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
thrempp/component/config.go

49 lines
982 B
Go
Raw Normal View History

2019-06-01 04:38:35 +02:00
package component
import (
"gosrc.io/xmpp"
2019-06-28 03:03:38 +02:00
"gosrc.io/xmpp/stanza"
2019-06-01 04:38:35 +02:00
)
type Config struct {
Type string
Host string
Connection string
Secret string
2019-06-06 21:20:51 +02:00
XMPPDebug bool `toml:"xmpp_debug"`
2019-06-01 04:38:35 +02:00
Special map[string]interface{}
xmpp *xmpp.Component
comp Component
}
2019-06-10 01:00:36 +02:00
func (c *Config) Start() (err error) {
out, err := c.comp.Connect()
2019-06-01 04:38:35 +02:00
if err != nil {
2019-06-10 01:00:36 +02:00
return
2019-06-01 04:38:35 +02:00
}
2019-06-20 13:40:22 +02:00
router := xmpp.NewRouter()
2019-06-28 03:03:38 +02:00
router.NewRoute().IQNamespaces(stanza.NSDiscoInfo).HandlerFunc(c.handleDiscoInfo)
router.NewRoute().IQNamespaces(stanza.NSDiscoItems).HandlerFunc(c.handleDiscoItems)
2019-06-20 13:40:22 +02:00
router.HandleFunc("iq", c.handleIQ)
router.HandleFunc("message", c.handleMessage)
2019-06-10 01:00:36 +02:00
c.xmpp, err = xmpp.NewComponent(xmpp.ComponentOptions{
Domain: c.Host,
Secret: c.Secret,
Address: c.Connection,
Name: c.Type,
Category: "gateway",
Type: "service",
2019-06-20 13:40:22 +02:00
}, router)
2019-06-10 01:00:36 +02:00
if err != nil {
return
}
cm := xmpp.NewStreamManager(c.xmpp, nil)
2019-06-20 13:40:22 +02:00
go cm.Run()
2019-06-01 04:38:35 +02:00
go c.sender(out)
return nil
}