|
|
|
@ -154,8 +154,12 @@ func (h *hub) OnConnect(client Client, session *Session) {
@@ -154,8 +154,12 @@ func (h *hub) OnConnect(client Client, session *Session) {
|
|
|
|
|
log.Printf("Created client %d with id %s\n", client.Index(), session.Id) |
|
|
|
|
// Register connection or replace existing one.
|
|
|
|
|
if ec, ok := h.clients[session.Id]; ok { |
|
|
|
|
log.Printf("Closing obsolete client %d with id %s\n", ec.Index(), session.Id) |
|
|
|
|
ec.ReplaceAndClose() |
|
|
|
|
// Clean up old client at the end and make sure to run this in another go routine,
|
|
|
|
|
// to avoid blocking the new client if the old one hangs or whatever.
|
|
|
|
|
defer func() { |
|
|
|
|
log.Printf("Closing obsolete client %d with id %s\n", ec.Index(), session.Id) |
|
|
|
|
go ec.ReplaceAndClose() |
|
|
|
|
}() |
|
|
|
|
} |
|
|
|
|
h.clients[session.Id] = client |
|
|
|
|
h.mutex.Unlock() |
|
|
|
|