Module net::websocket_loader
source Β· Expand description
The websocket handler has three main responsibilities:
- initiate the initial HTTP connection and process the response
- ensure any DOM requests for sending/closing are propagated to the network
- 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§
- 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
, andCookie
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_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.