pub trait BridgePlugin: Send + Sync {
// Required method
fn name(&self) -> &str;
// Provided methods
fn inject_js(&self) -> Option<String> { ... }
fn on_request(&self, _req: &mut IpcRequest) -> Result<(), IpcError> { ... }
fn on_response(&self, _res: &mut IpcResponse) -> Result<(), IpcError> { ... }
}Expand description
Trait for implementing bridge plugins
Plugins can extend the bridge with custom functionality such as:
- Logging and monitoring
- Authentication and authorization
- Request/response transformation
- Custom JavaScript injection
§Example
ⓘ
use dioxus_ipc_bridge::plugin::BridgePlugin;
struct LoggingPlugin;
impl BridgePlugin for LoggingPlugin {
fn name(&self) -> &str {
"logging"
}
fn inject_js(&self) -> Option<String> {
Some("console.log('[Plugin] Logging enabled');".to_string())
}
fn on_request(&self, req: &mut IpcRequest) -> Result<(), IpcError> {
println!("Request: {} {}", req.method, req.url);
Ok(())
}
}Required Methods§
Provided Methods§
Sourcefn inject_js(&self) -> Option<String>
fn inject_js(&self) -> Option<String>
Optional JavaScript code to inject during bridge initialization
This code will be executed after the core bridge is set up
Sourcefn on_request(&self, _req: &mut IpcRequest) -> Result<(), IpcError>
fn on_request(&self, _req: &mut IpcRequest) -> Result<(), IpcError>
Called before a request is processed
Plugins can modify the request or return an error to reject it
Sourcefn on_response(&self, _res: &mut IpcResponse) -> Result<(), IpcError>
fn on_response(&self, _res: &mut IpcResponse) -> Result<(), IpcError>
Called after a response is generated
Plugins can modify the response before it’s sent to JavaScript