@@ -36,6 +36,8 @@ defmodule Broadcaster.Forwarder do
36
36
37
37
@ impl true
38
38
def handle_call ( { :connect_input , pc } , _from , state ) do
39
+ Process . monitor ( pc )
40
+
39
41
if state . input_pc != nil do
40
42
PeerSupervisor . terminate_pc ( state . input_pc )
41
43
end
@@ -51,6 +53,8 @@ defmodule Broadcaster.Forwarder do
51
53
52
54
@ impl true
53
55
def handle_call ( { :connect_output , pc } , _from , state ) do
56
+ Process . monitor ( pc )
57
+
54
58
PeerConnection . controlling_process ( pc , self ( ) )
55
59
pending_outputs = [ pc | state . pending_outputs ]
56
60
@@ -130,6 +134,19 @@ defmodule Broadcaster.Forwarder do
130
134
{ :noreply , state }
131
135
end
132
136
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
+
133
150
@ impl true
134
151
def handle_info ( _msg , state ) do
135
152
{ :noreply , state }
0 commit comments