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::{AudioRuntimeStatus, 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//! fn get_audio_status(&self) -> Option<AudioRuntimeStatus> {
49//! // Implementation
50//! None
51//! }
52//! }
53//!
54//! // Create handler
55//! let handler = IpcHandler::new(MyApp);
56//!
57//! // Handle incoming JSON from WebView
58//! let request_json = r#"{"jsonrpc":"2.0","id":1,"method":"ping"}"#;
59//! let response_json = handler.handle_json(request_json);
60//! ```
61
62pub mod error;
63pub mod handler;
64pub mod host;
65pub mod in_memory_host;
66pub mod plugin_loader;
67
68// Re-export key types for convenience
69pub use error::BridgeError;
70pub use handler::IpcHandler;
71pub use host::ParameterHost;
72pub use in_memory_host::{InMemoryParameterHost, MeterProvider};
73pub use plugin_loader::{PluginLoaderError, PluginParamLoader};
74
75// Re-export protocol types used in bridge API
76pub use wavecraft_protocol::{
77 GetAllParametersResult, GetParameterParams, GetParameterResult, IpcError, IpcNotification,
78 IpcRequest, IpcResponse, MeterUpdateNotification, ParameterChangedNotification, ParameterInfo,
79 ParameterType, RegisterAudioParams, RegisterAudioResult, RequestId, SetParameterParams,
80 SetParameterResult,
81};