Skip to main content

BridgePlugin

Trait BridgePlugin 

Source
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§

Source

fn name(&self) -> &str

Plugin identifier name

Provided Methods§

Source

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

Source

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

Source

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

Implementors§