Skip to content

Commit

Permalink
Implement next_mid function
Browse files Browse the repository at this point in the history
  • Loading branch information
LVala committed Oct 25, 2023
1 parent 1a111b0 commit 5be24c4
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions lib/ex_webrtc/peer_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ defmodule ExWebRTC.PeerConnection do
# we need to asign unique mid values for the transceivers
# in this case internal counter is used

# TODO: set counter so its greater than any mid in remote description or own transcevers mids
next_mid = find_next_mid(state.next_mid)
next_mid = find_next_mid(state)
{transceivers, next_mid} = assign_mids(state.transceivers, next_mid)

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L142-L143

Added lines #L142 - L143 were not covered by tests

{:ok, ice_ufrag, ice_pwd} = ICEAgent.get_local_credentials(state.ice_agent)
Expand Down Expand Up @@ -452,9 +451,28 @@ defmodule ExWebRTC.PeerConnection do
assign_mids(rest, next_mid, [transceiver | acc])

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L451

Added line #L451 was not covered by tests
end

defp find_next_mid(next_mid) do
# TODO: implement
next_mid
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
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
[]
else
for mline <- state.current_remote_desc.media,
{:mid, mid} <- ExSDP.Media.get_attribute(mline, :mid),
{mid, _} <- Integer.parse(mid) do

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L461-L463

Added lines #L461 - L463 were not covered by tests
mid
end
end

tsc_mids =
for %RTPTransceiver{mid: mid} when mid != nil <- state.transceivers,
{mid, _} <- Integer.parse(mid) do

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L468-L470

Added lines #L468 - L470 were not covered by tests
mid
end

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

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

View check run for this annotation

Codecov / codecov/patch

lib/ex_webrtc/peer_connection.ex#L474-L475

Added lines #L474 - L475 were not covered by tests
end

defp check_desc_altered(:offer, sdp, %{last_offer: offer}) when sdp == offer, do: :ok
Expand Down

0 comments on commit 5be24c4

Please sign in to comment.