summaryrefslogtreecommitdiff
path: root/xmpp/session.go
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp/session.go')
-rw-r--r--xmpp/session.go42
1 files changed, 20 insertions, 22 deletions
diff --git a/xmpp/session.go b/xmpp/session.go
index 80c07a1..2e7bade 100644
--- a/xmpp/session.go
+++ b/xmpp/session.go
@@ -1,46 +1,44 @@
package xmpp
import (
- "time"
"log"
+ "time"
)
+type SessionConnect struct{}
+type SessionDisconnect struct{}
+type SessionShouldDisconnect struct{}
+
type Session struct {
- in, Out chan Event
+ in, out chan any
}
-func NewSession(jid string, pwd string) *Session {
+func StartSession(out chan any, jid string, pwd string) chan any {
s := Session{}
- s.in = make(chan Event)
- s.Out = make(chan Event)
+ s.in = make(chan any)
+ s.out = out
+
+ go s.run()
- return &s
+ return s.in
}
-func (s *Session) Run() {
- defer func() { s.Out <- DisconnectEvent }()
+func (s *Session) run() {
+ defer func() { s.out <- SessionDisconnect{} }()
- s.init()
+ time.Sleep(time.Second) // faked connect time
+ s.out <- SessionConnect{}
for {
select {
- case ev := <-s.in:
- switch ev {
- case ShouldDisconnectEvent:
+ case data := <-s.in:
+ switch data.(type) {
+ case SessionShouldDisconnect:
return
default:
- log.Printf("Unknown Event '%d'!\n", ev)
+ log.Printf("Unknown data '%d'!\n", data)
}
}
}
}
-
-func (s *Session) init() {
- time.Sleep(time.Second)
- s.Out <- ConnectEvent
-}
-
-func (s *Session) Close() {
- go func(){ s.in <- ShouldDisconnectEvent }()
-}