summaryrefslogtreecommitdiff
path: root/xmpp/session.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-06-03 20:52:45 +0200
committerxengineering <me@xengineering.eu>2023-06-03 20:52:45 +0200
commite313bce92afea09b2da657b5a4f7de2c958c0100 (patch)
tree8975cb4432d2ed5195b3902c80cd5e702ea40cc0 /xmpp/session.go
parent30d99c706e3a75948c49289fc6b0317258957819 (diff)
downloadlimox-e313bce92afea09b2da657b5a4f7de2c958c0100.tar
limox-e313bce92afea09b2da657b5a4f7de2c958c0100.tar.zst
limox-e313bce92afea09b2da657b5a4f7de2c958c0100.zip
Introduce new communication pattern
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 }()
-}