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

[RTC-228] Don't send new_tracks notification with empty list #269

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/membrane_rtc_engine/engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,19 @@ defmodule Membrane.RTC.Engine do
|> Map.keys()
|> Enum.map(&{:notify_child, {{:endpoint, &1}, {:new_peer, peer}}})

active_tracks = get_active_tracks(state.endpoints)

new_tracks_notification =
if active_tracks == [] do
[]
else
[notify_child: {{:endpoint, endpoint_id}, {:new_tracks, active_tracks}}]
end

actions =
[
notify_child: {{:endpoint, endpoint_id}, {:ready, peers_in_room}},
notify_child:
{{:endpoint, endpoint_id}, {:new_tracks, get_active_tracks(state.endpoints)}}
] ++ new_peer_notifications
notify_child: {{:endpoint, endpoint_id}, {:ready, peers_in_room}}
] ++ new_tracks_notification ++ new_peer_notifications

state =
state
Expand Down Expand Up @@ -850,11 +857,13 @@ defmodule Membrane.RTC.Engine do
else: []

# Only inform about the tracks if we're not taking about a peer
active_tracks = get_active_tracks(state.endpoints)

tracks_actions =
if is_peer? do
[]
if not is_peer? and active_tracks != [] do
[notify_child: {endpoint_name, {:new_tracks, active_tracks}}]
else
[notify_child: {endpoint_name, {:new_tracks, get_active_tracks(state.endpoints)}}]
[]
end

actions = [spec: spec] ++ display_manager_message ++ tracks_actions
Expand Down
2 changes: 2 additions & 0 deletions test/membrane_rtc_engine/engine_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defmodule Membrane.RTC.EngineTest do

assert_receive {:new_peer, %Peer{id: "peer", metadata: "metadata"}}
assert_receive {:ready, []}
refute_receive {:new_tracks, []}
end

test "is ignored for non-peers", %{rtc_engine: rtc_engine} do
Expand All @@ -52,6 +53,7 @@ defmodule Membrane.RTC.EngineTest do

refute_receive {:new_peer, _peer}
refute_receive {:ready, _peers_in_room}
refute_receive {:new_tracks, []}
end

test "reports other peers", %{rtc_engine: rtc_engine} do
Expand Down