From 513a9143d8cea5dd86e2c49eacd5101ccfc9368b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wala?= Date: Mon, 6 Nov 2023 09:56:01 +0100 Subject: [PATCH] Apply requested changes --- lib/ex_webrtc/dtls_transport.ex | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/ex_webrtc/dtls_transport.ex b/lib/ex_webrtc/dtls_transport.ex index 726357b7..306f3ce6 100644 --- a/lib/ex_webrtc/dtls_transport.ex +++ b/lib/ex_webrtc/dtls_transport.ex @@ -14,8 +14,7 @@ defmodule ExWebRTC.DTLSTransport do :pkey, :fingerprint, :mode, - finished: false, - should_start: false + finished: false ] def new(ice_agent) do @@ -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 @@ -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) + 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} else dtls