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, OscilloscopeFrame, 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 get_oscilloscope_frame(&self) -> Option<OscilloscopeFrame> {
44//! // Implementation
45//! None
46//! }
47//!
48//! fn request_resize(&self, _width: u32, _height: u32) -> bool {
49//! // Implementation
50//! false
51//! }
52//!
53//! fn get_audio_status(&self) -> Option<AudioRuntimeStatus> {
54//! // Implementation
55//! None
56//! }
57//! }
58//!
59//! // Create handler
60//! let handler = IpcHandler::new(MyApp);
61//!
62//! // Handle incoming JSON from WebView
63//! let request_json = r#"{"jsonrpc":"2.0","id":1,"method":"ping"}"#;
64//! let response_json = handler.handle_json(request_json);
65//! ```
66
67pub mod error;
68pub mod handler;
69pub mod host;
70pub mod in_memory_host;
71pub mod plugin_loader;
72
73// Core bridge entrypoints and host abstraction.
74pub use error::BridgeError;
75pub use handler::IpcHandler;
76pub use host::ParameterHost;
77
78// Test/dev host implementations and plugin loader support.
79pub use in_memory_host::{InMemoryParameterHost, MeterProvider, OscilloscopeProvider};
80pub use plugin_loader::{PluginLoaderError, PluginParamLoader};
81
82// Protocol contracts surfaced by the bridge API.
83pub use wavecraft_protocol::{
84 GetAllParametersResult, GetParameterParams, GetParameterResult, IpcError, IpcNotification,
85 IpcRequest, IpcResponse, MeterUpdateNotification, ParameterChangedNotification, ParameterInfo,
86 ParameterType, ProcessorInfo, RegisterAudioParams, RegisterAudioResult, RequestId,
87 SetParameterParams, SetParameterResult,
88};