Skip to content

Commit

Permalink
Simplify start of DTLS handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
LVala committed Nov 3, 2023
1 parent 11e2947 commit 2dd32ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
22 changes: 5 additions & 17 deletions lib/ex_webrtc/dtls_transport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule ExWebRTC.DTLSTransport do
%__MODULE__{dtls | client: client}
end

def start(%{ice_state: ice_state} = dtls, :active) do
def start(dtls, :active) do
{:ok, client} =
ExDTLS.start_link(
client_mode: true,
Expand All @@ -55,22 +55,15 @@ defmodule ExWebRTC.DTLSTransport do
cert: dtls.cert
)

dtls = %__MODULE__{dtls | client: client}

case ice_state do
state when state in [:active, :connected] ->
start_handshake(dtls)
dtls

_other ->
%__MODULE__{dtls | should_start: true}
end
# we assume that ICE in not in connected state yet
%__MODULE__{dtls | client: client, should_start: true}
end

def update_ice_state(dtls, :connected) do
dtls =
if dtls.should_start do
start_handshake(dtls)
{:ok, packets} = ExDTLS.do_handshake(dtls.client)
:ok = ICEAgent.send_data(dtls.ice_agent, packets)
%__MODULE__{dtls | should_start: false}

Check warning on line 67 in lib/ex_webrtc/dtls_transport.ex

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/dtls_transport.ex#L63-L67

Added lines #L63 - L67 were not covered by tests
else
dtls

Check warning on line 69 in lib/ex_webrtc/dtls_transport.ex

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/dtls_transport.ex#L69

Added line #L69 was not covered by tests
Expand Down Expand Up @@ -132,9 +125,4 @@ defmodule ExWebRTC.DTLSTransport do
dtls

Check warning on line 125 in lib/ex_webrtc/dtls_transport.ex

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/dtls_transport.ex#L125

Added line #L125 was not covered by tests
end
end

defp start_handshake(dtls) do
{:ok, packets} = ExDTLS.do_handshake(dtls.client)
:ok = ICEAgent.send_data(dtls.ice_agent, packets)
end
end
5 changes: 5 additions & 0 deletions lib/ex_webrtc/peer_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ defmodule ExWebRTC.PeerConnection do
end
end

@impl true
def handle_call({:add_ice_candidate, _}, _from, %{current_remote_desc: nil} = state) do
{:reply, {:error, :no_remote_description}, state}

Check warning on line 288 in lib/ex_webrtc/peer_connection.ex

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L288

Added line #L288 was not covered by tests
end

@impl true
def handle_call({:add_ice_candidate, candidate}, _from, state) do
with "candidate:" <> attr <- candidate.candidate do
Expand Down

0 comments on commit 2dd32ca

Please sign in to comment.