blob: 80c07a1e2cca3fdf553550345d045da109fc04b4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 }()
}
|