Skip to content

Commit

Permalink
Apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LVala committed Oct 27, 2023
1 parent 5be24c4 commit cb5c805
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
11 changes: 5 additions & 6 deletions lib/ex_webrtc/peer_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ defmodule ExWebRTC.PeerConnection do
dtls_finished: false,
transceivers: [],
signaling_state: :stable,
next_mid: 0,
last_offer: nil,
last_answer: nil
]
Expand Down Expand Up @@ -140,7 +139,7 @@ defmodule ExWebRTC.PeerConnection do
# in this case internal counter is used

next_mid = find_next_mid(state)
{transceivers, next_mid} = assign_mids(state.transceivers, next_mid)
transceivers = assign_mids(state.transceivers, next_mid)

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L141-L142

Added lines #L141 - L142 were not covered by tests

{:ok, ice_ufrag, ice_pwd} = ICEAgent.get_local_credentials(state.ice_agent)
{:ok, dtls_fingerprint} = ExDTLS.get_cert_fingerprint(state.dtls_client)

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L144-L145

Added lines #L144 - L145 were not covered by tests
Expand Down Expand Up @@ -180,7 +179,7 @@ defmodule ExWebRTC.PeerConnection do

sdp = to_string(offer)
desc = %SessionDescription{type: :offer, sdp: sdp}
state = %{state | next_mid: next_mid, last_offer: sdp}
state = %{state | last_offer: sdp}

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L180-L182

Added lines #L180 - L182 were not covered by tests

{:reply, {:ok, desc}, state}

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L184

Added line #L184 was not covered by tests
end
Expand Down Expand Up @@ -440,7 +439,7 @@ defmodule ExWebRTC.PeerConnection do
end

defp assign_mids(transceivers, next_mid, acc \\ [])
defp assign_mids([], next_mid, acc), do: {Enum.reverse(acc), next_mid}
defp assign_mids([], _next_mid, acc), do: Enum.reverse(acc)

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L441-L442

Added lines #L441 - L442 were not covered by tests

defp assign_mids([transceiver | rest], next_mid, acc) when is_nil(transceiver.mid) do
transceiver = %RTPTransceiver{transceiver | mid: Integer.to_string(next_mid)}
Expand All @@ -454,6 +453,7 @@ defmodule ExWebRTC.PeerConnection do
defp find_next_mid(state) do
# next mid must be unique, it's acomplished by looking for values
# greater than any mid in remote description or our own transceivers
# should we keep track of next_mid in the state?
crd_mids =
if is_nil(state.current_remote_desc) do

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L457-L458

Added lines #L457 - L458 were not covered by tests
[]
Expand All @@ -471,8 +471,7 @@ defmodule ExWebRTC.PeerConnection do
mid
end

max_mid = Enum.max(crd_mids ++ tsc_mids, &>=/2, fn -> -1 end) + 1
max(state.next_mid, max_mid + 1)
Enum.max(crd_mids ++ tsc_mids, &>=/2, fn -> -1 end) + 1

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L474

Added line #L474 was not covered by tests
end

defp check_desc_altered(:offer, sdp, %{last_offer: offer}) when sdp == offer, do: :ok
Expand Down
21 changes: 11 additions & 10 deletions lib/ex_webrtc/rtp_transceiver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ defmodule ExWebRTC.RTPTransceiver do
end)

attributes =
[
transceiver.direction,
{:mid, transceiver.mid},
{:ice_ufrag, Keyword.fetch!(config, :ice_ufrag)},
{:ice_pwd, Keyword.fetch!(config, :ice_pwd)},
{:ice_options, Keyword.fetch!(config, :ice_options)},
{:fingerprint, Keyword.fetch!(config, :fingerprint)},
{:setup, Keyword.fetch!(config, :setup)},
:rtcp_mux
] ++ if(Keyword.get(config, :rtcp, false), do: [{"rtcp", "9 IN IP4 0.0.0.0"}], else: [])
if(Keyword.get(config, :rtcp, false), do: [{"rtcp", "9 IN IP4 0.0.0.0"}], else: []) ++

Check warning on line 76 in lib/ex_webrtc/rtp_transceiver.ex

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/rtp_transceiver.ex#L75-L76

Added lines #L75 - L76 were not covered by tests
[
transceiver.direction,
{:mid, transceiver.mid},

Check warning on line 79 in lib/ex_webrtc/rtp_transceiver.ex

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/rtp_transceiver.ex#L78-L79

Added lines #L78 - L79 were not covered by tests
{:ice_ufrag, Keyword.fetch!(config, :ice_ufrag)},
{:ice_pwd, Keyword.fetch!(config, :ice_pwd)},
{:ice_options, Keyword.fetch!(config, :ice_options)},
{:fingerprint, Keyword.fetch!(config, :fingerprint)},
{:setup, Keyword.fetch!(config, :setup)},
:rtcp_mux
]

%ExSDP.Media{
ExSDP.Media.new(transceiver.kind, 9, "UDP/TLS/RTP/SAVPF", pt)
Expand Down

0 comments on commit cb5c805

Please sign in to comment.