diff --git a/Cargo.toml b/Cargo.toml index 7b929ecd67fd3fa692a392de4b0d335abbade1df..7ad8ed38f7bde2a486392f3314a66802f3dabce5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-sockets" -version = "0.1.0" +version = "0.2.0" authors = ["scratchyone <scratchywon@gmail.com>"] edition = "2018" license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index 3bf83c597f23eaf3294ebf9eb5a48dec82c3d68d..01f781fc3dfd4c4a42db8c73bf3996da1ba6b3aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,6 +96,9 @@ use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; use web_sys::{ErrorEvent, MessageEvent, WebSocket}; +#[cfg(not(target_arch = "wasm32"))] +compile_error!("wasm-sockets can only compile to WASM targets"); + #[derive(Debug, Clone, PartialEq)] pub enum ConnectionStatus { /// Connecting to a server @@ -116,6 +119,7 @@ pub enum Message { /// A binary message Binary(Vec<u8>), } +#[cfg(target_arch = "wasm32")] pub struct PollingClient { /// The URL this client is connected to pub url: String, @@ -125,6 +129,7 @@ pub struct PollingClient { pub status: Rc<RefCell<ConnectionStatus>>, data: Rc<RefCell<Vec<Message>>>, } +#[cfg(target_arch = "wasm32")] // TODO: Replace unwraps and JsValue with custom error type impl PollingClient { /// Create a new PollingClient and connect to a WebSocket URL