arora_websocket/lib.rs
1//! Arora WebSocket Protocol
2//!
3//! The open local bridge for Arora: a WebSocket server implementing
4//! [`arora_bridge::Bridge`] (see [`bridge::WsBridge`]), with type-safe message
5//! definitions, a method registry, and a ready-to-use server.
6//!
7//! # Features
8//!
9//! - **Message Types**: Type-safe [`Incoming`] and [`Outgoing`] message enums
10//! - **Registry**: Store slots and methods with [`Registry`]
11//! - **Server**: Full WebSocket server with [`AroraWSServer`] (requires `server` feature)
12//! - **Connection Trait**: Implements [`AroraConnection`] for protocol-agnostic usage
13//!
14//! # Protocol Overview
15//!
16//! Messages are JSON-encoded with a `type` field discriminator:
17//!
18//! ```json
19//! // Client -> Server
20//! {"type": "set_slot_values", "values": {"face/mouth": {"f64": 0.5}}}
21//! {"type": "list_slots", "path": "face"}
22//! {"type": "list_methods"}
23//! {"type": "invoke", "method": "reset", "request_id": "req-1"}
24//!
25//! // Server -> Client
26//! {"type": "set_slot_values_resp", "success": true}
27//! {"type": "list_slots_resp", "slots": [...]}
28//! {"type": "list_methods_resp", "methods": [...]}
29//! {"type": "invoke_resp", "success": true, "request_id": "req-1"}
30//! ```
31//!
32//! # Server Example
33//!
34//! ```rust,no_run
35//! use arora_websocket::{AroraWSServer, ServerConfig, MethodInfo, InvokeResult};
36//! use tokio_util::sync::CancellationToken;
37//!
38//! #[tokio::main]
39//! async fn main() {
40//! let server = AroraWSServer::with_port(9000);
41//!
42//! // Register a method
43//! server.registry().register_method_fn(
44//! MethodInfo {
45//! path: "reset".to_string(),
46//! params: vec![],
47//! return_type: None,
48//! description: Some("Reset to defaults".to_string()),
49//! },
50//! |_args| InvokeResult::ok(),
51//! ).await;
52//!
53//! // Set update handler
54//! server.set_set_slot_values_handler(|values| {
55//! println!("Received {} updates", values.len());
56//! Ok(())
57//! }).await;
58//!
59//! // Run the server
60//! let cancel = CancellationToken::new();
61//! server.run(cancel).await.unwrap();
62//! }
63//! ```
64
65/// The WS server as an Arora `Bridge`.
66pub mod bridge;
67pub mod handlers;
68mod messages;
69mod method;
70mod registry;
71mod server;
72mod slot;
73
74pub use handlers::{
75 GetSlotValuesHandler, MethodHandler, OnClientConnectedHandler, SetSlotValuesResult,
76};
77pub use messages::{Incoming, Outgoing};
78pub use method::{InvokeResult, MethodInfo, MethodParam};
79pub use registry::Registry;
80pub use server::{process_message, AroraWSServer, ServerConfig, SetSlotValuesHandler};
81pub use slot::SlotInfo;
82pub use tokio_util::sync::CancellationToken;
83
84pub use arora_types::keyvalue::{KeyValue, KeyValueField};
85pub use arora_types::value::{Type, Value};