summaryrefslogtreecommitdiff
path: root/xmpp/session.go
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp/session.go')
-rw-r--r--xmpp/session.go46
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 }()
+}