Skip to main content

web_transport_ws/
server.rs

1use tokio::io::{AsyncRead, AsyncWrite};
2
3/// A WebTransport server that accepts WebSocket connections.
4///
5/// # Deprecated
6///
7/// Use [`qmux::ws::Server`] instead.
8#[deprecated(note = "use qmux::ws::Server instead")]
9#[derive(Default, Clone)]
10pub struct Server {
11    inner: qmux::ws::Server,
12}
13
14#[allow(deprecated)]
15impl Server {
16    pub fn new() -> Self {
17        Self::default()
18    }
19
20    /// Add a supported application-level subprotocol for negotiation.
21    pub fn with_protocol(mut self, protocol: &str) -> Self {
22        self.inner = self.inner.with_protocol(protocol);
23        self
24    }
25
26    /// Add multiple supported application-level subprotocols for negotiation.
27    pub fn with_protocols(mut self, protocols: &[&str]) -> Self {
28        self.inner = self.inner.with_protocols(protocols);
29        self
30    }
31
32    /// Accept a WebSocket connection, negotiating the subprotocol.
33    pub async fn accept<T: AsyncRead + AsyncWrite + Unpin + Send + 'static>(
34        &self,
35        socket: T,
36    ) -> Result<qmux::Session, qmux::Error> {
37        self.inner.accept(socket).await
38    }
39}