Skip to main content

Crate arora_websocket

Crate arora_websocket 

Source
Expand description

Arora WebSocket Protocol

The open local bridge for Arora: a WebSocket server implementing arora_bridge::Bridge (see bridge::WsBridge), with type-safe message definitions, a method registry, and a ready-to-use server.

§Features

  • Message Types: Type-safe Incoming and Outgoing message enums
  • Registry: Store slots and methods with Registry
  • Server: Full WebSocket server with AroraWSServer (requires server feature)
  • Connection Trait: Implements [AroraConnection] for protocol-agnostic usage

§Protocol Overview

Messages are JSON-encoded with a type field discriminator:

// Client -> Server
{"type": "set_slot_values", "values": {"face/mouth": {"f64": 0.5}}}
{"type": "list_slots", "path": "face"}
{"type": "list_methods"}
{"type": "invoke", "method": "reset", "request_id": "req-1"}

// Server -> Client
{"type": "set_slot_values_resp", "success": true}
{"type": "list_slots_resp", "slots": [...]}
{"type": "list_methods_resp", "methods": [...]}
{"type": "invoke_resp", "success": true, "request_id": "req-1"}

§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;

    // Set update handler
    server.set_set_slot_values_handler(|values| {
        println!("Received {} updates", values.len());
        Ok(())
    }).await;

    // Run the server
    let cancel = CancellationToken::new();
    server.run(cancel).await.unwrap();
}

Re-exports§

pub use handlers::GetSlotValuesHandler;
pub use handlers::MethodHandler;
pub use handlers::OnClientConnectedHandler;
pub use handlers::SetSlotValuesResult;

Modules§

bridge
The WS server as an Arora Bridge. [WsBridge]: the Vizij WebSocket server driven as an Arora Bridge (Phase 5C).
handlers
Callback types the server dispatches incoming protocol messages to.

Structs§

AroraWSServer
WebSocket server for the arora protocol.
CancellationToken
A token which can be used to signal a cancellation request to one or more tasks.
InvokeResult
Result type for method invocation.
KeyValue
A collection of named KeyValueFields identified by a UUID.
KeyValueField
MethodInfo
Metadata describing an available RPC method.
MethodParam
Descriptor for an RPC method parameter.
Registry
Registry for slots and methods.
ServerConfig
Configuration for the WebSocket server.
SlotInfo
Metadata describing an available slot in the system.

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.

Type Aliases§

SetSlotValuesHandler
Callback for handling SetSlotValues messages.