summaryrefslogtreecommitdiffstats
path: root/bridge/bridge.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-02-14 21:12:02 +0100
committerWim <wim@42.be>2017-02-14 21:12:02 +0100
commit163f55f9c27e9e8a75774424d22598799e8306c6 (patch)
tree5c84a9443dfce24d98b4bd466f066efa8faae211 /bridge/bridge.go
parent2d16fd085e91eb31264f7ff6e8cce76f79f0445b (diff)
downloadmatterbridge-msglm-163f55f9c27e9e8a75774424d22598799e8306c6.tar.gz
matterbridge-msglm-163f55f9c27e9e8a75774424d22598799e8306c6.tar.bz2
matterbridge-msglm-163f55f9c27e9e8a75774424d22598799e8306c6.zip
Refactor to handle disconnects/reconnects better.
Now try to reconnect every 60 seconds until forever.
Diffstat (limited to 'bridge/bridge.go')
-rw-r--r--bridge/bridge.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/bridge/bridge.go b/bridge/bridge.go
index b387812a..c8c6ac4e 100644
--- a/bridge/bridge.go
+++ b/bridge/bridge.go
@@ -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
+}