1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-07 14:56:25 +01:00

tweak for chrome since it works great in firefox but chrome cannot handle it

This commit is contained in:
J. Nick Koston
2024-05-25 13:16:44 -10:00
parent f3d2003dca
commit 439e2d76b1
2 changed files with 6 additions and 5 deletions
@@ -22,6 +22,7 @@ type AsyncWebSocketCommandHandler = Callable[
DOMAIN: Final = "websocket_api"
URL: Final = "/api/websocket"
PENDING_MSG_PEAK: Final = 1024
READY_FUTURE_MAX_MESSAGES: Final = 128
PENDING_MSG_PEAK_TIME: Final = 5
# Maximum number of messages that can be pending at any given time.
# This is effectively the upper limit of the number of entities
@@ -26,6 +26,7 @@ from .const import (
MAX_PENDING_MSG,
PENDING_MSG_PEAK,
PENDING_MSG_PEAK_TIME,
READY_FUTURE_MAX_MESSAGES,
SIGNAL_WEBSOCKET_CONNECTED,
SIGNAL_WEBSOCKET_DISCONNECTED,
URL,
@@ -247,7 +248,9 @@ class WebSocketHandler:
We will release the ready future if the queue did not grow since the
last time we tried to release the ready future.
If we reach the peak, we will release the ready future immediately.
If we reach READY_FUTURE_MAX_MESSAGES, we will release the ready
future immediately so avoid the messages getting to large which
can cause Chrome to stall (not not firefox).
"""
if (
not (ready_future := self._ready_future)
@@ -256,10 +259,7 @@ class WebSocketHandler:
):
self._release_ready_queue_size = 0
return
# If we are below the peak and there are new messages in the queue
# since the last time we tried to release the ready future, we try again
# later so we can coalesce more messages.
if queue_size > self._release_ready_queue_size < PENDING_MSG_PEAK:
if queue_size > self._release_ready_queue_size < READY_FUTURE_MAX_MESSAGES:
self._release_ready_queue_size = queue_size
self._loop.call_soon(self._release_ready_future_or_reschedule)
return