Skip to main content

socketio_next/
lib.rs

1//! A [Socket.IO](https://socket.io) v4 client for Rust, with the behaviour of the reference
2//! JavaScript client (socket.io-client 4.8 / engine.io-client 6.6): namespaces, auth, acks in
3//! both directions, binary data anywhere in the arguments, reconnection with the same backoff,
4//! connection state recovery, and polling / websocket transports over rustls or native-tls.
5//!
6//! ```no_run
7//! use std::time::Duration;
8//! use socketio_next::{Client, ClientBuilder, ConnectionState, Event};
9//! use serde_json::json;
10//!
11//! #[tokio::main]
12//! async fn main() -> socketio_next::Result<()> {
13//!     let client = ClientBuilder::new("http://localhost:3000")
14//!         .auth(json!({ "token": "abc" }))
15//!         .on("greeting", |event: Event, _client: Client| async move {
16//!             println!("server says {:?}", event.payload());
17//!         })
18//!         .on_state_change(|state: ConnectionState, _client: Client| async move {
19//!             println!("state: {state:?}");
20//!         })
21//!         .connect()
22//!         .await?;
23//!
24//!     client.emit("hello", json!({ "from": "rust" }))?;
25//!     let reply = client
26//!         .emit_with_ack("add", vec![json!(1), json!(2)], Duration::from_secs(5))
27//!         .await?;
28//!     println!("1 + 2 = {}", reply.arg::<i64>(0)?);
29//!
30//!     client.disconnect().await
31//! }
32//! ```
33//!
34//! - [`ClientBuilder`] configures and connects; [`Client`] emits, acks, adds handlers at
35//!   runtime and reports [`ConnectionState`] / [`LinkInfo`].
36//! - [`blocking`] (feature `blocking`) is the same client without async.
37//! - [`engineio`] is the transport layer, [`protocol`] the packet codecs (no I/O).
38#![cfg_attr(docsrs, feature(doc_cfg))]
39
40mod actor;
41mod backoff;
42#[cfg(feature = "blocking")]
43#[cfg_attr(docsrs, doc(cfg(feature = "blocking")))]
44pub mod blocking;
45mod builder;
46mod client;
47pub mod engineio;
48mod error;
49mod event;
50mod handler;
51pub mod protocol;
52mod redact;
53mod state;
54mod transport_type;
55
56pub use builder::{ClientBuilder, ConnectParams, Direction};
57pub use client::Client;
58pub use engineio::{TlsConfig, TransportKind};
59pub use error::{Error, Result};
60pub use event::{AckSender, Event};
61pub use handler::{Handler, ListenerId};
62pub use protocol::Payload;
63pub use state::{ConnectionState, DisconnectReason, LinkInfo};
64pub use transport_type::TransportType;