-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbroadcast.go
48 lines (39 loc) · 1.24 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
package carrot
import (
log "github.com/sirupsen/logrus"
)
/*
Response groups are enumerated by the constants in this file.
To add a new response group, add it to the list of constants
at the start of the file.
*/
type Broadcast struct {
broadcaster Broadcaster
logger *log.Entry
}
// NewBroadcast initializes a new instance of the Broadcast struct.
func NewBroadcast(broadcaster Broadcaster) *Broadcast {
return &Broadcast{
broadcaster: broadcaster,
logger: log.WithField("module", "broadcast"),
}
}
/*
// ...string []string
Broadcast(message, "sessiontoken", "sessiontoken")
Broadcast(message, sessionTokens)
Broadcast(message)
Broadcast(message, req.SessionToken)
func (c *TestController) EchoToSomePeople(req *carrot.Request, broadcast *carrot.Broadcast) {
response := carrot.Response()
response.AddParam("hello": "world")
response.Build()
responseGroup = mysql.find(/*query to find users).SessionTokens
broadcast.Broadcast(message, responseGroup)
}
*/
// Broadcast allows controllers to send responses to all or a subset of listening devices.
func (b *Broadcast) Broadcast(message []byte, sessions ...string) {
b.logger.Debug("sending message")
b.broadcaster.broadcast <- OutboundMessage(message, sessions)
}