# OpenRTC Rust Core
The `openrtc` crate is the shared realtime engine behind OpenRTC's native and
browser/WASM runtimes.
```toml
[dependencies]
openrtc = "1.0.2"
```
Rust 1.91 or newer is required. The default feature set is intentionally small;
enable only the native transports your host ships:
```toml
openrtc = { version = "1.0.2", features = ["transport-lan"] }
```
It powers:
- the native runtime used by Tauri and other native hosts
- the WASM runtime loaded by the npm package in browsers
## Core Responsibilities
- app-scoped device discovery
- presence publishing and cleanup
- signaling messages and sessions
- room membership
- peer identity resolution
- iroh endpoint lifecycle and connection management
- shared runtime records used by both native and WASM hosts
## Native vs WASM
### Native
Used for:
- Tauri desktop/mobile-style hosts
- headless or CLI-style runners
- advanced endpoint and router integration
Native-only features include:
- endpoint adoption/export
- custom router / no-internal-router mode
- native auth relay helpers
- protocol registry and plugin registration
### WASM
The same runtime logic compiles to WebAssembly for browser hosts.
The npm package loads that WASM build and forwards auth/runtime configuration into it. The browser path should behave like the native path at the runtime-contract level.
## Recommended Native Shape
- use `ClientBuilder` / injected runtime construction
- keep host-specific behavior outside the core where possible
- use the runtime manager and protocol registry for advanced native composition
## Peer Sessions and Custom Protocols
The Rust core owns one peer-session view per `deviceId`. Host layers should
consume connected peer-session snapshots rather than reason about transport
records directly.
Protocol authors have two supported extension paths:
1. **Session-adjacent stream composition**
- wait for a connected peer session
- open `open_bi` / `open_uni` streams
- define framing and message semantics externally
2. **ALPN protocol plugins**
- register protocol plugins through `RuntimeManager` / `ProtocolRegistry`
- use `SessionAdjacent` plugins for runtime-ready hooks without ALPN routing
- use `Alpn` plugins when the native runtime should register a dedicated ALPN
WASM/browser consumers should prefer the first model. The second is a
Rust-first advanced capability.
## Important Rule
Rust owns discovery, signaling, presence, lifecycle, and peer identity. TypeScript should wrap those contracts, not duplicate them.
See the [lifecycle ownership contract](https://github.com/bluestarburst/openrtc/blob/main/docs/architecture/lifecycle-ownership-contract.md)
and [application security and delivery contract](https://github.com/bluestarburst/openrtc/blob/main/docs/architecture/application-security-and-delivery-contract.md)
before adding host retry, connection, admission, or delivery behavior.