From 6c018ee6fea5114cfeda9c3e1043c50b1139d3eb Mon Sep 17 00:00:00 2001 From: Wim Date: Sat, 26 Nov 2016 15:02:39 +0100 Subject: Enable keepalive (xmpp) --- bridge/xmpp/xmpp.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index f57fa515..9ec6b234 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -78,19 +78,26 @@ func (b *Bxmpp) createXMPP() (*xmpp.Client, error) { return b.xc, err } -func (b *Bxmpp) xmppKeepAlive() { +func (b *Bxmpp) xmppKeepAlive() chan bool { + done := make(chan bool) go func() { ticker := time.NewTicker(90 * time.Second) + defer ticker.Stop() for { select { case <-ticker.C: - b.xc.Send(xmpp.Chat{}) + b.xc.PingC2S("", "") + case <-done: + return } } }() + return done } func (b *Bxmpp) handleXmpp() error { + done := b.xmppKeepAlive() + defer close(done) for { m, err := b.xc.Recv() if err != nil { -- cgit v1.2.3