"""
This type stub file was generated by pyright.
"""

from typing import Any, Final, TYPE_CHECKING
from tornado.websocket import WebSocketHandler
from streamlit.runtime import Runtime, SessionClient
from collections.abc import Awaitable
from streamlit.proto.ForwardMsg_pb2 import ForwardMsg

if TYPE_CHECKING:
    ...
_LOGGER: Final = ...
class BrowserWebSocketHandler(WebSocketHandler, SessionClient):
    """Handles a WebSocket connection from the browser."""
    def initialize(self, runtime: Runtime) -> None:
        ...
    
    def get_signed_cookie(self, name: str, value: str | None = ..., max_age_days: float = ..., min_version: int | None = ...) -> bytes | None:
        """Get a signed cookie from the request. Added for compatibility with
        Tornado < 6.3.0.

        See release notes: https://www.tornadoweb.org/en/stable/releases/v6.3.0.html#deprecation-notices
        """
        ...
    
    def check_origin(self, origin: str) -> bool:
        """Set up CORS."""
        ...
    
    def write_forward_msg(self, msg: ForwardMsg) -> None:
        """Send a ForwardMsg to the browser."""
        ...
    
    def select_subprotocol(self, subprotocols: list[str]) -> str | None:
        """Return the first subprotocol in the given list.

        This method is used by Tornado to select a protocol when the
        Sec-WebSocket-Protocol header is set in an HTTP Upgrade request.

        NOTE: We repurpose the Sec-WebSocket-Protocol header here in a slightly
        unfortunate (but necessary) way. The browser WebSocket API doesn't allow us to
        set arbitrary HTTP headers, and this header is the only one where we have the
        ability to set it to arbitrary values, so we use it to pass tokens (in this
        case, the previous session ID to allow us to reconnect to it) from client to
        server as the *third* value in the list.

        The reason why the auth token is set as the third value is that:
          - when Sec-WebSocket-Protocol is set, many clients expect the server to
            respond with a selected subprotocol to use. We don't want that reply to be
            the session token, so we by convention have the client always set the first
            protocol to "streamlit" and select that.
          - the second protocol in the list is reserved in some deployment environments
            for an auth token that we currently don't use
        """
        ...
    
    def open(self, *args, **kwargs) -> Awaitable[None] | None:
        ...
    
    def on_close(self) -> None:
        ...
    
    def get_compression_options(self) -> dict[Any, Any] | None:
        """Enable WebSocket compression.

        Returning an empty dict enables websocket compression. Returning
        None disables it.

        (See the docstring in the parent class.)
        """
        ...
    
    def on_message(self, payload: str | bytes) -> None:
        ...
    


