Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 61b1caf

Browse files
author
Michał Śledź
committed
Refactor link_inbound_track function
1 parent 44c1091 commit 61b1caf

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lib/membrane_rtc_engine/engine.ex

+16-12
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,20 @@ defmodule Membrane.RTC.Engine do
839839

840840
state = put_in(state, [:filters, track_id], depayloading_filter)
841841
track = state.endpoints |> Map.fetch!(endpoint_id) |> Endpoint.get_track_by_id(track_id)
842-
{links, state} = link_inbound_track(track_id, rid, track, endpoint_id, ctx, state)
842+
{links, state} = create_tee_and_link(track_id, rid, track, endpoint_id, ctx, state)
843+
844+
# check for subscriptions for this track and fulfill them
845+
{pending_track_subscriptions, pending_rest_subscriptions} =
846+
Enum.split_with(state.pending_subscriptions, &(&1.track_id == track.id))
847+
848+
{links, state} =
849+
Enum.flat_map_reduce(pending_track_subscriptions, state, fn subscription, state ->
850+
fulfill_subscription(subscription, ctx, state)
851+
end)
852+
853+
state = %{state | pending_subscriptions: pending_rest_subscriptions}
854+
855+
links = endpoint_to_tee_links ++ links
843856

844857
spec = %ParentSpec{
845858
links: links,
@@ -925,7 +938,7 @@ defmodule Membrane.RTC.Engine do
925938
{:ok, state}
926939
end
927940

928-
defp link_inbound_track(track_id, rid, track, endpoint_id, ctx, state) do
941+
defp create_tee_and_link(track_id, rid, track, endpoint_id, ctx, state) do
929942
tee =
930943
cond do
931944
rid != nil ->
@@ -959,16 +972,7 @@ defmodule Membrane.RTC.Engine do
959972
end
960973
]
961974

962-
{pending_track_subscriptions, pending_rest_subscriptions} =
963-
Enum.split_with(state.pending_subscriptions, &(&1.track_id == track.id))
964-
965-
{links, state} =
966-
Enum.flat_map_reduce(pending_track_subscriptions, state, fn subscription, state ->
967-
fulfill_subscription(subscription, ctx, state)
968-
end)
969-
970-
state = %{state | pending_subscriptions: pending_rest_subscriptions}
971-
{endpoint_to_tee_links ++ links, state}
975+
{endpoint_to_tee_links, state}
972976
end
973977

974978
defp check_subscription(subscription, state) do

0 commit comments

Comments
 (0)