@@ -651,6 +651,59 @@ defmodule ExWebRTC.PeerConnectionTest do
651651 assert sdp . media == [ ]
652652 end
653653
654+ test "after remote offer" do
655+ { :ok , pc1 } = PeerConnection . start_link ( )
656+ { :ok , pc2 } = PeerConnection . start_link ( )
657+
658+ PeerConnection . add_transceiver ( pc1 , :video )
659+ { :ok , offer } = PeerConnection . create_offer ( pc1 )
660+ :ok = PeerConnection . set_local_description ( pc1 , offer )
661+
662+ :ok = PeerConnection . set_remote_description ( pc2 , offer )
663+ [ tr ] = PeerConnection . get_transceivers ( pc2 )
664+ :ok = PeerConnection . stop_transceiver ( pc2 , tr . id )
665+
666+ assert [
667+ % RTPTransceiver {
668+ current_direction: nil ,
669+ direction: :inactive ,
670+ stopping: true ,
671+ stopped: false
672+ }
673+ ] = PeerConnection . get_transceivers ( pc2 )
674+
675+ { :ok , answer } = PeerConnection . create_answer ( pc2 )
676+ [ video ] = ExSDP . parse! ( answer . sdp ) . media
677+ assert video . port == 9
678+
679+ :ok = PeerConnection . set_local_description ( pc2 , answer )
680+ :ok = PeerConnection . set_remote_description ( pc1 , answer )
681+
682+ assert_receive { :ex_webrtc , ^ pc2 , :negotiation_needed }
683+
684+ # Ensure transceiver is removed after renegotiation
685+
686+ { :ok , offer2 } = PeerConnection . create_offer ( pc2 )
687+ :ok = PeerConnection . set_local_description ( pc2 , offer2 )
688+ [ new_video ] = ExSDP . parse! ( offer2 . sdp ) . media
689+ assert new_video . port == 0
690+
691+ assert [
692+ % RTPTransceiver {
693+ current_direction: :inactive ,
694+ direction: :inactive ,
695+ stopping: true ,
696+ stopped: false
697+ }
698+ ] = PeerConnection . get_transceivers ( pc2 )
699+
700+ :ok = PeerConnection . set_remote_description ( pc1 , offer2 )
701+ { :ok , answer2 } = PeerConnection . create_answer ( pc1 )
702+
703+ :ok = PeerConnection . set_remote_description ( pc2 , answer2 )
704+ assert [ ] = PeerConnection . get_transceivers ( pc2 )
705+ end
706+
654707 test "with renegotiation" do
655708 { :ok , pc1 } = PeerConnection . start_link ( )
656709 { :ok , pc2 } = PeerConnection . start_link ( )
0 commit comments