# Public API

## Types

- `CallSession` – orchestrates state transitions for a single call. Construct with `CallSession::new(config)` or `CallSession::with_engine(config, engine)`.
- `RtcConfig` – describes ICE servers, codec preference, and media toggles.
- `SignalingMessage` – enum covering `Offer`, `Answer`, `IceCandidate`, and `Hangup` payloads.
- `RtcEvent` – emitted over the async queue (`LocalIceCandidate`, `StateChanged`, `ConnectionEstablished`, `ConnectionClosed`).
- `CallState` – discrete states used by the state machine.
- `EnigmaRtcError` – errors: `InvalidState`, `InvalidSdp`, `InvalidCandidate`, `WebRtcError`, `JsonError`, `ChannelClosed`.

## CallSession methods

- `create_offer() -> Result<SignalingMessage>` – transitions `Idle` → `CreatingOffer` → `WaitingAnswer` and returns the offer payload.
- `accept_offer(&str) -> Result<SignalingMessage>` – transitions `Idle` → `IncomingOffer` → `Connected` and returns an answer payload.
- `accept_answer(&str) -> Result<()>` – available only from `WaitingAnswer`, transitions to `Connected`.
- `add_ice_candidate(&str) -> Result<()>` – validates a candidate JSON string and forwards it to the engine when state allows it.
- `hangup(Option<&str>) -> Result<SignalingMessage>` – transitions through `Ending` to `Ended`, emitting a hangup payload plus `ConnectionClosed` event.
- `set_microphone_enabled(bool)` and `set_camera_enabled(bool)` – delegate to the engine while rejecting calls after `Ended`.
- `next_event() -> impl Future<Output = Result<RtcEvent>>` – awaits the next local event from the session queue.
- `state() -> CallState` and `config() -> &RtcConfig` – read-only helpers for diagnostics.

## Helpers

- `encode_signaling(&SignalingMessage) -> String`
- `decode_signaling(&str) -> Result<SignalingMessage>`

## Engine layer

- `RtcEngine` trait – allows alternate WebRTC backends.
- `WebRtcEngine` – default implementation backed by `webrtc-rs`.
- `MockWebRtcEngine` – deterministic engine for unit tests.
