mirror of
https://github.com/owncast/owncast.git
synced 2024-11-25 06:12:23 +03:00
Pass along just the client id instead a reference to the entire client when unregistering the client
This commit is contained in:
parent
f07c9e2e00
commit
f85b54cfeb
3 changed files with 7 additions and 7 deletions
|
@ -25,7 +25,7 @@ func GetChatMessages(w http.ResponseWriter, r *http.Request) {
|
|||
messages := chat.GetChatHistory()
|
||||
|
||||
if err := json.NewEncoder(w).Encode(messages); err != nil {
|
||||
log.Errorln(err)
|
||||
log.Debugln(err)
|
||||
}
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotImplemented)
|
||||
|
|
|
@ -155,7 +155,7 @@ func (c *ChatClient) close() {
|
|||
log.Traceln("client closed:", c.User.DisplayName, c.id, c.ipAddress)
|
||||
|
||||
c.conn.Close()
|
||||
c.server.unregister <- c
|
||||
c.server.unregister <- c.id
|
||||
if c.send != nil {
|
||||
close(c.send)
|
||||
c.send = nil
|
||||
|
|
|
@ -32,7 +32,7 @@ type ChatServer struct {
|
|||
inbound chan chatClientEvent
|
||||
|
||||
// unregister requests from clients.
|
||||
unregister chan *ChatClient
|
||||
unregister chan uint // the ChatClient id
|
||||
}
|
||||
|
||||
func NewChat() *ChatServer {
|
||||
|
@ -40,7 +40,7 @@ func NewChat() *ChatServer {
|
|||
clients: map[uint]*ChatClient{},
|
||||
outbound: make(chan []byte),
|
||||
inbound: make(chan chatClientEvent),
|
||||
unregister: make(chan *ChatClient),
|
||||
unregister: make(chan uint),
|
||||
maxClientCount: handleMaxConnectionCount(),
|
||||
}
|
||||
|
||||
|
@ -50,10 +50,10 @@ func NewChat() *ChatServer {
|
|||
func (s *ChatServer) Run() {
|
||||
for {
|
||||
select {
|
||||
case client := <-s.unregister:
|
||||
if _, ok := s.clients[client.id]; ok {
|
||||
case clientId := <-s.unregister:
|
||||
if _, ok := s.clients[clientId]; ok {
|
||||
s.mu.Lock()
|
||||
delete(s.clients, client.id)
|
||||
delete(s.clients, clientId)
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue