@@ -685,7 +685,7 @@ defmodule ExWebRTC.PeerConnection do
685685
686686 @ impl true
687687 def handle_call (
688- { :set_sender_code , _sender_id , _codec } ,
688+ { :set_sender_codec , _sender_id , _codec } ,
689689 _from ,
690690 % { signaling_state: :closed } = state
691691 ) do
@@ -1151,7 +1151,7 @@ defmodule ExWebRTC.PeerConnection do
11511151 def handle_call (
11521152 { :create_data_channel , _label , _opts } ,
11531153 _from ,
1154- % { connection_state : :closed } = state
1154+ % { signaling_state : :closed } = state
11551155 ) do
11561156 { :reply , { :error , :invalid_state } , state }
11571157 end
@@ -1382,14 +1382,28 @@ defmodule ExWebRTC.PeerConnection do
13821382
13831383 @ impl true
13841384 def handle_call ( :close , _from , % { signaling_state: :closed } = state ) do
1385- { :reply , { :error , :invalid_state } , state }
1385+ { :reply , :ok , state }
13861386 end
13871387
13881388 @ impl true
13891389 def handle_call ( :close , _from , state ) do
13901390 Logger . debug ( "Closing peer connection" )
1391- # don't emit state change events
1392- state = do_close ( state , notify: false )
1391+ transceivers = Enum . map ( state . transceivers , & RTPTransceiver . stop ( & 1 ) )
1392+ sctp_transport = SCTPTransport . close_abruptly ( state . sctp_transport )
1393+ :ok = DTLSTransport . close ( state . dtls_transport )
1394+ :ok = state . ice_transport . close ( state . ice_pid )
1395+
1396+ state =
1397+ % {
1398+ state
1399+ | ice_state: :closed ,
1400+ dtls_state: :closed ,
1401+ transceivers: transceivers ,
1402+ sctp_transport: sctp_transport
1403+ }
1404+ |> update_signaling_state ( :closed , notify: false )
1405+ |> update_conn_state ( :closed , notify: false )
1406+
13931407 { :reply , :ok , state }
13941408 end
13951409
@@ -1548,17 +1562,12 @@ defmodule ExWebRTC.PeerConnection do
15481562
15491563 next_conn_state = next_conn_state ( state . ice_state , new_dtls_state )
15501564
1551- if next_conn_state == :closed and state . conn_state != :closed do
1552- state = do_close ( state )
1553- { :noreply , state }
1554- else
1555- state =
1556- % { state | dtls_state: new_dtls_state }
1557- |> update_conn_state ( next_conn_state )
1558- |> maybe_connect_sctp ( )
1565+ state =
1566+ % { state | dtls_state: new_dtls_state }
1567+ |> update_conn_state ( next_conn_state )
1568+ |> maybe_connect_sctp ( )
15591569
1560- { :noreply , state }
1561- end
1570+ { :noreply , state }
15621571 end
15631572
15641573 @ impl true
@@ -2325,13 +2334,8 @@ defmodule ExWebRTC.PeerConnection do
23252334 # the order of these clauses is important
23262335 defp next_conn_state ( ice_state , dtls_state )
23272336
2328- # Give closed precedence over failed.
2329- # Failed connection can be restarted.
2330- # Closed connection can't be reused.
23312337 defp next_conn_state ( :closed , _dtls_state ) , do: :closed
23322338
2333- defp next_conn_state ( _ice_state , :closed ) , do: :closed
2334-
23352339 defp next_conn_state ( :failed , _dtls_state ) , do: :failed
23362340
23372341 defp next_conn_state ( _ice_state , :failed ) , do: :failed
@@ -2342,8 +2346,9 @@ defmodule ExWebRTC.PeerConnection do
23422346 when ice_state in [ :new , :checking ] or dtls_state in [ :new , :connecting ] ,
23432347 do: :connecting
23442348
2345- defp next_conn_state ( ice_state , :connected ) when ice_state in [ :connected , :completed ] ,
2346- do: :connected
2349+ defp next_conn_state ( ice_state , dtls_state )
2350+ when ice_state in [ :connected , :completed ] and dtls_state in [ :connected , :closed ] ,
2351+ do: :connected
23472352
23482353 defp update_conn_state ( state , conn_state , opts \\ [ ] )
23492354 defp update_conn_state ( % { conn_state: conn_state } = state , conn_state , _opts ) , do: state
@@ -2551,27 +2556,6 @@ defmodule ExWebRTC.PeerConnection do
25512556 % SessionDescription { type: type , sdp: to_string ( sdp ) }
25522557 end
25532558
2554- defp do_close ( state , opts \\ [ ] ) do
2555- transceivers = Enum . map ( state . transceivers , & RTPTransceiver . stop ( & 1 ) )
2556- sctp_transport = SCTPTransport . close_abruptly ( state . sctp_transport )
2557- :ok = DTLSTransport . close ( state . dtls_transport )
2558- :ok = state . ice_transport . close ( state . ice_pid )
2559-
2560- if opts [ :notify ] != false do
2561- notify ( state . owner , { :ice_connection_state_change , :closed } )
2562- end
2563-
2564- % {
2565- state
2566- | ice_state: :closed ,
2567- dtls_state: :closed ,
2568- transceivers: transceivers ,
2569- sctp_transport: sctp_transport
2570- }
2571- |> update_signaling_state ( :closed , opts )
2572- |> update_conn_state ( :closed , opts )
2573- end
2574-
25752559 defp generate_ssrcs ( state ) do
25762560 generate_ssrcs ( state . transceivers , Map . keys ( state . demuxer . ssrc_to_mid ) )
25772561 end
0 commit comments