blob: 2e7bade6f9015686f6f3fd9828127ff2f8d0545b (
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
|
package xmpp
import (
"log"
"time"
)
type SessionConnect struct{}
type SessionDisconnect struct{}
type SessionShouldDisconnect struct{}
type Session struct {
in, out chan any
}
func StartSession(out chan any, jid string, pwd string) chan any {
s := Session{}
s.in = make(chan any)
s.out = out
go s.run()
return s.in
}
func (s *Session) run() {
defer func() { s.out <- SessionDisconnect{} }()
time.Sleep(time.Second) // faked connect time
s.out <- SessionConnect{}
for {
select {
case data := <-s.in:
switch data.(type) {
case SessionShouldDisconnect:
return
default:
log.Printf("Unknown data '%d'!\n", data)
}
}
}
}
|