Module websocket_loader

Module 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ยง

DomMsg ๐Ÿ”’

Functionsยง

create_handshake_request
Create a 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.
process_ws_response ๐Ÿ”’
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.
setup_dom_listener ๐Ÿ”’
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.