Add XMPP server address in config file.
This commit is contained in:
parent
213e1305d9
commit
b387657f5a
|
|
@ -18,6 +18,7 @@ SessionCookieLifeTime = 3600
|
||||||
|
|
||||||
JID = test@kingpenguin.tk
|
JID = test@kingpenguin.tk
|
||||||
PWD = test
|
PWD = test
|
||||||
|
SERVER = 51.254.205.203
|
||||||
PORT = 5222
|
PORT = 5222
|
||||||
TIMER_PING = 60
|
TIMER_PING = 60
|
||||||
XMPP_DEBUG = true
|
XMPP_DEBUG = true
|
||||||
|
|
|
||||||
20
xmpp/xmpp.go
20
xmpp/xmpp.go
|
|
@ -35,6 +35,7 @@ var (
|
||||||
|
|
||||||
JidStr = beego.AppConfig.String("JID")
|
JidStr = beego.AppConfig.String("JID")
|
||||||
passwdStr = beego.AppConfig.String("PWD")
|
passwdStr = beego.AppConfig.String("PWD")
|
||||||
|
server = beego.AppConfig.String("SERVER")
|
||||||
serverPort = beego.AppConfig.String("PORT")
|
serverPort = beego.AppConfig.String("PORT")
|
||||||
|
|
||||||
jid xmpp.JID
|
jid xmpp.JID
|
||||||
|
|
@ -68,10 +69,25 @@ func Run() {
|
||||||
// Create stream and configure it as a component connection.
|
// Create stream and configure it as a component connection.
|
||||||
log.Info("XMPP Run()")
|
log.Info("XMPP Run()")
|
||||||
|
|
||||||
|
streamConfig := &xmpp.StreamConfig{LogStanzas: Debug}
|
||||||
jid = must(xmpp.ParseJID(JidStr)).(xmpp.JID)
|
jid = must(xmpp.ParseJID(JidStr)).(xmpp.JID)
|
||||||
addrs, err := xmpp.HomeServerAddrs(jid)
|
var addrs []string
|
||||||
|
var err error = nil
|
||||||
|
if server != "" {
|
||||||
|
log.Info("Host in config")
|
||||||
|
addr := server
|
||||||
|
if serverPort != "" {
|
||||||
|
addr += ":" + serverPort
|
||||||
|
} else {
|
||||||
|
addr += ":5222"
|
||||||
|
}
|
||||||
|
addrs = append(addrs, addr)
|
||||||
|
} else {
|
||||||
|
log.Info("SRV lookup")
|
||||||
|
addrs, err = xmpp.HomeServerAddrs(jid)
|
||||||
|
}
|
||||||
if err == nil && len(addrs) > 0 {
|
if err == nil && len(addrs) > 0 {
|
||||||
stream = must(xmpp.NewStream(addrs[0], &xmpp.StreamConfig{LogStanzas: Debug})).(*xmpp.Stream)
|
stream = must(xmpp.NewStream(addrs[0], streamConfig)).(*xmpp.Stream)
|
||||||
client = must(xmpp.NewClientXMPP(stream, jid, passwdStr, &xmpp.ClientConfig{InsecureSkipVerify: true})).(*xmpp.XMPP)
|
client = must(xmpp.NewClientXMPP(stream, jid, passwdStr, &xmpp.ClientConfig{InsecureSkipVerify: true})).(*xmpp.XMPP)
|
||||||
|
|
||||||
mainXMPP()
|
mainXMPP()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue