Skip to main content

Crate wavecraft_bridge

Crate wavecraft_bridge 

Source
Expand description

IPC bridge for WebView ↔ Rust communication

This crate provides the message handling layer between the React UI (running in a WebView) and Rust application logic. It implements JSON-RPC 2.0 style request/response handling with typed message contracts.

§Architecture

  • ParameterHost trait: Abstracts parameter storage (desktop POC, plugin, etc.)
  • IpcHandler: Dispatches JSON-RPC requests to appropriate handlers
  • BridgeError: Typed error handling with conversion to IPC error codes

§Example

use wavecraft_bridge::{IpcHandler, ParameterHost, BridgeError};
use wavecraft_protocol::{AudioRuntimeStatus, MeterFrame, ParameterInfo};

// Implement ParameterHost for your application state
struct MyApp;

impl ParameterHost for MyApp {
    fn get_parameter(&self, id: &str) -> Option<ParameterInfo> {
        // Implementation
        None
    }
     
    fn set_parameter(&self, id: &str, value: f32) -> Result<(), BridgeError> {
        // Implementation
        Ok(())
    }
     
    fn get_all_parameters(&self) -> Vec<ParameterInfo> {
        // Implementation
        vec![]
    }

    fn get_meter_frame(&self) -> Option<MeterFrame> {
        // Implementation
        None
    }

    fn request_resize(&self, _width: u32, _height: u32) -> bool {
        // Implementation
        false
    }

    fn get_audio_status(&self) -> Option<AudioRuntimeStatus> {
        // Implementation
        None
    }
}

// Create handler
let handler = IpcHandler::new(MyApp);

// Handle incoming JSON from WebView
let request_json = r#"{"jsonrpc":"2.0","id":1,"method":"ping"}"#;
let response_json = handler.handle_json(request_json);

Re-exports§

pub use error::BridgeError;
pub use handler::IpcHandler;
pub use host::ParameterHost;
pub use in_memory_host::InMemoryParameterHost;
pub use in_memory_host::MeterProvider;
pub use plugin_loader::PluginLoaderError;
pub use plugin_loader::PluginParamLoader;

Modules§

error
Error types for the IPC bridge layer
handler
IPC request handler.
host
Parameter host trait - abstraction for plugin parameter management.
in_memory_host
In-memory ParameterHost implementation for dev tools and tests.
plugin_loader
Plugin parameter loader using libloading for FFI.

Structs§

GetAllParametersResult
Result of getAllParameters request
GetParameterParams
Parameters for getParameter request
GetParameterResult
Result of getParameter request
IpcError
Error returned in IpcResponse
IpcNotification
Notification message sent from Rust to UI (no response expected)
IpcRequest
Request message sent from UI to Rust
IpcResponse
Response message sent from Rust to UI
MeterUpdateNotification
Notification sent from audio binary to browser via dev server
ParameterChangedNotification
Notification sent when a parameter changes (e.g., from host automation)
ParameterInfo
Information about a single parameter
RegisterAudioParams
Parameters for registerAudio request (audio binary → dev server)
RegisterAudioResult
Result of registerAudio request
SetParameterParams
Parameters for setParameter request
SetParameterResult
Result of setParameter request (empty success)

Enums§

ParameterType
Parameter type discriminator
RequestId
Request ID can be string or number