summaryrefslogtreecommitdiff
path: root/xmpp/xmpp.go
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp/xmpp.go')
-rw-r--r--xmpp/xmpp.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go
index 5193f02..1d00739 100644
--- a/xmpp/xmpp.go
+++ b/xmpp/xmpp.go
@@ -15,8 +15,19 @@ const (
ShouldDisconnectEvent
)
-func Run(ch chan Event, jid string, pwd string) {
- conn, err := setupConn(jid)
+type Conn struct {
+ ch chan Event
+ jid, pwd string
+}
+
+func NewConn(ch chan Event, jid string, pwd string) *Conn {
+ c := Conn{ch, jid, pwd}
+
+ return &c
+}
+
+func (c *Conn) Run() {
+ conn, err := setupConn(c.jid)
if err != nil {
log.Print(err)
return
@@ -32,15 +43,15 @@ func Run(ch chan Event, jid string, pwd string) {
tr := newTokenRouter(&enc)
- end := sendStreamStart(&enc, jid)
+ end := sendStreamStart(&enc, c.jid)
defer sendStreamEnd(&enc, end)
- ch <- ConnectEvent
- defer func() { ch <- DisconnectEvent }()
+ c.ch <- ConnectEvent
+ defer func() { c.ch <- DisconnectEvent }()
for {
select {
- case ev := <-ch:
+ case ev := <-c.ch:
switch ev {
case ShouldDisconnectEvent:
return