ankurah_websocket_client/
lib.rs

1//! # Ankurah WebSocket Client
2//!
3//! A native (non-browser) WebSocket client for connecting an Ankurah node to another
4//! Ankurah node which hosts a WebSocket server
5//!
6//! ## Automatic reconnection
7//!
8//!  Reconnects to the server if the connection is lost using exponential backoff
9//!
10//! ## Graceful shutdown
11//!
12//!   To shutdown the client, call the `shutdown` method. This will wait for the connection to be closed and then return.
13//!
14//! ## Basic Usage
15//!
16//! ```rust,no_run
17//! # use ankurah::{Node, PermissiveAgent};
18//! # use ankurah_storage_sled::SledStorageEngine;
19//! # use ankurah_websocket_client::WebsocketClient;
20//! # use ankurah::policy::DEFAULT_CONTEXT as c;
21//! # use std::sync::Arc;
22//!
23//! #[tokio::main]
24//! async fn main() -> anyhow::Result<()> {
25//!     // Create a client node
26//!     let storage = Arc::new(SledStorageEngine::new_test()?);
27//!     let my_node = Node::new(storage, PermissiveAgent::new());
28//!
29//!     // Create WebSocket client to connect to remote server (automatically starts connecting)
30//!     let client = WebsocketClient::new(my_node.clone(), "ws://localhost:8080").await?;
31//!
32//!     println!("State: {}", client.state().value()); // State: Connected
33//!
34//!     // See [ankurah] for usage details
35//!
36//!     // When you're done, shutdown the client
37//!     client.shutdown().await?;
38//!     Ok(())
39//! }
40//! ```
41//!
42//! // See ankurah for basic details
43
44pub mod client;
45pub mod sender;
46
47// Re-export the main types for easy use
48pub use client::{ConnectionState, WebsocketClient};
49pub use sender::WebsocketPeerSender;
50
51// Re-export common types for convenience
52pub use tokio_tungstenite::tungstenite::Error as TungsteniteError;