Keep the greeting around and push it to new clients

This commit is contained in:
Ian Gulliver
2016-03-11 12:06:32 -08:00
parent 251c577cb8
commit 2ad7ad7a8f

View File

@@ -5,6 +5,7 @@ type hub struct {
broadcast chan []byte
register chan *connection
unregister chan *connection
greeting []byte
}
var h = hub{
@@ -19,6 +20,7 @@ func (h *hub) run() {
select {
case c := <-h.register:
h.connections[c] = true
c.send <- h.greeting
case c := <-h.unregister:
_, ok := h.connections[c]
@@ -28,6 +30,9 @@ func (h *hub) run() {
}
case m := <-h.broadcast:
if len(h.greeting) == 0 {
h.greeting = m
}
for c := range h.connections {
select {
case c.send <- m: