@@ -3,6 +3,8 @@ defmodule ExWebRTC.PeerConnectionTest do
33
44 alias ExWebRTC . { MediaStreamTrack , PeerConnection , SessionDescription , SDPUtils , Utils }
55
6+ alias ExSDP.Attribute.Extmap
7+
68 { _pkey , cert } = ExDTLS . generate_key_cert ( )
79
810 @ fingerprint cert
@@ -355,4 +357,43 @@ defmodule ExWebRTC.PeerConnectionTest do
355357
356358 assert_receive { :ex_webrtc , ^ pc2 , { :rtp , ^ id2 , % ExRTP.Packet { payload: ^ payload } } }
357359 end
360+
361+ test "updates rtp header extension ids" do
362+ # check wheter we update our RTP header extension ids
363+ # when we receive a remote offer with different ones
364+ { :ok , pc1 } = PeerConnection . start_link ( )
365+ { :ok , _ } = PeerConnection . add_transceiver ( pc1 , :audio )
366+ { :ok , offer } = PeerConnection . create_offer ( pc1 )
367+
368+ sdp = ExSDP . parse! ( offer . sdp )
369+
370+ # munge Extmap so that we use different id
371+ [ mline ] = sdp . media
372+
373+ extmaps =
374+ mline
375+ |> ExSDP . get_attributes ( Extmap )
376+ |> Enum . map ( fn extmap -> % { extmap | id: extmap . id + 1 } end )
377+
378+ mline =
379+ mline
380+ |> SDPUtils . delete_attribute ( Extmap )
381+ |> ExSDP . add_attributes ( extmaps )
382+
383+ sdp = % { sdp | media: [ mline ] }
384+
385+ offer = % SessionDescription { type: :offer , sdp: to_string ( sdp ) }
386+
387+ { :ok , pc2 } = PeerConnection . start_link ( )
388+ :ok = PeerConnection . set_remote_description ( pc2 , offer )
389+ { :ok , answer } = PeerConnection . create_answer ( pc2 )
390+ :ok = PeerConnection . set_local_description ( pc2 , answer )
391+
392+ { :ok , _ } = PeerConnection . add_transceiver ( pc2 , :audio )
393+ { :ok , offer } = PeerConnection . create_offer ( pc2 )
394+
395+ [ audio1 , audio2 ] = ExSDP . parse! ( offer . sdp ) . media
396+
397+ assert ExSDP . get_attributes ( audio1 , Extmap ) == ExSDP . get_attributes ( audio2 , Extmap )
398+ end
358399end
0 commit comments