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ยง
- create_
handshake_ request - Create a Request object for the initial HTTP request.
This request contains
Origin,Sec-WebSocket-Protocol,Authorization, andCookieheaders 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
Cookieor 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.