Skip to content

Commit 97c68d7

Browse files
authored
[Broadcaster] Remove closed inputs and outputs from Forwarder's state. (#15)
1 parent 1ce37eb commit 97c68d7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

broadcaster/lib/broadcaster/forwarder.ex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ defmodule Broadcaster.Forwarder do
3636

3737
@impl true
3838
def handle_call({:connect_input, pc}, _from, state) do
39+
Process.monitor(pc)
40+
3941
if state.input_pc != nil do
4042
PeerSupervisor.terminate_pc(state.input_pc)
4143
end
@@ -51,6 +53,8 @@ defmodule Broadcaster.Forwarder do
5153

5254
@impl true
5355
def handle_call({:connect_output, pc}, _from, state) do
56+
Process.monitor(pc)
57+
5458
PeerConnection.controlling_process(pc, self())
5559
pending_outputs = [pc | state.pending_outputs]
5660

@@ -130,6 +134,19 @@ defmodule Broadcaster.Forwarder do
130134
{:noreply, state}
131135
end
132136

137+
@impl true
138+
def handle_info({:DOWN, _ref, :process, pid, _reason}, %{input_pc: pid} = state) do
139+
state = %{state | input_pc: nil, audio_input: nil, video_input: nil}
140+
{:noreply, state}
141+
end
142+
143+
@impl true
144+
def handle_info({:DOWN, _ref, :process, pid, _reason}, state)
145+
when is_map_key(state.outputs, pid) do
146+
{_, state} = pop_in(state, [:outputs, pid])
147+
{:noreply, state}
148+
end
149+
133150
@impl true
134151
def handle_info(_msg, state) do
135152
{:noreply, state}

0 commit comments

Comments
 (0)