@@ -1186,7 +1186,8 @@ defmodule ExWebRTC.PeerConnection do
1186
1186
end
1187
1187
1188
1188
@ impl true
1189
- def handle_cast ( { :send_rtp , track_id , packet , opts } , state ) do
1189
+ def handle_cast ( { :send_rtp , track_id , packet , opts } , % { conn_state: conn_state } = state )
1190
+ when conn_state != :failed do
1190
1191
rtx? = Keyword . get ( opts , :rtx? , false )
1191
1192
1192
1193
# TODO: iterating over transceivers is not optimal
@@ -1238,7 +1239,8 @@ defmodule ExWebRTC.PeerConnection do
1238
1239
end
1239
1240
1240
1241
@ impl true
1241
- def handle_cast ( { :send_pli , track_id , rid } , state ) do
1242
+ def handle_cast ( { :send_pli , track_id , rid } , % { conn_state: conn_state } = state )
1243
+ when conn_state != :failed do
1242
1244
state . transceivers
1243
1245
|> Enum . with_index ( )
1244
1246
|> Enum . find ( fn { tr , _idx } -> tr . receiver . track . id == track_id end )
@@ -1265,7 +1267,8 @@ defmodule ExWebRTC.PeerConnection do
1265
1267
end
1266
1268
1267
1269
@ impl true
1268
- def handle_cast ( { :send_data , channel_ref , data_type , data } , state ) do
1270
+ def handle_cast ( { :send_data , channel_ref , data_type , data } , % { conn_state: conn_state } = state )
1271
+ when conn_state != :failed do
1269
1272
{ events , sctp_transport } =
1270
1273
SCTPTransport . send ( state . sctp_transport , channel_ref , data_type , data )
1271
1274
@@ -1280,6 +1283,12 @@ defmodule ExWebRTC.PeerConnection do
1280
1283
{ :noreply , state }
1281
1284
end
1282
1285
1286
+ @ impl true
1287
+ def handle_cast ( msg , state ) do
1288
+ Logger . warning ( "Unexpected cast in state: #{ state . conn_state } . Cast: #{ inspect ( msg ) } " )
1289
+ { :noreply , state }
1290
+ end
1291
+
1283
1292
@ impl true
1284
1293
def handle_info ( { :ex_ice , _from , { :connection_state_change , new_ice_state } } , state ) do
1285
1294
state = % { state | ice_state: new_ice_state }
@@ -1294,7 +1303,7 @@ defmodule ExWebRTC.PeerConnection do
1294
1303
1295
1304
if next_conn_state == :failed do
1296
1305
Logger . debug ( "Stopping PeerConnection" )
1297
- { :stop , { :shutdown , :conn_state_failed } , state }
1306
+ { :noreply , state }
1298
1307
else
1299
1308
{ :noreply , state }
1300
1309
end
0 commit comments