Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Oct 18, 2023
1 parent 0e615c5 commit 4f6f3ff
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/ex_webrtc/peer_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,23 @@ defmodule ExWebRTC.PeerConnection do
defp apply_remote_description(_type, sdp, state) do
# TODO apply steps listed in RFC 8829 5.10
media = hd(sdp.media)
{:ice_ufrag, ufrag} = ExSDP.Media.get_attribute(media, :ice_ufrag)
{:ice_pwd, pwd} = ExSDP.Media.get_attribute(media, :ice_pwd)

:ok = ICEAgent.set_remote_credentials(state.ice_agent, ufrag, pwd)
:ok = ICEAgent.gather_candidates(state.ice_agent)
with {:ice_ufrag, ufrag} <- ExSDP.Media.get_attribute(media, :ice_ufrag),
{:ice_pwd, pwd} <- ExSDP.Media.get_attribute(media, :ice_pwd),
{:ok, transceivers} <- get_transceivers(sdp, state) do
:ok = ICEAgent.set_remote_credentials(state.ice_agent, ufrag, pwd)
:ok = ICEAgent.gather_candidates(state.ice_agent)

transceivers = Map.merge(transceivers, state.transceivers)
{:ok, %{state | current_remote_desc: sdp, transceivers: transceivers}}
else
nil -> {:error, :missing_ice_ufrag_or_pwd}
end
end

defp get_transceivers(sdp, state) do
transceivers =

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

View workflow job for this annotation

GitHub Actions / Test (OTP 26 / Elixir 1.15)

variable "transceivers" is unused (if the variable is not meant to be used, prefix it with an underscore)
sdp.media
|> Enum.reduce(%{}, fn media ->
Enum.reduce_while(sdp.media, %{}, fn media, transceivers ->

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

View workflow job for this annotation

GitHub Actions / Test (OTP 26 / Elixir 1.15)

variable "transceivers" is unused (if the variable is not meant to be used, prefix it with an underscore)
{:mid, mid} = ExSDP.Media.get_attribute(media, :mid)
# if there is no direction, the default is sendrecv
# see RFC 3264, sec. 6.1
Expand All @@ -320,17 +328,15 @@ defmodule ExWebRTC.PeerConnection do

{tr.mid, tr}
end)
|> Map.merge(state.transceivers)

{:ok, %{state | current_remote_desc: sdp, transceivers: transceivers}}
end

defp find_or_create_transceiver(mid, direction, transceivers)
when direction in [:sendrecv, :recvonly] do
Enum.find(transceivers, %RTPTransceiver{mid: mid, direction: :recvonly}, fn
{nil, tr} when tr.direction == direction -> tr
_other -> nil
Enum.find(transceivers, {nil, %RTPTransceiver{mid: mid, direction: :recvonly}}, fn
{nil, tr} -> tr.direction == direction
_other -> false
end)
|> elem(1)
end

defp find_or_create_transceiver(mid, :sendonly, _transceivers) do
Expand Down

0 comments on commit 4f6f3ff

Please sign in to comment.