diff --git a/web/Cargo.toml b/web/Cargo.toml index 30f5a45..954f21c 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -37,8 +37,9 @@ letterbox-shared = { version = "0.14.0", path = "../shared", registry = "xinu" } letterbox-notmuch = { version = "0.14.0", path = "../notmuch", registry = "xinu" } seed_hooks = { version = "0.4.0", registry = "xinu" } strum_macros = "0.27.1" -wasm-sockets = "1.0.0" gloo-console = "0.3.0" +[target.'cfg(target_arch = "wasm32")'.dependencies] +wasm-sockets = "1.0.0" [package.metadata.wasm-pack.profile.release] wasm-opt = ['-Os'] diff --git a/web/src/websocket.rs b/web/src/websocket.rs index f998fed..fdb855c 100644 --- a/web/src/websocket.rs +++ b/web/src/websocket.rs @@ -4,7 +4,63 @@ use letterbox_shared::WebsocketMessage; use log::{error, info}; use seed::prelude::*; use serde::{Deserialize, Serialize}; -use wasm_sockets::{self, ConnectionStatus, EventClient, Message, WebSocketError}; +#[cfg(not(target_arch = "wasm32"))] +#[allow(dead_code)] +mod wasm_sockets { + use std::{cell::RefCell, rc::Rc}; + + use thiserror::Error; + use web_sys::{CloseEvent, ErrorEvent}; + + #[derive(Debug)] + pub struct JsValue; + #[derive(Debug)] + pub enum ConnectionStatus { + /// Connecting to a server + Connecting, + /// Connected to a server + Connected, + /// Disconnected from a server due to an error + Error, + /// Disconnected from a server without an error + Disconnected, + } + #[derive(Debug)] + pub struct EventClient { + pub status: Rc>, + } + impl EventClient { + pub fn new(_: &str) -> Result { + todo!("this is a mock") + } + pub fn send_string(&self, _essage: &str) -> Result<(), JsValue> { + todo!("this is a mock") + } + pub fn set_on_error(&mut self, _: Option>) { + todo!("this is a mock") + } + pub fn set_on_connection(&mut self, _: Option>) { + todo!("this is a mock") + } + pub fn set_on_close(&mut self, _: Option>) { + todo!("this is a mock") + } + pub fn set_on_message(&mut self, _: Option>) { + todo!("this is a mock") + } + } + #[derive(Debug, Clone)] + pub enum Message { + Text(String), + Binary(Vec), + } + #[derive(Debug, Clone, Error)] + pub enum WebSocketError {} +} +#[cfg(not(target_arch = "wasm32"))] +use wasm_sockets::{ConnectionStatus, EventClient, Message, WebSocketError}; +#[cfg(target_arch = "wasm32")] +use wasm_sockets::{ConnectionStatus, EventClient, Message, WebSocketError}; use web_sys::CloseEvent; /// Message from the server to the client. @@ -142,9 +198,9 @@ fn create_websocket(orders: &impl Orders) -> Result