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

A `MobWebrtc.Engine` with no network and no native code, for host tests and
for driving a screen when there's no remote peer.

It follows the offer/answer state machine closely enough to catch misuse:
`create_answer/1` needs a remote offer, and a peer reports
`{:connection_state, :connected}` once it has both a local and a remote
description. Descriptions are recognisably fake (`"sdp" => "v=0 fake …"`).
`send_rtp/3` sends nothing; `MobWebrtc.get_stats/1` reports how many packets
each track sent (`:rtp_sent`) and the last 100 of them (`:recent_rtp`).

A data channel opens (`{:data_channel_state, ref, :open}`) once the peer is
connected. `send_data/4` sends nothing either; `:data_sent` in the stats
holds each channel's messages as `{type, binary}`, oldest first.

The first local description starts ICE gathering, which completes at once
(`{:ice_gathering_state, :gathering}`, then `:complete`), and
`local_description/1` then carries one fake host candidate.

To play the remote side, inject events into a peer with `emit/2`; they reach
the owner exactly as the real engine's would:

    MobWebrtc.Engine.Fake.emit(peer, {:keyframe_request, track_id})

A channel the remote side opened, then a message on it:

    ref = make_ref()
    MobWebrtc.Engine.Fake.emit(peer, {:data_channel, %{ref: ref, label: "chat"}})
    MobWebrtc.Engine.Fake.emit(peer, {:data_channel_state, ref, :open})
    MobWebrtc.Engine.Fake.emit(peer, {:data, ref, ~s({"text":"hi"})})

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `emit`

```elixir
@spec emit(MobWebrtc.peer(), MobWebrtc.event()) :: :ok
```

Delivers `event` to `peer`'s owner as if it came from the network.

---

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