Skip to content

Commit 27c267d

Browse files
committed
Don't terminate PeerConnection after moving to the failed state
1 parent 241931e commit 27c267d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/ex_webrtc/peer_connection.ex

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ defmodule ExWebRTC.PeerConnection do
409409
410410
For more information, refer to the [RTCPeerConnection: createOffer() method](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createOffer).
411411
"""
412-
@spec create_offer(peer_connection(), restart_ice?: boolean()) ::
412+
@spec create_offer(peer_connection(), ice_restart: boolean()) ::
413413
{:ok, SessionDescription.t()} | {:error, term()}
414414
def create_offer(peer_connection, options \\ []) do
415415
GenServer.call(peer_connection, {:create_offer, options})
@@ -1186,7 +1186,8 @@ defmodule ExWebRTC.PeerConnection do
11861186
end
11871187

11881188
@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
11901191
rtx? = Keyword.get(opts, :rtx?, false)
11911192

11921193
# TODO: iterating over transceivers is not optimal
@@ -1238,7 +1239,8 @@ defmodule ExWebRTC.PeerConnection do
12381239
end
12391240

12401241
@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
12421244
state.transceivers
12431245
|> Enum.with_index()
12441246
|> Enum.find(fn {tr, _idx} -> tr.receiver.track.id == track_id end)
@@ -1265,7 +1267,8 @@ defmodule ExWebRTC.PeerConnection do
12651267
end
12661268

12671269
@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
12691272
{events, sctp_transport} =
12701273
SCTPTransport.send(state.sctp_transport, channel_ref, data_type, data)
12711274

@@ -1280,6 +1283,12 @@ defmodule ExWebRTC.PeerConnection do
12801283
{:noreply, state}
12811284
end
12821285

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+
12831292
@impl true
12841293
def handle_info({:ex_ice, _from, {:connection_state_change, new_ice_state}}, state) do
12851294
state = %{state | ice_state: new_ice_state}
@@ -1294,7 +1303,7 @@ defmodule ExWebRTC.PeerConnection do
12941303

12951304
if next_conn_state == :failed do
12961305
Logger.debug("Stopping PeerConnection")
1297-
{:stop, {:shutdown, :conn_state_failed}, state}
1306+
{:noreply, state}
12981307
else
12991308
{:noreply, state}
13001309
end

0 commit comments

Comments
 (0)