Skip to main content

clasp_transport/
lib.rs

1//! CLASP Transport Layer
2//!
3//! This crate provides transport implementations for CLASP.
4//! The protocol is transport-agnostic - any byte transport works.
5//!
6//! Available transports:
7//! - WebSocket (recommended baseline for interoperability)
8//!   - Native: tokio-tungstenite (client + server)
9//!   - WASM: web-sys (client only)
10//! - UDP (LAN, low-latency, broadcast) - native only
11//! - QUIC (modern native apps, connection migration) - native only
12//! - Serial (direct hardware, lowest latency) - native only
13//! - BLE (Bluetooth Low Energy, wireless controllers) - native only
14//! - WebRTC (P2P, NAT traversal, low-latency)
15
16pub mod error;
17pub mod traits;
18
19// Native WebSocket (uses tokio-tungstenite)
20#[cfg(all(feature = "websocket", not(target_arch = "wasm32")))]
21pub mod websocket;
22
23// WASM WebSocket (uses web-sys)
24#[cfg(all(feature = "wasm-websocket", target_arch = "wasm32"))]
25pub mod wasm_websocket;
26
27// Native-only transports
28#[cfg(all(feature = "tcp", not(target_arch = "wasm32")))]
29pub mod tcp;
30
31#[cfg(all(feature = "udp", not(target_arch = "wasm32")))]
32pub mod udp;
33
34#[cfg(all(feature = "quic", not(target_arch = "wasm32")))]
35pub mod quic;
36
37#[cfg(all(feature = "serial", not(target_arch = "wasm32")))]
38pub mod serial;
39
40#[cfg(all(feature = "ble", not(target_arch = "wasm32")))]
41pub mod ble;
42
43#[cfg(feature = "webrtc")]
44pub mod webrtc;
45
46pub use error::{Result, TransportError};
47pub use traits::{Transport, TransportEvent, TransportReceiver, TransportSender, TransportServer};
48
49// Native WebSocket exports
50#[cfg(all(feature = "websocket", not(target_arch = "wasm32")))]
51pub use websocket::{WebSocketConfig, WebSocketServer, WebSocketTransport};
52
53// WASM WebSocket exports
54#[cfg(all(feature = "wasm-websocket", target_arch = "wasm32"))]
55pub use wasm_websocket::{WasmWebSocketConfig, WasmWebSocketTransport};
56
57#[cfg(all(feature = "tcp", not(target_arch = "wasm32")))]
58pub use tcp::{TcpConfig, TcpServer, TcpTransport};
59
60#[cfg(all(feature = "udp", not(target_arch = "wasm32")))]
61pub use udp::{UdpConfig, UdpTransport};
62
63#[cfg(all(feature = "ble", not(target_arch = "wasm32")))]
64pub use ble::{BleConfig, BleTransport};
65
66#[cfg(feature = "webrtc")]
67pub use webrtc::{WebRtcConfig, WebRtcTransport};
68
69#[cfg(all(feature = "quic", not(target_arch = "wasm32")))]
70pub use quic::{QuicConfig, QuicConnection, QuicTransport};
71
72#[cfg(all(feature = "serial", not(target_arch = "wasm32")))]
73pub use serial::{SerialConfig, SerialTransport};