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:
{:close_subscription, participant_id, name}: open, but no longer desired, no longer published, orstale: 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).{:open_subscription, participant_id, name, %{gain: g}}: desired and live. Subscriptions to pending tracks wait until they go live.{: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
Functions
@spec diff(%{required(String.t()) => [Octoroom.Track.t()]}, map()) :: [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 fordiff/2
Operations, in the order they should be applied: tear down first, so capacity and billing go down before they go up.
{:stop_inlet, {worker_id, input}}: no longer an input, or its track is gone.{:stop_outlet, name}: no longer any worker's output, or now another worker's: it's stopped here and started again for that worker.{:stop_worker, id}: no longer in the specs.{: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).{: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.{:start_inlet, {worker_id, input}}: an input whose track is live. Inlets of pending tracks wait until they go live.
A policy result entry as a track: a name means full gain.