From 00add37ae12f6e49bf7a98b616323dde2d1f9a71 Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Wed, 27 Mar 2024 10:24:39 +0100 Subject: [PATCH] Add `connect` function --- src/lib.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8c17323..6be622c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,11 @@ #![forbid(unsafe_code)] +use std::net::SocketAddr; +use std::time::Duration; + pub use futures_util; -pub use url; +pub use url::{self, Url}; #[cfg(target_arch = "wasm32")] pub use wasm_ws::WsMessage; @@ -16,6 +19,23 @@ pub mod native; pub mod wasm; #[cfg(not(target_arch = "wasm32"))] -pub use self::native::{Message as WsMessage, Sink, Stream}; +pub use self::native::{Error, Message as WsMessage, Sink, Stream}; #[cfg(target_arch = "wasm32")] -pub use self::wasm::{Sink, Stream}; +pub use self::wasm::{Error, Sink, Stream}; + +/// Connect +/// +/// **Proxy is ignored for WASM targets!** +pub async fn connect( + url: &Url, + _proxy: Option, + timeout: Option, +) -> Result<(Sink, Stream), Error> { + #[cfg(not(target_arch = "wasm32"))] + let (tx, rx) = self::native::connect(url, _proxy, timeout).await?; + + #[cfg(target_arch = "wasm32")] + let (tx, rx) = self::wasm::connect(url, timeout).await?; + + Ok((tx, rx)) +}