lighthouse_client/connect/
tokio.rs

1use async_tungstenite::{WebSocketStream, tokio::{ConnectStream, connect_async}};
2use lighthouse_protocol::Authentication;
3
4use crate::{Result, Lighthouse, LIGHTHOUSE_URL, TokioSpawner};
5
6pub type TokioWebSocket = WebSocketStream<ConnectStream>;
7
8impl Lighthouse<TokioWebSocket> {
9    /// Connects to the lighthouse server at the given URL.
10    pub async fn connect_with_tokio_to(url: &str, authentication: Authentication) -> Result<Self> {
11        let (web_socket, _) = connect_async(url).await?;
12        Self::new::<TokioSpawner>(web_socket, authentication)
13    }
14
15    /// Connects to the lighthouse server at the default URL.
16    pub async fn connect_with_tokio(authentication: Authentication) -> Result<Self> {
17        Self::connect_with_tokio_to(LIGHTHOUSE_URL, authentication).await
18    }
19}