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 17, 2023
1 parent dbfea02 commit 3a9380b
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions lib/ex_webrtc/dtls_transport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ defmodule ExWebRTC.DTLSTransport do
pkey: pkey,
fingerprint: fingerprint,
srtp: srtp,
dtls_state: :new
dtls_state: :new,
client: nil,
mode: nil
}

{:ok, state}
Expand All @@ -79,13 +81,8 @@ defmodule ExWebRTC.DTLSTransport do
end

@impl true
def handle_call({:start_dtls, _mode}, _from, %{client: _client} = state) do
# is there a case when mode will change and new handshake will be needed?
{:reply, {:error, :already_started}, state}
end

@impl true
def handle_call({:start_dtls, mode}, _from, state) when mode in [:active, :passive] do
def handle_call({:start_dtls, mode}, _from, %{client: nil} = state)
when mode in [:active, :passive] do
{:ok, client} =
ExDTLS.start_link(
client_mode: mode == :active,
Expand All @@ -94,14 +91,16 @@ defmodule ExWebRTC.DTLSTransport do
cert: state.cert
)

state =
state
|> Map.put(:client, client)
|> Map.put(:mode, mode)

state = %{state | client: client, mode: mode}
{:reply, :ok, state}
end

@impl true
def handle_call({:start_dtls, _mode}, _from, state) do
# is there a case when mode will change and new handshake will be needed?
{:reply, {:error, :already_started}, state}
end

@impl true
def handle_cast({:send_data, _data}, %{dtls_state: :connected, ice_state: ice_state} = state)
when ice_state in [:connected, :completed] do
Expand All @@ -111,7 +110,6 @@ defmodule ExWebRTC.DTLSTransport do

@impl true
def handle_cast({:send_data, _data}, state) do
# TODO: maybe this should be a call?
Logger.error(
"Attempted to send data when DTLS handshake was not finished or ICE Transport is unavailable"
)
Expand Down Expand Up @@ -184,7 +182,10 @@ defmodule ExWebRTC.DTLSTransport do
end

defp handle_ice({:data, _data}, state) do
Logger.warning("Received RTP/RTCP packets, but DTLS handshake hasn't been finished yet")
Logger.warning(
"Received RTP/RTCP packets, but DTLS handshake hasn't been finished yet. Ignoring."
)

state
end

Expand Down

0 comments on commit 3a9380b

Please sign in to comment.