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.
2019-06-01 04:38:35 +02:00
|
|
|
package component
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gosrc.io/xmpp"
|
|
|
|
)
|
|
|
|
|
|
|
|
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-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",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cm := xmpp.NewStreamManager(c.xmpp, nil)
|
|
|
|
err = cm.Start()
|
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
|
|
|
}
|
|
|
|
|
|
|
|
go c.sender(out)
|
|
|
|
go c.receiver()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|