BB.LiveView.SyntheticCamera (bb_liveview v0.5.1)

Copy Markdown View Source

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.

Summary

Types

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

Functions

Returns a specification to start this module under a supervisor.

Ends a stream, as a camera stopping would.

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

Starts the synthetic camera.

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

Types

stream()

@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.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

end_stream(stream)

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

Ends a stream, as a camera stopping would.

set_status(camera, status)

@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(opts)

@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(stream, message)

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

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