Expand description
The open local bridge for Arora: a WebSocket server that bridges the Arora
API, implementing arora_bridge::Bridge (see bridge::WsBridge), with
type-safe message definitions, a method registry, and a ready-to-use server.
Messages speak the Arora data-layer vocabulary: the store is a shared,
path-keyed blackboard, so clients write and read Values at
keys (hierarchical paths, e.g. face/mouth), list the available keys,
and invoke registered RPC methods. The server binds the loopback interface
by default: the link is unauthenticated and meant for editors and apps on
trusted local links.
§Features
- Message Types: Type-safe
IncomingandOutgoingmessage enums - Registry: Advertise keys and methods with
Registry - Server: Full WebSocket server with
AroraWSServer - Bridge:
bridge::WsBridgedrives the server as an AroraBridge
§Wire Format
Messages are JSON-encoded with a type field discriminator:
// Client -> Server
{"type": "write_values", "values": {"face/mouth": {"f64": 0.5}}}
{"type": "read_values", "keys": ["face/mouth"]}
{"type": "list_keys", "path": "face"}
{"type": "list_methods"}
{"type": "invoke", "method": "reset", "request_id": "req-1"}
// Server -> Client
{"type": "write_values_resp", "success": true}
{"type": "read_values_resp", "values": {"face/mouth": {"f64": 0.5}}}
{"type": "list_keys_resp", "keys": [...]}
{"type": "list_methods_resp", "methods": [...]}
{"type": "invoke_resp", "success": true, "request_id": "req-1"}
// Server -> Client, unsolicited: the live state feed
{"type": "values_changed", "values": {"face/mouth": {"f64": 0.5}}}§Server Example
use arora_websocket::{AroraWSServer, ServerConfig, MethodInfo, InvokeResult};
use tokio_util::sync::CancellationToken;
#[tokio::main]
async fn main() {
let server = AroraWSServer::with_port(9000);
// Register a method
server.registry().register_method_fn(
MethodInfo {
path: "reset".to_string(),
params: vec![],
return_type: None,
description: Some("Reset to defaults".to_string()),
},
|_args| InvokeResult::ok(),
).await;
// Handle writes from clients
server.set_write_values_handler(|values| {
println!("Received {} writes", values.len());
Ok(())
}).await;
// Run the server
let cancel = CancellationToken::new();
server.run(cancel).await.unwrap();
}Re-exports§
pub use handlers::MethodHandler;pub use handlers::OnClientConnectedHandler;pub use handlers::ReadValuesHandler;pub use handlers::WriteValuesHandler;pub use handlers::WriteValuesResult;
Modules§
- bridge
- The WS server as an Arora
Bridge. [WsBridge]: the WebSocket server driven as an AroraBridge. - handlers
- Callback types the server dispatches incoming messages to.
Structs§
- AroraWS
Server - WebSocket server bridging the Arora API.
- Cancellation
Token - A token which can be used to signal a cancellation request to one or more tasks.
- Invoke
Result - Result type for method invocation.
- KeyInfo
- Metadata describing a key exposed by the runtime’s data layer.
- KeyValue
- A collection of named
KeyValueFields identified by a UUID. - KeyValue
Field - Method
Info - Metadata describing an available RPC method.
- Method
Param - Descriptor for an RPC method parameter.
- Registry
- Registry for keys and methods.
- Server
Config - Configuration for the WebSocket server.
Enums§
- Incoming
- Messages received from WebSocket clients.
- Outgoing
- Messages sent to WebSocket clients.
- Type
- Value
Functions§
- process_
message - Process an incoming message and return the response.