コード例 #1
0
ファイル: samechannel.go プロジェクト: 42wim/matterbridge
func New(cfg *config.Config, gateway *config.SameChannelGateway) error {
	c := make(chan config.Message)
	gw := &SameChannelGateway{}
	gw.Bridges = make(map[string]*bridge.Bridge)
	gw.Name = gateway.Name
	gw.Config = cfg
	gw.MyConfig = gateway
	gw.Channels = gateway.Channels
	for _, account := range gateway.Accounts {
		br := config.Bridge{Account: account}
		log.Infof("Starting bridge: %s", account)
		gw.Bridges[account] = bridge.New(cfg, &br, c)
	}
	for _, br := range gw.Bridges {
		err := br.Connect()
		if err != nil {
			log.Fatalf("Bridge %s failed to start: %v", br.Account, err)
		}
		for _, channel := range gw.Channels {
			log.Infof("%s: joining %s", br.Account, channel)
			br.JoinChannel(channel)
		}
	}
	gw.handleReceive(c)
	return nil
}
コード例 #2
0
ファイル: gateway.go プロジェクト: 42wim/matterbridge
func (gw *Gateway) AddBridge(cfg *config.Bridge) error {
	for _, br := range gw.Bridges {
		if br.Account == cfg.Account {
			return nil
		}
	}
	log.Infof("Starting bridge: %s ", cfg.Account)
	br := bridge.New(gw.Config, cfg, gw.Message)
	gw.Bridges[cfg.Account] = br
	err := br.Connect()
	if err != nil {
		return fmt.Errorf("Bridge %s failed to start: %v", br.Account, err)
	}
	exists := make(map[string]bool)
	for _, channel := range append(gw.ChannelsOut[br.Account], gw.ChannelsIn[br.Account]...) {
		if !exists[br.Account+channel] {
			log.Infof("%s: joining %s", br.Account, channel)
			br.JoinChannel(channel)
			exists[br.Account+channel] = true
		}
	}
	return nil
}