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

Commit

Permalink
[RTC-228] Don't send new_tracks notification with empty list (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 authored May 15, 2023
1 parent ff2bd9b commit 65b3347
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
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

0 comments on commit 65b3347

Please sign in to comment.