diff --git a/lib/ex_webrtc/sdp_utils.ex b/lib/ex_webrtc/sdp_utils.ex index 96b15dc..907b0b7 100644 --- a/lib/ex_webrtc/sdp_utils.ex +++ b/lib/ex_webrtc/sdp_utils.ex @@ -129,9 +129,21 @@ defmodule ExWebRTC.SDPUtils do @spec add_ice_candidates(ExSDP.t(), [String.t()]) :: ExSDP.t() def add_ice_candidates(sdp, candidates) do + # we only add candidates to the first mline + # as we don't support bundle-policies other than "max-bundle" candidates = Enum.map(candidates, &{"candidate", &1}) - media = Enum.map(sdp.media, &ExSDP.add_attributes(&1, candidates)) - %ExSDP{sdp | media: media} + + if sdp.media != [] do + mline = + sdp.media + |> List.first() + |> ExSDP.add_attribute(candidates) + + media = List.replace_at(sdp.media, 0, mline) + %ExSDP{sdp | media: media} + else + sdp + end end @spec get_dtls_role(ExSDP.t()) ::