summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go/main.go45
1 files changed, 30 insertions, 15 deletions
diff --git a/go/main.go b/go/main.go
index 8bfb1fa..4688055 100644
--- a/go/main.go
+++ b/go/main.go
@@ -3,6 +3,7 @@ package main
import (
"image/color"
"log"
+ "net"
"os"
"gioui.org/app"
@@ -28,6 +29,7 @@ type Limox struct {
JidEditor widget.Editor
PwdEditor widget.Editor
MainButton widget.Clickable
+ XmppError chan error
State LimoxState
Window *app.Window
Operations op.Ops
@@ -56,21 +58,26 @@ func NewLimox() Limox {
),
Operations: op.Ops{},
Theme: material.NewTheme(gofont.Collection()),
+ XmppError: make(chan error),
State: Disconnected,
}
}
func (l *Limox) run() error {
for {
- e := <-l.Window.Events()
- switch e := e.(type) {
- case system.DestroyEvent:
- return e.Err
- case system.FrameEvent:
- if l.MainButton.Clicked() {
- l.buttonCallback()
+ select {
+ case e := <-l.Window.Events():
+ switch e := e.(type) {
+ case system.DestroyEvent:
+ return e.Err
+ case system.FrameEvent:
+ if l.MainButton.Clicked() {
+ l.buttonCallback()
+ }
+ l.draw(e)
}
- l.draw(e)
+ case <-l.XmppError:
+ l.State = Disconnected
}
}
}
@@ -79,7 +86,7 @@ func (l *Limox) buttonCallback() {
switch l.State {
case Disconnected:
log.Println("Starting connection establishment")
- go xmpp(l.JidEditor.Text(), l.PwdEditor.Text())
+ go l.xmpp(l.JidEditor.Text(), l.PwdEditor.Text())
l.State = Connecting
case Connecting:
log.Println("Aborted connection establishment")
@@ -90,9 +97,19 @@ func (l *Limox) buttonCallback() {
}
}
-func xmpp(jid string, pwd string) {
+func (l *Limox) xmpp(jid string, pwd string) {
log.Printf("JID: '%s' PWD: '%s'\n", jid, pwd)
- log.Printf("Domain: '%s'\n", domainpart(jid))
+
+ domain := domainpart(jid)
+ log.Printf("Domain: '%s'\n", domain)
+
+ tcpServer, err := net.ResolveTCPAddr("tcp", domain+":"+"5222")
+ if err != nil {
+ log.Print(err)
+ l.XmppError <- err
+ return
+ }
+ log.Printf("Server: %s\n", tcpServer)
}
// domainpart extracts the domain name from a JID / XMPP address. See
@@ -100,17 +117,15 @@ func xmpp(jid string, pwd string) {
func domainpart(jid string) string {
list := []rune(jid)
- for i, v := range(list) {
+ for i, v := range list {
if v == '/' {
- log.Printf("Index of / rune: %d\n", i)
list = list[:i]
break
}
}
- for i, v := range(list) {
+ for i, v := range list {
if v == '@' {
- log.Printf("Index of @ rune: %d\n", i)
list = list[i+1:]
break
}