Module net::websocket_loader

source Β·
Expand description

The websocket handler has three main responsibilities:

  1. initiate the initial HTTP connection and process the response
  2. ensure any DOM requests for sending/closing are propagated to the network
  3. transmit any incoming messages/closing to the DOM

In order to accomplish this, the handler uses a long-running loop that selects over events from the network and events from the DOM, using async/await to avoid the need for a dedicated thread per websocket.

Enums§

Functions§

  • connect πŸ”’
    Create a new websocket connection for the given request.
  • create_request πŸ”’
    Create a tungstenite Request object for the initial HTTP request. This request contains Origin, Sec-WebSocket-Protocol, Authorization, and Cookie headers as appropriate. Returns an error if any header values are invalid or tungstenite cannot create the desired request.
  • Create a new websocket connection for the given request.
  • Process an HTTP response resulting from a WS handshake. This ensures that any Cookie or HSTS headers are recognized. Returns an error if the protocol selected by the handshake doesn’t match the list of provided protocols in the original request.
  • run_ws_loop πŸ”’
    Listen for WS events from the DOM and the network until one side closes the connection or an error occurs. Since this is an async function that uses the select operation, it will run as a task on the WS tokio runtime.
  • Initialize a listener for DOM actions. These are routed from the IPC channel to a tokio channel that the main WS client task uses to receive them.
  • start_websocket πŸ”’
    Initiate a new async WS connection. Returns an error if the connection fails for any reason, or if the response isn’t valid. Otherwise, the endless WS listening loop will be started.