5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-22 21:50:28 +00:00

Enable keepalive (xmpp)

This commit is contained in:
Wim 2016-11-26 15:02:39 +01:00
parent 4ef32103ca
commit 6c018ee6fe

View File

@ -78,19 +78,26 @@ func (b *Bxmpp) createXMPP() (*xmpp.Client, error) {
return b.xc, err return b.xc, err
} }
func (b *Bxmpp) xmppKeepAlive() { func (b *Bxmpp) xmppKeepAlive() chan bool {
done := make(chan bool)
go func() { go func() {
ticker := time.NewTicker(90 * time.Second) ticker := time.NewTicker(90 * time.Second)
defer ticker.Stop()
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
b.xc.Send(xmpp.Chat{}) b.xc.PingC2S("", "")
case <-done:
return
} }
} }
}() }()
return done
} }
func (b *Bxmpp) handleXmpp() error { func (b *Bxmpp) handleXmpp() error {
done := b.xmppKeepAlive()
defer close(done)
for { for {
m, err := b.xc.Recv() m, err := b.xc.Recv()
if err != nil { if err != nil {