-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.go
47 lines (41 loc) · 917 Bytes
/
messages.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
package main
// WS MESSGES FROM FRONT END
type Message struct {
MessageType string
BidderId string
Body map[string]interface{}
Subscriber *Subscriber
rawJson []byte
}
type NewBidderBody struct {
Name string `json:"name"`
Cap int `json:"cap"`
Spots int `json:"space"`
}
type TokenBody struct {
Token string `json:"token"`
}
type NominationBody struct {
PlayerName string `json:"name"`
BidderId string `json:"bidderId"`
}
// SEND MESSAGE TO ALL CLIENTS
func broadcastMessage(h *DraftHub, message []byte) {
for client := range h.clients {
select {
case client.send <- message:
default:
close(client.send)
delete(h.clients, client)
}
}
}
// SEND MESSAGE TO A SINGLE CLIENT
func sendMessageToSubscriber(h *DraftHub, c *Subscriber, message []byte) {
select {
case c.send <- message:
default:
close(c.send)
delete(h.clients, c)
}
}