Skip to main content

mqtt_client_wasm/
lib.rs

1//! MQTT Client for WASM
2//!
3//! This library provides a WebSocket-based MQTT client that works in WASM environments.
4//! It offers a low-level endpoint API similar to mqtt-endpoint-tokio, providing
5//! basic operations like send, recv, and close without high-level publish/subscribe abstractions.
6
7mod client;
8mod error;
9pub mod platform;
10mod types;
11mod websocket;
12
13#[cfg(target_arch = "wasm32")]
14mod js_transport;
15#[cfg(target_arch = "wasm32")]
16mod wasm_interface;
17
18pub use client::MqttClient;
19pub use error::{Error, Result};
20pub use types::*;
21pub use websocket::{UnderlyingLayerCommand, UnderlyingLayerEvent, UnderlyingLayerInterface};
22
23// WASM-specific exports - export the clean client implementation
24#[cfg(target_arch = "wasm32")]
25pub mod wasm {
26    pub use crate::js_transport::{create_client_with_js_transport, JsTransport};
27    pub use crate::wasm_interface::{
28        WasmMqttClient, WasmMqttConfig, WasmMqttPacket, WasmPacketType,
29    };
30    pub use crate::{MqttClient, MqttConfig};
31}
32
33// Re-export organized MQTT types
34pub mod mqtt;
35
36#[cfg(target_arch = "wasm32")]
37use wasm_bindgen::prelude::*;
38
39#[cfg(target_arch = "wasm32")]
40#[wasm_bindgen(start)]
41pub fn init() {
42    console_error_panic_hook::set_once();
43}