Skip to main content

wavecraft_bridge/
lib.rs

1//! IPC bridge for WebView ↔ Rust communication
2//!
3//! This crate provides the message handling layer between the React UI
4//! (running in a WebView) and Rust application logic. It implements
5//! JSON-RPC 2.0 style request/response handling with typed message contracts.
6//!
7//! # Architecture
8//!
9//! - **ParameterHost** trait: Abstracts parameter storage (desktop POC, plugin, etc.)
10//! - **IpcHandler**: Dispatches JSON-RPC requests to appropriate handlers
11//! - **BridgeError**: Typed error handling with conversion to IPC error codes
12//!
13//! # Example
14//!
15//! ```rust,no_run
16//! use wavecraft_bridge::{IpcHandler, ParameterHost, BridgeError};
17//! use wavecraft_protocol::{MeterFrame, ParameterInfo};
18//!
19//! // Implement ParameterHost for your application state
20//! struct MyApp;
21//!
22//! impl ParameterHost for MyApp {
23//!     fn get_parameter(&self, id: &str) -> Option<ParameterInfo> {
24//!         // Implementation
25//!         None
26//!     }
27//!     
28//!     fn set_parameter(&self, id: &str, value: f32) -> Result<(), BridgeError> {
29//!         // Implementation
30//!         Ok(())
31//!     }
32//!     
33//!     fn get_all_parameters(&self) -> Vec<ParameterInfo> {
34//!         // Implementation
35//!         vec![]
36//!     }
37//!
38//!     fn get_meter_frame(&self) -> Option<MeterFrame> {
39//!         // Implementation
40//!         None
41//!     }
42//!
43//!     fn request_resize(&self, _width: u32, _height: u32) -> bool {
44//!         // Implementation
45//!         false
46//!     }
47//! }
48//!
49//! // Create handler
50//! let handler = IpcHandler::new(MyApp);
51//!
52//! // Handle incoming JSON from WebView
53//! let request_json = r#"{"jsonrpc":"2.0","id":1,"method":"ping"}"#;
54//! let response_json = handler.handle_json(request_json);
55//! ```
56
57pub mod error;
58pub mod handler;
59pub mod host;
60pub mod in_memory_host;
61pub mod plugin_loader;
62
63// Re-export key types for convenience
64pub use error::BridgeError;
65pub use handler::IpcHandler;
66pub use host::ParameterHost;
67pub use in_memory_host::{InMemoryParameterHost, MeterProvider};
68pub use plugin_loader::{PluginLoaderError, PluginParamLoader};
69
70// Re-export protocol types used in bridge API
71pub use wavecraft_protocol::{
72    GetAllParametersResult, GetParameterParams, GetParameterResult, IpcError, IpcNotification,
73    IpcRequest, IpcResponse, MeterUpdateNotification, ParameterChangedNotification, ParameterInfo,
74    ParameterType, RegisterAudioParams, RegisterAudioResult, RequestId, SetParameterParams,
75    SetParameterResult,
76};