Revert "Disable WebSocket compression and see if it helps with Safari"
This reverts commit f3354f2f1c
.
This commit is contained in:
parent
f3354f2f1c
commit
4466bb0ef5
|
@ -30,8 +30,7 @@ type Subscriber struct {
|
||||||
conn *websocket.Conn
|
conn *websocket.Conn
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
messages chan []byte // WebSocket outgoing queue
|
messages chan []byte
|
||||||
cooldown sync.Mutex // don't spam messages out the WS
|
|
||||||
closeSlow func()
|
closeSlow func()
|
||||||
|
|
||||||
muteMu sync.RWMutex
|
muteMu sync.RWMutex
|
||||||
|
@ -114,12 +113,7 @@ func (sub *Subscriber) SendJSON(v interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debug("SendJSON(%d=%s): %s", sub.ID, sub.Username, data)
|
log.Debug("SendJSON(%d=%s): %s", sub.ID, sub.Username, data)
|
||||||
|
return sub.conn.Write(sub.ctx, websocket.MessageText, 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMe sends the current user state to the client.
|
// SendMe sends the current user state to the client.
|
||||||
|
@ -146,9 +140,7 @@ func (s *Server) WebSocket() http.HandlerFunc {
|
||||||
ip := util.IPAddress(r)
|
ip := util.IPAddress(r)
|
||||||
log.Info("WebSocket connection from %s - %s", ip, r.Header.Get("User-Agent"))
|
log.Info("WebSocket connection from %s - %s", ip, r.Header.Get("User-Agent"))
|
||||||
log.Debug("Headers: %+v", r.Header)
|
log.Debug("Headers: %+v", r.Header)
|
||||||
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
|
c, err := websocket.Accept(w, r, nil)
|
||||||
CompressionMode: websocket.CompressionDisabled,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
fmt.Fprintf(w, "Could not accept websocket connection: %s", err)
|
fmt.Fprintf(w, "Could not accept websocket connection: %s", err)
|
||||||
|
@ -185,11 +177,7 @@ func (s *Server) WebSocket() http.HandlerFunc {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case msg := <-sub.messages:
|
case msg := <-sub.messages:
|
||||||
// Don't spam messages too quick.
|
|
||||||
sub.cooldown.Lock()
|
|
||||||
err = writeTimeout(ctx, time.Second*5, c, msg)
|
err = writeTimeout(ctx, time.Second*5, c, msg)
|
||||||
time.Sleep(100 * time.Second)
|
|
||||||
sub.cooldown.Unlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user