Refactor to handle disconnects/reconnects better.

Now try to reconnect every 60 seconds until forever.
This commit is contained in:
Wim
2017-02-14 21:12:02 +01:00
parent 2d16fd085e
commit 163f55f9c2
11 changed files with 99 additions and 24 deletions

View File

@@ -10,6 +10,8 @@ import (
"github.com/42wim/matterbridge/bridge/slack"
"github.com/42wim/matterbridge/bridge/telegram"
"github.com/42wim/matterbridge/bridge/xmpp"
log "github.com/Sirupsen/logrus"
"strings"
)
@@ -17,14 +19,18 @@ type Bridger interface {
Send(msg config.Message) error
Connect() error
JoinChannel(channel string) error
Disconnect() error
}
type Bridge struct {
Config config.Protocol
Bridger
Name string
Account string
Protocol string
Name string
Account string
Protocol string
ChannelsOut []string
ChannelsIn []string
ChannelOptions config.ChannelOptions
}
func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Bridge {
@@ -66,3 +72,15 @@ func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Brid
}
return b
}
func (b *Bridge) JoinChannels() error {
exists := make(map[string]bool)
for _, channel := range append(b.ChannelsIn, b.ChannelsOut...) {
if !exists[channel] {
log.Infof("%s: joining %s", b.Account, channel)
b.JoinChannel(channel)
exists[channel] = true
}
}
return nil
}