summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-21 13:12:23 +0200
committerxengineering <me@xengineering.eu>2023-05-21 13:12:23 +0200
commit1d46cedcbb92edf69f080bf3dca07509a14159e2 (patch)
tree499fe796a6450f23e44fb82db1baf166fa1cf34d
parent37753409dc55da1a1cc3feed139f287a2d6215bb (diff)
downloadlimox-1d46cedcbb92edf69f080bf3dca07509a14159e2.tar
limox-1d46cedcbb92edf69f080bf3dca07509a14159e2.tar.zst
limox-1d46cedcbb92edf69f080bf3dca07509a14159e2.zip
Introduce xengineering.eu/xmpp.Conn
-rw-r--r--limox.go3
-rw-r--r--xmpp/xmpp.go23
2 files changed, 19 insertions, 7 deletions
diff --git a/limox.go b/limox.go
index 620f009..a7c00e1 100644
--- a/limox.go
+++ b/limox.go
@@ -86,7 +86,8 @@ func (l *Limox) buttonCallback() {
pwd := l.PwdEditor.Text()
setLastJid(jid)
setLastPwd(pwd)
- go xmpp.Run(l.XmppConn, jid, pwd)
+ c := xmpp.NewConn(l.XmppConn, jid, pwd)
+ go c.Run()
l.State = Connecting
case Connecting:
log.Println("Aborted connection establishment")
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