From 4466bb0ef569f976f3a13753eea7369a6450d0c5 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Fri, 31 Mar 2023 12:40:15 -0700 Subject: [PATCH] Revert "Disable WebSocket compression and see if it helps with Safari" This reverts commit f3354f2f1cbd4fa094ccd6fe08400e8d916e4527. --- pkg/websocket.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/pkg/websocket.go b/pkg/websocket.go index 9912575..c622e04 100644 --- a/pkg/websocket.go +++ b/pkg/websocket.go @@ -30,8 +30,7 @@ type Subscriber struct { conn *websocket.Conn ctx context.Context cancel context.CancelFunc - messages chan []byte // WebSocket outgoing queue - cooldown sync.Mutex // don't spam messages out the WS + messages chan []byte closeSlow func() muteMu sync.RWMutex @@ -114,12 +113,7 @@ func (sub *Subscriber) SendJSON(v interface{}) error { return err } log.Debug("SendJSON(%d=%s): %s", sub.ID, sub.Username, data) - - // Write it to their outgoing channel so we can rate limit in case of Safari browsers - // which get overwhelmed with too many messages. - sub.messages <- data - // return sub.conn.Write(sub.ctx, websocket.MessageText, data) - return nil + return sub.conn.Write(sub.ctx, websocket.MessageText, data) } // SendMe sends the current user state to the client. @@ -146,9 +140,7 @@ func (s *Server) WebSocket() http.HandlerFunc { ip := util.IPAddress(r) log.Info("WebSocket connection from %s - %s", ip, r.Header.Get("User-Agent")) log.Debug("Headers: %+v", r.Header) - c, err := websocket.Accept(w, r, &websocket.AcceptOptions{ - CompressionMode: websocket.CompressionDisabled, - }) + c, err := websocket.Accept(w, r, nil) if err != nil { w.WriteHeader(http.StatusInternalServerError) fmt.Fprintf(w, "Could not accept websocket connection: %s", err) @@ -185,11 +177,7 @@ func (s *Server) WebSocket() http.HandlerFunc { for { select { case msg := <-sub.messages: - // Don't spam messages too quick. - sub.cooldown.Lock() err = writeTimeout(ctx, time.Second*5, c, msg) - time.Sleep(100 * time.Second) - sub.cooldown.Unlock() if err != nil { return }