@@ -839,7 +839,20 @@ defmodule Membrane.RTC.Engine do
839
839
840
840
state = put_in ( state , [ :filters , track_id ] , depayloading_filter )
841
841
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
843
856
844
857
spec = % ParentSpec {
845
858
links: links ,
@@ -925,7 +938,7 @@ defmodule Membrane.RTC.Engine do
925
938
{ :ok , state }
926
939
end
927
940
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
929
942
tee =
930
943
cond do
931
944
rid != nil ->
@@ -959,16 +972,7 @@ defmodule Membrane.RTC.Engine do
959
972
end
960
973
]
961
974
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 }
972
976
end
973
977
974
978
defp check_subscription ( subscription , state ) do
0 commit comments