@@ -577,7 +577,7 @@ defmodule ExWebRTC.PeerConnection do
577577 on_data: nil
578578 ]
579579
580- { :ok , ice_pid } = DefaultICETransport . start_link ( :controlled , ice_config )
580+ { :ok , ice_pid } = DefaultICETransport . start_link ( ice_config )
581581 { :ok , dtls_transport } = DTLSTransport . start_link ( DefaultICETransport , ice_pid )
582582 # route data to the DTLSTransport
583583 :ok = DefaultICETransport . on_data ( ice_pid , dtls_transport )
@@ -1188,7 +1188,7 @@ defmodule ExWebRTC.PeerConnection do
11881188 timestamp: timestamp ,
11891189 ice_state: ice_stats . state ,
11901190 ice_gathering_state: state . ice_gathering_state ,
1191- ice_role: ice_stats . role ,
1191+ ice_role: ice_stats . role || :unknown ,
11921192 ice_local_ufrag: ice_stats . local_ufrag ,
11931193 dtls_state: state . dtls_state ,
11941194 bytes_sent: ice_stats . bytes_sent ,
@@ -1361,6 +1361,8 @@ defmodule ExWebRTC.PeerConnection do
13611361 def handle_info ( { :dtls_transport , _pid , { :state_change , new_dtls_state } } , state ) do
13621362 next_conn_state = next_conn_state ( state . ice_state , new_dtls_state )
13631363
1364+ notify ( state . owner , { :dtls_state_change , new_dtls_state } )
1365+
13641366 state =
13651367 % { state | dtls_state: new_dtls_state }
13661368 |> update_conn_state ( next_conn_state )
@@ -1717,6 +1719,13 @@ defmodule ExWebRTC.PeerConnection do
17171719 with { :ok , next_sig_state } <- next_signaling_state ( state . signaling_state , :local , type ) ,
17181720 :ok <- check_altered ( type , raw_sdp , state ) ,
17191721 { :ok , sdp } <- parse_sdp ( raw_sdp ) do
1722+ # See: https://www.w3.org/TR/webrtc/#ref-for-dfn-icerole-1
1723+ # Also, this has to be before gathering candidates.
1724+ # Note: If we add support for ice-lite, this code needs to be adjusted.
1725+ if state . ice_transport . get_role ( state . ice_pid ) == nil and type == :offer do
1726+ :ok = state . ice_transport . set_role ( state . ice_pid , :controlling )
1727+ end
1728+
17201729 if state . ice_gathering_state == :new do
17211730 state . ice_transport . gather_candidates ( state . ice_pid )
17221731 end
@@ -1755,10 +1764,23 @@ defmodule ExWebRTC.PeerConnection do
17551764 { :ok , sdp } <- parse_sdp ( raw_sdp ) ,
17561765 :ok <- SDPUtils . ensure_valid ( sdp ) ,
17571766 { :ok , ice_creds } <- SDPUtils . get_ice_credentials ( sdp ) ,
1767+ ice_lite <- SDPUtils . get_ice_lite ( sdp ) ,
17581768 { :ok , { :fingerprint , { :sha256 , peer_fingerprint } } } <- SDPUtils . get_cert_fingerprint ( sdp ) ,
17591769 { :ok , dtls_role } <- SDPUtils . get_dtls_role ( sdp ) do
17601770 config = Configuration . update ( state . config , sdp )
17611771
1772+ # See: https://www.w3.org/TR/webrtc/#ref-for-dfn-icerole-1
1773+ # Note: If we add support for ice-lite, this code needs to be adjusted.
1774+ if state . ice_transport . get_role ( state . ice_pid ) == nil do
1775+ cond do
1776+ type == :offer and ice_lite == true ->
1777+ :ok = state . ice_transport . set_role ( state . ice_pid , :controlling )
1778+
1779+ type == :offer and ice_lite == false ->
1780+ :ok = state . ice_transport . set_role ( state . ice_pid , :controlled )
1781+ end
1782+ end
1783+
17621784 twcc_id =
17631785 ( config . video_extensions ++ config . audio_extensions )
17641786 |> Enum . find ( & ( & 1 . uri == @ twcc_uri ) )
0 commit comments