summaryrefslogtreecommitdiffstats
path: root/gateway/samechannel/samechannel.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-04-01 17:24:19 +0200
committerWim <wim@42.be>2017-04-01 17:24:19 +0200
commita16ad8bf3b39d99658f306d3c065680c606e4801 (patch)
tree370528dd84572928161f4eff988f738581394ac0 /gateway/samechannel/samechannel.go
parent1e0490bd36ec20a7de43587f43feb6ec63c02ddb (diff)
downloadmatterbridge-msglm-a16ad8bf3b39d99658f306d3c065680c606e4801.tar.gz
matterbridge-msglm-a16ad8bf3b39d99658f306d3c065680c606e4801.tar.bz2
matterbridge-msglm-a16ad8bf3b39d99658f306d3c065680c606e4801.zip
Reuse connection when using same bridge with another gateway. See #87
Diffstat (limited to 'gateway/samechannel/samechannel.go')
-rw-r--r--gateway/samechannel/samechannel.go49
1 files changed, 13 insertions, 36 deletions
diff --git a/gateway/samechannel/samechannel.go b/gateway/samechannel/samechannel.go
index 22f37e67..937d769b 100644
--- a/gateway/samechannel/samechannel.go
+++ b/gateway/samechannel/samechannel.go
@@ -2,50 +2,27 @@ package samechannelgateway
import (
"github.com/42wim/matterbridge/bridge/config"
- "github.com/42wim/matterbridge/gateway"
)
type SameChannelGateway struct {
*config.Config
- MyConfig *config.SameChannelGateway
- Channels []string
- Name string
}
-func New(cfg *config.Config, gatewayCfg *config.SameChannelGateway) *SameChannelGateway {
- return &SameChannelGateway{
- MyConfig: gatewayCfg,
- Channels: gatewayCfg.Channels,
- Name: gatewayCfg.Name,
- Config: cfg}
+func New(cfg *config.Config) *SameChannelGateway {
+ return &SameChannelGateway{Config: cfg}
}
-func (sgw *SameChannelGateway) Start() error {
- gw := gateway.New(sgw.Config, &config.Gateway{Name: sgw.Name})
- gw.DestChannelFunc = sgw.getDestChannel
- for _, account := range sgw.MyConfig.Accounts {
- for _, channel := range sgw.Channels {
- br := config.Bridge{Account: account, Channel: channel}
- gw.MyConfig.InOut = append(gw.MyConfig.InOut, br)
+func (sgw *SameChannelGateway) GetConfig() []config.Gateway {
+ var gwconfigs []config.Gateway
+ cfg := sgw.Config
+ for _, gw := range cfg.SameChannelGateway {
+ gwconfig := config.Gateway{Name: gw.Name, Enable: gw.Enable}
+ for _, account := range gw.Accounts {
+ for _, channel := range gw.Channels {
+ gwconfig.InOut = append(gwconfig.InOut, config.Bridge{Account: account, Channel: channel, SameChannel: true})
+ }
}
+ gwconfigs = append(gwconfigs, gwconfig)
}
- return gw.Start()
-}
-
-func (sgw *SameChannelGateway) validChannel(channel string) bool {
- for _, c := range sgw.Channels {
- if c == channel {
- return true
- }
- }
- return false
-}
-
-func (sgw *SameChannelGateway) getDestChannel(msg *config.Message, dest string) []config.ChannelInfo {
- var channels []config.ChannelInfo
- if sgw.validChannel(msg.Channel) {
- channels = append(channels, config.ChannelInfo{Name: msg.Channel, Account: dest, ID: msg.Channel + dest})
- return channels
- }
- return channels
+ return gwconfigs
}