Skip to main content

infinity_bridge_wasm/
lib.rs

1//!
2//! ```rust,ignore
3//! use infinity_bridge_wasm::{Bridge, BridgeConfig, CommBusBackend};
4//! use serde_json::{json, Value};
5//!
6//! // Implement CommBusBackend for your MSFS SDK bindings
7//! struct MyCommBus;
8//! impl CommBusBackend for MyCommBus {
9//!     type Error = String;
10//!     type Subscription = MySubscription;
11//!
12//!     fn subscribe(
13//!         event: &str,
14//!         callback: impl Fn(&str) + 'static,
15//!     ) -> Result<Self::Subscription, Self::Error> {
16//!         // ... wire to msfs::comm_bus
17//!     }
18//!
19//!     fn call(event: &str, data: &str) -> Result<(), Self::Error> {
20//!         // ... wire to msfs::comm_bus::call
21//!     }
22//! }
23//!
24//! let bridge = Bridge::<MyCommBus>::new(
25//!     BridgeConfig::new("myaddon/bridge_call", "myaddon/bridge_resp"),
26//!     |name, payload| {
27//!         match name {
28//!             Some("get_state") => Ok(json!({"temp": 42})),
29//!             _ => Err("unknown command".into()),
30//!         }
31//!     },
32//! )?;
33//!
34//! // Fire-and-forget event to host
35//! bridge.emit("state_changed", json!({"phase": "cruise"}))?;
36//! ```
37
38mod backend;
39mod bridge;
40
41pub use backend::CommBusBackend;
42pub use bridge::{Bridge, BridgeConfig, BridgeHandler, Router};
43pub use infinity_bridge_wire::{BridgeError, ErrorKind};