diff options
author | xengineering <me@xengineering.eu> | 2023-06-03 20:20:30 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-06-03 20:21:11 +0200 |
commit | 30d99c706e3a75948c49289fc6b0317258957819 (patch) | |
tree | 76d63751700e6946655e08cb71553b2f4a19c816 /xmpp/session.go | |
parent | f1633a2ab8cb10cb49642c16700379270fb9dc99 (diff) | |
download | limox-30d99c706e3a75948c49289fc6b0317258957819.tar limox-30d99c706e3a75948c49289fc6b0317258957819.tar.zst limox-30d99c706e3a75948c49289fc6b0317258957819.zip |
Implement dummy session
Minimal step towards session-based XMPP architecture.
Diffstat (limited to 'xmpp/session.go')
-rw-r--r-- | xmpp/session.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/xmpp/session.go b/xmpp/session.go new file mode 100644 index 0000000..80c07a1 --- /dev/null +++ b/xmpp/session.go @@ -0,0 +1,46 @@ +package xmpp + +import ( + "time" + "log" +) + +type Session struct { + in, Out chan Event +} + +func NewSession(jid string, pwd string) *Session { + s := Session{} + + s.in = make(chan Event) + s.Out = make(chan Event) + + return &s +} + +func (s *Session) Run() { + defer func() { s.Out <- DisconnectEvent }() + + s.init() + + for { + select { + case ev := <-s.in: + switch ev { + case ShouldDisconnectEvent: + return + default: + log.Printf("Unknown Event '%d'!\n", ev) + } + } + } +} + +func (s *Session) init() { + time.Sleep(time.Second) + s.Out <- ConnectEvent +} + +func (s *Session) Close() { + go func(){ s.in <- ShouldDisconnectEvent }() +} |