Skip to main content

web_transport_ws/
client.rs

1/// A WebTransport client that connects over WebSocket.
2///
3/// # Deprecated
4///
5/// Use [`qmux::ws::Client`] instead.
6#[deprecated(note = "use qmux::ws::Client instead")]
7#[derive(Default, Clone)]
8pub struct Client {
9    inner: qmux::ws::Client,
10}
11
12#[allow(deprecated)]
13impl Client {
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    /// Add a supported application-level subprotocol for negotiation.
19    pub fn with_protocol(mut self, protocol: &str) -> Self {
20        self.inner = self.inner.with_protocol(protocol);
21        self
22    }
23
24    /// Add multiple supported application-level subprotocols for negotiation.
25    pub fn with_protocols(mut self, protocols: &[&str]) -> Self {
26        self.inner = self.inner.with_protocols(protocols);
27        self
28    }
29
30    /// Set the WebSocket configuration (e.g. max message/frame sizes).
31    pub fn with_config(mut self, config: qmux::tungstenite::protocol::WebSocketConfig) -> Self {
32        self.inner = self.inner.with_config(config);
33        self
34    }
35
36    /// Set the TLS connector for secure WebSocket connections.
37    #[cfg(any(
38        feature = "rustls-tls-native-roots",
39        feature = "rustls-tls-webpki-roots"
40    ))]
41    pub fn with_connector(mut self, connector: qmux::tokio_tungstenite::Connector) -> Self {
42        self.inner = self.inner.with_connector(connector);
43        self
44    }
45
46    /// Connect to a WebSocket server, negotiating the configured subprotocols.
47    pub async fn connect(&self, url: &str) -> Result<qmux::Session, qmux::Error> {
48        self.inner.connect(url).await
49    }
50}