Skip to content

Commit

Permalink
Apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LVala committed Nov 6, 2023
1 parent 2dd32ca commit 513a914
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/ex_webrtc/dtls_transport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ defmodule ExWebRTC.DTLSTransport do
:pkey,
:fingerprint,
:mode,
finished: false,
should_start: false
finished: false
]

def new(ice_agent) do
Expand Down Expand Up @@ -43,7 +42,7 @@ defmodule ExWebRTC.DTLSTransport do
cert: dtls.cert
)

%__MODULE__{dtls | client: client}
%__MODULE__{dtls | client: client, mode: :passive}
end

def start(dtls, :active) do
Expand All @@ -56,23 +55,19 @@ defmodule ExWebRTC.DTLSTransport do
)

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

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

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/dtls_transport.ex#L62-L64

Added lines #L62 - L64 were not covered by tests
end

dtls =
if dtls.buffered_packets do
Logger.debug("Sending buffered DTLS packets")
ICEAgent.send_data(dtls.ice_agent, dtls.buffered_packets)
:ok = ICEAgent.send_data(dtls.ice_agent, dtls.buffered_packets)
%__MODULE__{dtls | buffered_packets: nil}

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/dtls_transport.ex#L67-L71

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

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/dtls_transport.ex#L73

Added line #L73 was not covered by tests
Expand Down

0 comments on commit 513a914

Please sign in to comment.