/
broadcast.go
62 lines (49 loc) · 1.29 KB
/
broadcast.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package api_ws
import (
)
//------------------------------------------------------------
// WebSocket broadcast
//------------------------------------------------------------
// Returns public broadcaster.
func GetBroadcaster_Public() func(string, interface{}) (err error) {
return broadcastPublic
}
// Returns authenticated broadcaster.
func GetBroadcaster_Authd() func(string, interface{}) (err error) {
return broadcastAuthd
}
// Broadcasts to open public websocket connections.
func broadcastPublic(op string, data interface{}) (err error) {
//fmt.Println(DumpConnsPublic("BROADCAST PUBLIC"))
/* OLD STYLE:
for _, ws := range _connsPublic {
if ws.isOpen {
ws.chanOut <- NewResponse_Broadcast(0, op, data)
}
}
*/
_chanBroadcast <- &Message{
isAuthd: false,
res: NewResponse_Broadcast(0, op, data),
}
return
}
// Broadcasts to open authenticated websocket connections.
func broadcastAuthd(op string, data interface{}) (err error) {
//fmt.Println(DumpConnsAuthd("BROADCAST AUTHD"))
/* OLD STYLE:
for _, conns := range _connsAuthd {
for _, ws := range conns {
if ws.isOpen {
ws.chanOut <- NewResponse_Broadcast(0, op, data)
}
}
}
*/
// XXX via channel
_chanBroadcast <- &Message{
isAuthd: true,
res: NewResponse_Broadcast(0, op, data),
}
return
}