diff --git a/Windows/Rust/CubeLib/src/lib.rs b/Windows/Rust/CubeLib/src/lib.rs index e9d6450..8656567 100644 --- a/Windows/Rust/CubeLib/src/lib.rs +++ b/Windows/Rust/CubeLib/src/lib.rs @@ -30,4 +30,4 @@ pub mod websocket; -pub use websocket::{WebSocketClient, WebSocketConfig, WebSocketMessage}; +pub use websocket::{WebSocketClient, WebSocketConfig, WebSocketMessage, OutgoingMessage, ConnectionStatus}; diff --git a/Windows/Rust/CubeLib/src/websocket/client.rs b/Windows/Rust/CubeLib/src/websocket/client.rs index ad8e825..6a9d1fe 100644 --- a/Windows/Rust/CubeLib/src/websocket/client.rs +++ b/Windows/Rust/CubeLib/src/websocket/client.rs @@ -2,6 +2,7 @@ use crate::websocket::{WebSocketConfig, WebSocketMessage, WebSocketError}; use futures_util::{SinkExt, StreamExt}; +use std::pin::Pin; use std::sync::Arc; use tokio::sync::{mpsc, Mutex}; use tokio::time::Duration; @@ -60,7 +61,8 @@ pub type SentCallback = Arc; pub type ReconnectingCallback = Arc>) + Send + Sync>; /// Callback triggered on first successful connection (before any reconnect) /// Arguments: (url, send_fn) - send_fn can be called to send messages -pub type FirstConnectCallback = Arc>>>) + Send + Sync>; +/// Note: This is an async callback - return a boxed Future +pub type FirstConnectCallback = Arc>>>) -> Pin + Send + Sync + 'static>> + Send + Sync>; /// WebSocket client with event-driven architecture pub struct WebSocketClient { @@ -198,10 +200,10 @@ impl WebSocketClient { } /// Set callback for first successful connection (before any reconnect) - /// This is called only on the first connection, allowing the app to send initial messages + /// This is an async callback - the returned Future will be awaited pub fn on_first_connect(&mut self, callback: F) -> &mut Self where - F: Fn(String, Arc>>>) + Send + Sync + 'static, + F: Fn(String, Arc>>>) -> Pin + Send + Sync + 'static>> + Send + Sync + 'static, { self.on_first_connect = Some(Arc::new(callback)); self @@ -468,7 +470,7 @@ impl WebSocketClient { // Call on_first_connect callback (only on first connection, not on reconnect) if is_first { if let Some(ref callback) = on_first_connect { - callback(url.to_string(), sender); + callback(url.to_string(), sender).await; } }