@@ -896,7 +896,7 @@ defmodule Membrane.RTC.Engine do
896
896
defp do_handle_notification (
897
897
{ :publish , { :new_tracks , tracks } } ,
898
898
{ :endpoint , endpoint_id } ,
899
- ctx ,
899
+ _ctx ,
900
900
state
901
901
) do
902
902
id_to_track = Map . new ( tracks , & { & 1 . id , & 1 } )
@@ -908,14 +908,7 @@ defmodule Membrane.RTC.Engine do
908
908
& Map . merge ( & 1 , id_to_track )
909
909
)
910
910
911
- tracks_msgs =
912
- do_publish (
913
- state . endpoints ,
914
- ctx ,
915
- { :new_tracks , tracks } ,
916
- { :endpoint , endpoint_id } ,
917
- state
918
- )
911
+ tracks_msgs = do_publish ( { :new_tracks , tracks } , { :endpoint , endpoint_id } , state )
919
912
920
913
endpoint = get_in ( state , [ :endpoints , endpoint_id ] )
921
914
track_id_to_track_metadata = Endpoint . get_active_track_metadata ( endpoint )
@@ -945,14 +938,7 @@ defmodule Membrane.RTC.Engine do
945
938
& Map . merge ( & 1 , id_to_track )
946
939
)
947
940
948
- tracks_msgs =
949
- do_publish (
950
- state . endpoints ,
951
- ctx ,
952
- { :remove_tracks , tracks } ,
953
- { :endpoint , endpoint_id } ,
954
- state
955
- )
941
+ tracks_msgs = do_publish ( { :remove_tracks , tracks } , { :endpoint , endpoint_id } , state )
956
942
957
943
track_ids = Enum . map ( tracks , & & 1 . id )
958
944
@@ -1197,8 +1183,6 @@ defmodule Membrane.RTC.Engine do
1197
1183
1198
1184
{ _peer , state } = pop_in ( state , [ :peers , peer_id ] )
1199
1185
{ _status , actions , state } = do_remove_endpoint ( peer_id , ctx , state )
1200
- { _waiting , state } = pop_in ( state , [ :waiting_for_linking , peer_id ] )
1201
- { _subscriptions , state } = pop_in ( state , [ :subscriptions , peer_id ] )
1202
1186
{ :present , actions , state }
1203
1187
else
1204
1188
{ :absent , [ ] , state }
@@ -1208,16 +1192,11 @@ defmodule Membrane.RTC.Engine do
1208
1192
defp do_remove_endpoint ( peer_id , ctx , state ) do
1209
1193
if Map . has_key? ( state . endpoints , peer_id ) do
1210
1194
{ endpoint , state } = pop_in ( state , [ :endpoints , peer_id ] )
1195
+ { _waiting , state } = pop_in ( state , [ :waiting_for_linking , peer_id ] )
1196
+ { _subscriptions , state } = pop_in ( state , [ :subscriptions , peer_id ] )
1211
1197
tracks = Enum . map ( Endpoint . get_tracks ( endpoint ) , & % Track { & 1 | active?: true } )
1212
1198
1213
- tracks_msgs =
1214
- do_publish (
1215
- state . endpoints ,
1216
- ctx ,
1217
- { :remove_tracks , tracks } ,
1218
- { :endpoint , peer_id } ,
1219
- state
1220
- )
1199
+ tracks_msgs = do_publish ( { :remove_tracks , tracks } , { :endpoint , peer_id } , state )
1221
1200
1222
1201
endpoint_bin = ctx . children [ { :endpoint , peer_id } ]
1223
1202
@@ -1255,46 +1234,46 @@ defmodule Membrane.RTC.Engine do
1255
1234
|> Enum . filter ( & Map . has_key? ( ctx . children , & 1 ) )
1256
1235
end
1257
1236
1258
- defp do_publish ( _endpoints , _ctx , { _ , [ ] } = _tracks , _endpoint_bin , _state ) , do: [ ]
1237
+ defp do_publish ( { _ , [ ] } = _tracks , _endpoint_bin , _state ) , do: [ ]
1259
1238
1260
- defp do_publish ( endpoints , ctx , { :new_tracks , _tracks } = msg , endpoint_bin_name , _state ) do
1261
- flat_map_children ( ctx , fn
1262
- { :endpoint , endpoint_id } = other_endpoint_bin ->
1263
- endpoint = Map . get ( endpoints , endpoint_id )
1239
+ defp do_publish ( { :new_tracks , _tracks } = msg , endpoint_bin_name , state ) do
1240
+ Enum . flat_map ( state . endpoints , fn { endpoint_id , endpoint } ->
1241
+ current_endpoint_bin_name = { :endpoint , endpoint_id }
1264
1242
1265
- if other_endpoint_bin != endpoint_bin_name and not is_nil ( endpoint ) do
1266
- [ forward: { other_endpoint_bin , msg } ]
1267
- else
1268
- [ ]
1269
- end
1270
-
1271
- _child ->
1243
+ if current_endpoint_bin_name != endpoint_bin_name and not is_nil ( endpoint ) do
1244
+ [ forward: { current_endpoint_bin_name , msg } ]
1245
+ else
1272
1246
[ ]
1247
+ end
1273
1248
end )
1274
1249
end
1275
1250
1276
- defp do_publish ( endpoints , ctx , { type , tracks } , endpoint_bin_name , state ) do
1277
- flat_map_children ( ctx , fn
1278
- { :endpoint , endpoint_id } = other_endpoint_bin ->
1279
- endpoint = Map . get ( endpoints , endpoint_id )
1251
+ defp do_publish ( { :remove_tracks , tracks } , endpoint_bin_name , state ) do
1252
+ Enum . flat_map ( state . endpoints , fn { endpoint_id , endpoint } ->
1253
+ current_endpoint_bin_name = { :endpoint , endpoint_id }
1280
1254
1281
- has_subscription_on_track = fn track_id ->
1282
- state . subscriptions
1283
- |> Map . fetch! ( endpoint_id )
1284
- |> Map . has_key? ( track_id )
1285
- end
1255
+ has_subscription_on_track = fn track_id ->
1256
+ state . subscriptions
1257
+ |> Map . fetch! ( endpoint_id )
1258
+ |> Map . has_key? ( track_id )
1259
+ end
1286
1260
1287
- new_tracks = Enum . filter ( tracks , & has_subscription_on_track . ( & 1 . id ) )
1288
- msg = { type , new_tracks }
1261
+ tracks_to_remove = Enum . filter ( tracks , & has_subscription_on_track . ( & 1 . id ) )
1262
+ msg = { :remove_tracks , tracks_to_remove }
1289
1263
1290
- if other_endpoint_bin != endpoint_bin_name and not is_nil ( endpoint ) do
1291
- [ forward: { other_endpoint_bin , msg } ]
1292
- else
1293
- [ ]
1294
- end
1295
-
1296
- _child ->
1264
+ if current_endpoint_bin_name != endpoint_bin_name and not is_nil ( endpoint ) do
1265
+ [ forward: { current_endpoint_bin_name , msg } ]
1266
+ else
1297
1267
[ ]
1268
+ end
1298
1269
end )
1299
1270
end
1271
+
1272
+ defp do_publish ( msg , _endpoint_bin_name , _state ) do
1273
+ Membrane.Logger . warn (
1274
+ "Requested unknown message type to be published by RTC Engine #{ inspect ( msg ) } . Ignoring."
1275
+ )
1276
+
1277
+ [ ]
1278
+ end
1300
1279
end
0 commit comments