Skip to content

Commit 77b907d

Browse files
authored
[Broadcaster] Add a log when input or output PC exits. Cleanup pending_outputs (#20)
1 parent 4663179 commit 77b907d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

broadcaster/lib/broadcaster/forwarder.ex

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,28 @@ defmodule Broadcaster.Forwarder do
135135
end
136136

137137
@impl true
138-
def handle_info({:DOWN, _ref, :process, pid, _reason}, %{input_pc: pid} = state) do
138+
def handle_info({:DOWN, _ref, :process, pid, reason}, %{input_pc: pid} = state) do
139+
Logger.info("Input process: #{inspect(pid)} exited with reason: #{inspect(reason)}")
139140
state = %{state | input_pc: nil, audio_input: nil, video_input: nil}
140141
{:noreply, state}
141142
end
142143

143144
@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}
145+
def handle_info({:DOWN, _ref, :process, pid, reason}, state) do
146+
cond do
147+
Map.has_key?(state.outputs, pid) ->
148+
Logger.info("Output process: #{inspect(pid)} exited with reason: #{inspect(reason)}")
149+
{_, state} = pop_in(state, [:outputs, pid])
150+
{:noreply, state}
151+
152+
pid in state.pending_outputs ->
153+
Logger.info("""
154+
Pending output process: #{inspect(pid)} exited with reason: #{inspect(reason)}\
155+
""")
156+
157+
pending_outputs = List.delete(state.pending_outputs, pid)
158+
{:noreply, %{state | pending_outputs: pending_outputs}}
159+
end
148160
end
149161

150162
@impl true

0 commit comments

Comments
 (0)