diff --git a/bindings/prose-sdk-js/src/connector/strophe_js.rs b/bindings/prose-sdk-js/src/connector/strophe_js.rs index 10208848..69868de5 100644 --- a/bindings/prose-sdk-js/src/connector/strophe_js.rs +++ b/bindings/prose-sdk-js/src/connector/strophe_js.rs @@ -12,6 +12,7 @@ use jid::FullJid; use minidom::Element; use secrecy::{ExposeSecret, Secret}; use thiserror::Error; +use tracing::warn; use wasm_bindgen::prelude::*; use wasm_bindgen_futures::spawn_local; use web_sys::DomException; @@ -158,6 +159,7 @@ impl ConnectionTrait for Connection { impl EventHandler { #[wasm_bindgen(js_name = "handleDisconnect")] pub fn handle_disconnect(&self, error: Option) { + warn!(">>> JS CALLED HANDLE DISCONNECT"); let fut = (self.handler)( &self.connection, ConnectionEvent::Disconnected { diff --git a/crates/prose-core-client/src/app/event_handlers/connection_event_handler.rs b/crates/prose-core-client/src/app/event_handlers/connection_event_handler.rs index eb581620..b470d829 100644 --- a/crates/prose-core-client/src/app/event_handlers/connection_event_handler.rs +++ b/crates/prose-core-client/src/app/event_handlers/connection_event_handler.rs @@ -5,6 +5,7 @@ use anyhow::Result; use async_trait::async_trait; +use tracing::warn; use prose_proc_macros::InjectDependencies; @@ -47,8 +48,10 @@ impl ConnectionEventHandler { // can be sure that we have everything we need. } ConnectionEvent::Disconnected { error } => { + warn!(">>> 1 EVENT HANDLER RECEIVED DISCONNECTED EVENT"); self.ctx.set_connection_state(ConnectionState::Disconnected); self.sidebar_domain_service.handle_disconnect().await?; + warn!(">>> 2 EVENT HANDLER RECEIVED DISCONNECTED EVENT"); self.client_event_dispatcher .dispatch_event(ClientEvent::ConnectionStatusChanged { event: ClientConnectionEvent::Disconnect { error }, diff --git a/crates/prose-core-client/src/infra/events/coalescing_client_event_dispatcher.rs b/crates/prose-core-client/src/infra/events/coalescing_client_event_dispatcher.rs index 41e8fb69..7c2a8451 100644 --- a/crates/prose-core-client/src/infra/events/coalescing_client_event_dispatcher.rs +++ b/crates/prose-core-client/src/infra/events/coalescing_client_event_dispatcher.rs @@ -8,7 +8,7 @@ use std::time::Duration; use futures::StreamExt; use tokio::sync::mpsc::{channel, Sender}; -use tracing::debug; +use tracing::{debug, warn}; use prose_wasm_utils::{spawn, ProseStreamExt, ReceiverStream}; @@ -88,19 +88,22 @@ impl ClientEventDispatcherTrait for CoalescingClientEventDispatcher { event: ConnectionEvent::Disconnect { .. }, } = event { + warn!(">>> 1 COALESCINGEVENTDISPATCHER RECEIVED DISCONNECTED EVENT"); let Some(delegate) = &self.delegate else { + warn!(">>> 2 COALESCINGEVENTDISPATCHER RECEIVED DISCONNECTED EVENT"); return; }; - + warn!(">>> 3 COALESCINGEVENTDISPATCHER RECEIVED DISCONNECTED EVENT"); let Some(client_inner) = self .client_inner .get() .expect("ClientInner was not set on ClientEventDispatcher") .upgrade() else { + warn!(">>> 4 COALESCINGEVENTDISPATCHER RECEIVED DISCONNECTED EVENT"); return; }; - + warn!(">>> 5 COALESCINGEVENTDISPATCHER RECEIVED DISCONNECTED EVENT"); let client = Client::from(client_inner); return delegate.handle_event(client, event); }; diff --git a/crates/prose-xmpp/src/client/client.rs b/crates/prose-xmpp/src/client/client.rs index 08257604..82978648 100644 --- a/crates/prose-xmpp/src/client/client.rs +++ b/crates/prose-xmpp/src/client/client.rs @@ -115,6 +115,7 @@ impl ClientInner { } fn disconnect(&self) { + warn!(">>> DISCONNECT CALLED"); Self::cancel_pending_futures(&self.context); self.context.disconnect() } @@ -129,7 +130,9 @@ impl ClientInner { async fn handle_event(self: Arc, event: ConnectionEvent) { match event { ConnectionEvent::Disconnected { error } => { + warn!(">>> 1 XMPP CLIENT RECEIVED DISCONNECTED EVENT"); Self::cancel_pending_futures(&self.context); + warn!(">>> 2 XMPP CLIENT RECEIVED DISCONNECTED EVENT"); self.context .clone() .schedule_event(ClientEvent::Client(Event::Disconnected { error })) diff --git a/crates/prose-xmpp/src/client/module_context.rs b/crates/prose-xmpp/src/client/module_context.rs index f924f55f..1df0230f 100644 --- a/crates/prose-xmpp/src/client/module_context.rs +++ b/crates/prose-xmpp/src/client/module_context.rs @@ -11,7 +11,7 @@ use anyhow::Result; use jid::{BareJid, DomainPart, FullJid, NodePart, ResourcePart}; use minidom::Element; use parking_lot::{Mutex, RwLock}; -use tracing::instrument; +use tracing::{instrument, warn}; use uuid::Uuid; use xmpp_parsers::iq::{Iq, IqType}; use xmpp_parsers::pubsub; @@ -169,7 +169,27 @@ impl ModuleContextInner { #[cfg(any(not(feature = "test"), target_arch = "wasm32"))] pub(crate) fn schedule_event(self: Arc, event: Event) { - let fut = (self.event_handler)(self.clone().try_into().unwrap(), event); + let is_disconnect_event = + if let Event::Client(crate::client::Event::Disconnected { .. }) = &event { + true + } else { + false + }; + + if is_disconnect_event { + warn!(">>> 1 SCHEDULE DISCONNECTED EVENT"); + } + + let self_clone = self.clone(); + let fut = Box::pin(async move { + if is_disconnect_event { + warn!(">>> 2 SCHEDULE DISCONNECTED EVENT"); + } + (self.event_handler)(self_clone.try_into().unwrap(), event).await; + if is_disconnect_event { + warn!(">>> 3 SCHEDULE DISCONNECTED EVENT"); + } + }); prose_wasm_utils::spawn(fut); }