summaryrefslogtreecommitdiffstats
path: root/bridge/xmpp/xmpp.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-02-27 00:33:21 +0100
committerWim <wim@42.be>2018-02-27 23:22:12 +0100
commit2bac8673829516d8314c459133e85a8c0cc1959c (patch)
treeed4123232727f9c53c685b1687725206f0b02cb6 /bridge/xmpp/xmpp.go
parent5fbd8a3be05cdecdde515ad459b7a5d87b056956 (diff)
downloadmatterbridge-msglm-2bac8673829516d8314c459133e85a8c0cc1959c.tar.gz
matterbridge-msglm-2bac8673829516d8314c459133e85a8c0cc1959c.tar.bz2
matterbridge-msglm-2bac8673829516d8314c459133e85a8c0cc1959c.zip
Refactor using factory
Diffstat (limited to 'bridge/xmpp/xmpp.go')
-rw-r--r--bridge/xmpp/xmpp.go29
1 files changed, 11 insertions, 18 deletions
diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go
index 03d81595..1363096e 100644
--- a/bridge/xmpp/xmpp.go
+++ b/bridge/xmpp/xmpp.go
@@ -2,11 +2,11 @@ package bxmpp
import (
"crypto/tls"
+ "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
"github.com/jpillora/backoff"
"github.com/mattn/go-xmpp"
- log "github.com/sirupsen/logrus"
"strings"
"time"
)
@@ -17,14 +17,7 @@ type Bxmpp struct {
*config.BridgeConfig
}
-var flog *log.Entry
-var protocol = "xmpp"
-
-func init() {
- flog = log.WithFields(log.Fields{"prefix": protocol})
-}
-
-func New(cfg *config.BridgeConfig) *Bxmpp {
+func New(cfg *config.BridgeConfig) bridge.Bridger {
b := &Bxmpp{BridgeConfig: cfg}
b.xmppMap = make(map[string]string)
return b
@@ -32,13 +25,13 @@ func New(cfg *config.BridgeConfig) *Bxmpp {
func (b *Bxmpp) Connect() error {
var err error
- flog.Infof("Connecting %s", b.Config.Server)
+ b.Log.Infof("Connecting %s", b.Config.Server)
b.xc, err = b.createXMPP()
if err != nil {
- flog.Debugf("%#v", err)
+ b.Log.Debugf("%#v", err)
return err
}
- flog.Info("Connection succeeded")
+ b.Log.Info("Connection succeeded")
go func() {
initial := true
bf := &backoff.Backoff{
@@ -52,7 +45,7 @@ func (b *Bxmpp) Connect() error {
initial = false
}
d := bf.Duration()
- flog.Infof("Disconnected. Reconnecting in %s", d)
+ b.Log.Infof("Disconnected. Reconnecting in %s", d)
time.Sleep(d)
b.xc, err = b.createXMPP()
if err == nil {
@@ -79,7 +72,7 @@ func (b *Bxmpp) Send(msg config.Message) (string, error) {
if msg.Event == config.EVENT_MSG_DELETE {
return "", nil
}
- flog.Debugf("Receiving %#v", msg)
+ b.Log.Debugf("Receiving %#v", msg)
// Upload a file (in xmpp case send the upload URL because xmpp has no native upload support)
if msg.Extra != nil {
@@ -131,10 +124,10 @@ func (b *Bxmpp) xmppKeepAlive() chan bool {
for {
select {
case <-ticker.C:
- flog.Debugf("PING")
+ b.Log.Debugf("PING")
err := b.xc.PingC2S("", "")
if err != nil {
- flog.Debugf("PING failed %#v", err)
+ b.Log.Debugf("PING failed %#v", err)
}
case <-done:
return
@@ -167,8 +160,8 @@ func (b *Bxmpp) handleXMPP() error {
if ok {
rmsg.Event = config.EVENT_USER_ACTION
}
- flog.Debugf("Sending message from %s on %s to gateway", rmsg.Username, b.Account)
- flog.Debugf("Message is %#v", rmsg)
+ b.Log.Debugf("Sending message from %s on %s to gateway", rmsg.Username, b.Account)
+ b.Log.Debugf("Message is %#v", rmsg)
b.Remote <- rmsg
}
case xmpp.Presence: