From 13ef3e40a8977abef0f2e56d9d2df5db4f488d9a Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Fri, 19 Jan 2024 13:46:51 +0100 Subject: [PATCH] testingg --- Cargo.toml | 2 +- src/gateway/heartbeat.rs | 31 ++++++++++++++++++++++++++----- tests/gateway.rs | 4 ---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 41f06a9..a38d7c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,7 @@ hostname = "0.3.1" getrandom = { version = "0.2.12", features = ["js"] } ws_stream_wasm = "0.7.4" wasm-bindgen-futures = "0.4.39" -wasm-glue = "0.1.0" +web-sys = "0.3.67" [dev-dependencies] lazy_static = "1.4.0" diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index 32d3d20..bcb3f5a 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -29,7 +29,9 @@ impl HeartbeatHandler { websocket_tx: Arc>, kill_rc: tokio::sync::broadcast::Receiver<()>, ) -> Self { - println!("HBH: Creating new self"); + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1("HBH: Creating new self"); + let (send, receive) = tokio::sync::mpsc::channel(32); let kill_receive = kill_rc.resubscribe(); @@ -41,7 +43,8 @@ impl HeartbeatHandler { wasm_bindgen_futures::spawn_local(async move { Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive).await; }); - println!("HBH: Spawned task"); + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1("HBH: Spawned task"); Self { heartbeat_interval, @@ -59,17 +62,25 @@ impl HeartbeatHandler { mut receive: Receiver, mut kill_receive: tokio::sync::broadcast::Receiver<()>, ) { - println!("HBH: Running task"); + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1("HBH: Running task"); let mut last_heartbeat_timestamp: Instant = time::Instant::now(); let mut last_heartbeat_acknowledged = true; let mut last_seq_number: Option = None; - println!("HBH: Initialized variables"); + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1("HBH: Initialized variables"); safina_timer::start_timer_thread(); loop { + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1("HBH: L0"); + println!("HBH: L0"); if kill_receive.try_recv().is_ok() { + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1("HBH: dying"); + println!("HBH: dying"); trace!("GW: Closing heartbeat task"); break; @@ -84,6 +95,9 @@ impl HeartbeatHandler { let mut should_send = false; + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1("HBH: L1"); + println!("HBH: L1"); tokio::select! { @@ -112,11 +126,17 @@ impl HeartbeatHandler { } } + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1("HBH: L2"); + println!("HBH: L2"); if should_send { trace!("GW: Sending Heartbeat.."); + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1("HBH: L3, sending"); + println!("HBH: L3, sending"); let heartbeat = types::GatewayHeartbeat { @@ -138,7 +158,8 @@ impl HeartbeatHandler { last_heartbeat_timestamp = time::Instant::now(); last_heartbeat_acknowledged = false; - println!("HBH: L4, sending done"); + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1("HBH: L4, sending done"); } } } diff --git a/tests/gateway.rs b/tests/gateway.rs index e36c090..5396333 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -26,10 +26,6 @@ async fn test_gateway_establish() { async fn test_gateway_authenticate() { let bundle = common::setup().await; - // Make println! work - #[cfg(target_arch = "wasm32")] - wasm_glue::hook(); - let gateway: GatewayHandle = Gateway::spawn(bundle.urls.wss.clone()).await.unwrap(); let mut identify = types::GatewayIdentifyPayload::common();