func onAccept(s *gotalk.Sock) { // Keep track of connected sockets socksmu.Lock() defer socksmu.Unlock() socks[s] = 1 s.CloseHandler = func(s *gotalk.Sock, _ int) { socksmu.Lock() defer socksmu.Unlock() delete(socks, s) } // Send list of rooms roomsmu.RLock() defer roomsmu.RUnlock() s.Notify("rooms", rooms) // Assign the socket a random username username := randomName() s.UserData = username s.Notify("username", username) }
func onAccept(s *gotalk.Sock) { c := client.NewClient() s.UserData = c fmt.Printf("New accepted connection. [%s]\n", c.ID) }