Skip to main content

arora_websocket/
handlers.rs

1//! Callback types the server dispatches incoming protocol messages to.
2
3use crate::method::InvokeResult;
4use arora_types::value::Value;
5use std::collections::HashMap;
6use std::future::Future;
7use std::pin::Pin;
8use std::sync::Arc;
9
10/// Result type for set slot values handler.
11pub type SetSlotValuesResult = Result<(), String>;
12
13/// Handler function type for SetSlotValues messages.
14/// Called when an external client wants to update slot values.
15pub type SetSlotValuesHandler =
16    Arc<dyn Fn(HashMap<String, Value>) -> SetSlotValuesResult + Send + Sync>;
17
18/// Handler function type for GetSlotValues messages.
19/// Called when an external client wants to read current slot values.
20/// Returns a map of slot paths to their current values.
21pub type GetSlotValuesHandler = Arc<
22    dyn Fn(Vec<String>) -> Pin<Box<dyn Future<Output = HashMap<String, Value>> + Send>>
23        + Send
24        + Sync,
25>;
26
27/// Handler function type for method invocations.
28pub type MethodHandler = Arc<dyn Fn(HashMap<String, Value>) -> InvokeResult + Send + Sync>;
29
30/// Handler called when a new client connects to this connection.
31/// Receives the connection identifier (e.g., "ws://127.0.0.1:9000").
32pub type OnClientConnectedHandler = Arc<dyn Fn(String) + Send + Sync>;