pub struct EventHandlers { /* private fields */ }Expand description
Connection lifecycle event handlers.
All handlers are optional. The builder pattern makes it easy to register
only the handlers you need. Handlers are Send + Sync so they work with
the async tokio runtime.
These handlers are invoked across all SDK platforms (Rust, TypeScript, Dart) with the same semantics.
Implementations§
Source§impl EventHandlers
impl EventHandlers
Sourcepub fn new() -> EventHandlers
pub fn new() -> EventHandlers
Create a new empty EventHandlers (no callbacks registered).
Sourcepub fn on_connect(self, f: impl Fn() + Send + Sync + 'static) -> EventHandlers
pub fn on_connect(self, f: impl Fn() + Send + Sync + 'static) -> EventHandlers
Register a callback invoked when the shared connection becomes ready.
§Example
use kalam_client::EventHandlers;
let handlers = EventHandlers::new().on_connect(|| println!("Connected!"));Sourcepub fn on_disconnect(
self,
f: impl Fn(DisconnectReason) + Send + Sync + 'static,
) -> EventHandlers
pub fn on_disconnect( self, f: impl Fn(DisconnectReason) + Send + Sync + 'static, ) -> EventHandlers
Register a callback invoked when the WebSocket connection is closed.
The callback receives a DisconnectReason with details about why
the connection was closed.
§Example
use kalam_client::EventHandlers;
let handlers =
EventHandlers::new().on_disconnect(|reason| println!("Disconnected: {}", reason));Sourcepub fn on_error(
self,
f: impl Fn(ConnectionError) + Send + Sync + 'static,
) -> EventHandlers
pub fn on_error( self, f: impl Fn(ConnectionError) + Send + Sync + 'static, ) -> EventHandlers
Register a callback invoked when a connection error occurs.
The callback receives a ConnectionError indicating whether the
error is recoverable (auto-reconnect may help) or fatal.
§Example
use kalam_client::EventHandlers;
let handlers = EventHandlers::new()
.on_error(|err| eprintln!("Error (recoverable={}): {}", err.recoverable, err));Sourcepub fn on_receive(
self,
f: impl Fn(&str) + Send + Sync + 'static,
) -> EventHandlers
pub fn on_receive( self, f: impl Fn(&str) + Send + Sync + 'static, ) -> EventHandlers
Register a callback invoked for every raw message received from the server.
This is a debug/tracing hook — it receives the raw JSON string of every inbound WebSocket message before parsing. Useful for logging or diagnostics. Not needed for normal operation.
§Example
use kalam_client::EventHandlers;
let handlers = EventHandlers::new().on_receive(|msg| println!("[RECV] {}", msg));Sourcepub fn on_send(self, f: impl Fn(&str) + Send + Sync + 'static) -> EventHandlers
pub fn on_send(self, f: impl Fn(&str) + Send + Sync + 'static) -> EventHandlers
Register a callback invoked for every raw message sent to the server.
This is a debug/tracing hook — it receives the raw JSON string of every outbound WebSocket message. Useful for logging or diagnostics.
§Example
use kalam_client::EventHandlers;
let handlers = EventHandlers::new().on_send(|msg| println!("[SEND] {}", msg));Trait Implementations§
Source§impl Clone for EventHandlers
impl Clone for EventHandlers
Source§fn clone(&self) -> EventHandlers
fn clone(&self) -> EventHandlers
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more