# `MobWebrtc.Engine`
[🔗](https://github.com/GenericJam/mob_webrtc/blob/main/lib/mob_webrtc/engine.ex#L1)

What a WebRTC implementation provides to `MobWebrtc.Peer`.

An engine owns one peer connection per `start_link/1` and reports to the
process that called it with messages of its own shape; `event/1` turns each
into the engine-neutral events `MobWebrtc` documents, so a screen never sees
which engine is underneath. Descriptions and ICE candidates are JSON-shaped
maps with string keys (`RTCSessionDescriptionInit`, `RTCIceCandidateInit`),
ready to send over signaling as they are.

Engines:

  * `MobWebrtc.Engine.ExWebRTC`: `ex_webrtc` over the static NIFs.
  * `MobWebrtc.Engine.Fake`: no network or native code, for host tests and
    for driving a screen without a remote peer.

# `candidate`

```elixir
@type candidate() :: %{required(String.t()) =&gt; term()}
```

# `channel_ref`

```elixir
@type channel_ref() :: reference()
```

# `data_type`

```elixir
@type data_type() :: :string | :binary
```

# `description`

```elixir
@type description() :: %{required(String.t()) =&gt; String.t()}
```

# `kind`

```elixir
@type kind() :: :audio | :video
```

# `pc`

```elixir
@type pc() :: pid()
```

# `track_id`

```elixir
@type track_id() :: term()
```

# `add_ice_candidate`

```elixir
@callback add_ice_candidate(pc(), candidate()) :: :ok | {:error, term()}
```

# `add_track`

```elixir
@callback add_track(pc(), kind()) :: {:ok, track_id()} | {:error, term()}
```

# `close`

```elixir
@callback close(pc()) :: :ok
```

# `create_answer`

```elixir
@callback create_answer(pc()) :: {:ok, description()} | {:error, term()}
```

# `create_data_channel`

```elixir
@callback create_data_channel(pc(), label :: String.t(), opts :: keyword()) ::
  {:ok, channel_ref()} | {:error, term()}
```

Opens a data channel. Options: `:ordered` (boolean, default `true`),
`:max_retransmits` or `:max_packet_life_time` (ms; neither means reliable),
`:protocol`.

# `create_offer`

```elixir
@callback create_offer(pc()) :: {:ok, description()} | {:error, term()}
```

# `event`

```elixir
@callback event(message :: term()) :: {:ok, [MobWebrtc.event()]} | :ignore
```

Turns a message the engine sent its caller into `MobWebrtc` events, or `:ignore`.

# `get_stats`

```elixir
@callback get_stats(pc()) :: map()
```

# `local_description`

```elixir
@callback local_description(pc()) :: description() | nil
```

The local description with every local candidate gathered so far in it
(`RTCPeerConnection.localDescription`), or `nil` before one is set.

# `request_keyframe`

```elixir
@callback request_keyframe(pc(), track_id()) :: :ok
```

Asks the remote sender of `track_id` (a receive track) for a keyframe (RTCP PLI).

# `send_data`

```elixir
@callback send_data(pc(), channel_ref(), binary(), data_type()) :: :ok
```

Sends one message on an open data channel.

# `send_rtp`

```elixir
@callback send_rtp(pc(), track_id(), ExRTP.Packet.t()) :: :ok
```

# `set_local_description`

```elixir
@callback set_local_description(pc(), description()) :: :ok | {:error, term()}
```

# `set_remote_description`

```elixir
@callback set_remote_description(pc(), description()) :: :ok | {:error, term()}
```

# `start_link`

```elixir
@callback start_link(opts :: keyword()) :: {:ok, pc()} | {:error, term()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
