Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Centralize chan closure to be done in the client, not the server. Set chan size to max message size.

Gabe Kangas5d7462b69fd3
diff --git a/core/chat/chatclient.go b/core/chat/chatclient.go
index 69015b0070..12af7e75eb 100644
--- a/core/chat/chatclient.go
+++ b/core/chat/chatclient.go
@@ -156,6 +156,10 @@ func (c *ChatClient) close() {
c.conn.Close()
c.server.unregister <- c
+ if c.send != nil {
+ close(c.send)
+ c.send = nil
+ }
}
func (c *ChatClient) passesRateLimit() bool {
@@ -175,7 +179,9 @@ func (c *ChatClient) sendPayload(payload events.EventPayload) {
return
}
- c.send <- data
+ if c.send != nil {
+ c.send <- data
+ }
}
func (c *ChatClient) sendAction(message string) {
diff --git a/core/chat/server.go b/core/chat/server.go
index 55388bd1af..240f32d3fb 100644
--- a/core/chat/server.go
+++ b/core/chat/server.go
@@ -54,7 +54,6 @@ func (s *ChatServer) Run() {
if _, ok := s.clients[client.id]; ok {
s.mu.Lock()
delete(s.clients, client.id)
- close(client.send)
s.mu.Unlock()
}
@@ -72,7 +71,7 @@ func (s *ChatServer) Addclient(conn *websocket.Conn, user *user.User, accessToke
User: user,
ipAddress: conn.RemoteAddr().String(),
accessToken: accessToken,
- send: make(chan []byte, 256),
+ send: make(chan []byte, maxMessageSize),
UserAgent: userAgent,
ConnectedAt: time.Now(),
}
@@ -195,7 +194,7 @@ func (s *ChatServer) Broadcast(payload events.EventPayload) error {
select {
case client.send <- data:
default:
- close(client.send)
+ client.close()
delete(s.clients, client.id)
}
}