# `BB.LiveView.SyntheticCamera`
[🔗](https://github.com/beam-bots/bb_liveview/blob/main/test/support/synthetic_camera.ex#L5)

A camera implementation with no camera and no WebRTC, for testing the
dashboard's side of the `BB.LiveView.Camera` seam.

    config :bb_liveview, :camera, BB.LiveView.SyntheticCamera

Cameras are whatever it was started with. Watching one hands the test the
stream, and the test plays the camera's half of the signalling, so it can
see exactly what the dashboard asked for and answer it, with nothing to wait
for:

  * `{:synthetic_camera, {:watching, camera, stream, opts}}` is sent to the
    reporting process when the dashboard starts watching `camera`;
  * `to_browser/2` sends a signalling message from the "camera" to the
    dashboard, as a WebRTC sink would;
  * `{:synthetic_camera, {:from_browser, camera, message}}` reports each
    message the dashboard passes back;
  * `end_stream/1` ends a stream, as a camera stopping would;
  * `{:synthetic_camera, {:unwatched, camera, stream}}` reports the
    dashboard letting go.

`to_browser/2` and `end_stream/1` send straight from the test to the
watching process, so anything the test asks of that process afterwards is
answered with the message already handled.

# `stream`

```elixir
@type stream() :: %{
  camera: atom(),
  ref: reference(),
  report_to: pid() | nil,
  viewer: pid()
}
```

A stream: the watch the dashboard holds, and what the test is handed.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `end_stream`

```elixir
@spec end_stream(stream()) :: :ok
```

Ends a stream, as a camera stopping would.

# `set_status`

```elixir
@spec set_status(atom(), :capturing | :running | :declared) :: :ok
```

Changes a camera's status, standing in for a robot starting or a sensor dying.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts the synthetic camera.

## Options

* `:cameras` — required, a list of camera specifications. Each is a map of
  `:robot`, `:name`, and optionally `:path`, `:attached_to`, `:status`
  (`:capturing | :running | :declared`) and `:stream`.
* `:available?` — whether a camera package is installed, `true` by
  default; `false` stands in for an application without `bb_camera`.
* `:webrtc?` — whether streaming is available, `true` by default; `false`
  stands in for an application without `bb_camera_webrtc`.
* `:report_to` — the process to send events to.

# `to_browser`

```elixir
@spec to_browser(stream(), map()) :: :ok
```

Sends a signalling message from the camera's side of `stream` to the dashboard.

---

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