Octoroom.Reconciler (octoroom v0.1.0)

Copy Markdown View Source

Diffs desired against actual room state and returns the operations that turn one into the other. Pure.

desired maps each participant that can receive (its connection is up) to the tracks it should hear. actual has:

  • :subscriptions: participant id => track name => %{status: :opening | :open | :closing, gain: float}
  • :tracks: the track directory, track name => :pending | :live

Operations, in the order they should be applied:

  1. {:close_subscription, participant_id, name}: open, but no longer desired, no longer published, or stale: true (pulled from a session that's gone, such as a worker output's before a restart; once closed, it's pulled again from the track's new session).
  2. {:open_subscription, participant_id, name, %{gain: g}}: desired and live. Subscriptions to pending tracks wait until they go live.
  3. {:update_subscription, participant_id, name, %{gain: g}}: open and staying open, with a different gain.

Subscriptions with an operation in flight (:opening, :closing) are left alone; the next diff after that operation settles picks them up.

Summary

Functions

Diffs the worker specs workers/1 returned against the running workers and their media. actual has

A policy result entry as a track: a name means full gain.

Types

op()

@type op() ::
  {:close_subscription, String.t(), String.t()}
  | {:open_subscription, String.t(), String.t(), map()}
  | {:update_subscription, String.t(), String.t(), map()}

worker_op()

@type worker_op() ::
  {:stop_inlet, {String.t(), String.t()}}
  | {:stop_outlet, String.t()}
  | {:stop_worker, String.t()}
  | {:start_worker, map()}
  | {:restart_worker, map()}
  | {:update_worker, map()}
  | {:start_outlet, String.t(), String.t()}
  | {:start_inlet, {String.t(), String.t()}}

Functions

diff(desired, actual)

@spec diff(%{required(String.t()) => [Octoroom.Track.t()]}, map()) :: [op()]

diff_workers(specs, actual)

@spec diff_workers([map()], map()) :: [worker_op()]

Diffs the worker specs workers/1 returned against the running workers and their media. actual has:

  • :workers: worker id => the spec it runs
  • :outlets: output track name => the id of the worker it belongs to
  • :inlets: a list of {worker_id, input track name}
  • :tracks: the track directory, as for diff/2

Operations, in the order they should be applied: tear down first, so capacity and billing go down before they go up.

  1. {:stop_inlet, {worker_id, input}}: no longer an input, or its track is gone.
  2. {:stop_outlet, name}: no longer any worker's output, or now another worker's: it's stopped here and started again for that worker.
  3. {:stop_worker, id}: no longer in the specs.
  4. {:start_worker, spec}, {:restart_worker, spec} (its module or args changed) and {:update_worker, spec} (only its inputs, outputs or data outputs changed: the worker keeps running).
  5. {:start_outlet, name, worker_id}: an output with no outlet of this worker's. If two workers name the same output, the first one in the specs has it.
  6. {:start_inlet, {worker_id, input}}: an input whose track is live. Inlets of pending tracks wait until they go live.

normalize(track)

A policy result entry as a track: a name means full gain.