Skip to content

Commit

Permalink
Add connect function
Browse files Browse the repository at this point in the history
yukibtc committed Mar 27, 2024
1 parent 618b4ee commit 00add37
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<SocketAddr>,
timeout: Option<Duration>,
) -> 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))
}

0 comments on commit 00add37

Please sign in to comment.