#![forbid(unsafe_code)]
#![warn(clippy::large_futures)]
#![cfg_attr(feature = "default", doc = include_str!("../README.md"))]
#[cfg(all(feature = "socks", not(target_arch = "wasm32")))]
use std::net::SocketAddr;
pub use futures_util;
pub use url::{self, Url};
pub mod message;
#[cfg(not(target_arch = "wasm32"))]
pub mod native;
pub mod prelude;
mod socket;
#[cfg(target_arch = "wasm32")]
pub mod wasm;
pub use self::message::Message;
#[cfg(not(target_arch = "wasm32"))]
pub use self::native::Error;
pub use self::socket::WebSocket;
#[cfg(target_arch = "wasm32")]
pub use self::wasm::Error;
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ConnectionMode {
#[default]
Direct,
#[cfg(all(feature = "socks", not(target_arch = "wasm32")))]
Proxy(SocketAddr),
}
impl ConnectionMode {
#[inline]
pub fn direct() -> Self {
Self::Direct
}
#[inline]
#[cfg(all(feature = "socks", not(target_arch = "wasm32")))]
pub fn proxy(addr: SocketAddr) -> Self {
Self::Proxy(addr)
}
}
#[inline]
pub async fn connect(url: &Url, mode: &ConnectionMode) -> Result<WebSocket, Error> {
WebSocket::connect(url, mode).await
}