@@ -847,7 +847,29 @@ func (pc *PeerConnection) CreateAnswer(*AnswerOptions) (SessionDescription, erro
847847 if err != nil {
848848 return SessionDescription {}, err
849849 }
850-
850+ // remove inactive media sections
851+ var inactiveMidValue []string
852+ for _ , media := range d .MediaDescriptions {
853+ if media .MediaName .Media == mediaSectionApplication {
854+ continue
855+ }
856+ if media .MediaName .Port .Value == 0 {
857+ var midValue string
858+ var inactive bool
859+ for _ , attr := range media .Attributes {
860+ if attr .Key == sdp .AttrKeyInactive {
861+ inactive = true
862+ }
863+ if attr .Key == sdp .AttrKeyMID {
864+ midValue = attr .Value
865+ }
866+ }
867+ if inactive {
868+ inactiveMidValue = append (inactiveMidValue , midValue )
869+ }
870+ }
871+ }
872+ pc .removeRTPTransceiver (inactiveMidValue )
851873 desc := SessionDescription {
852874 Type : SDPTypeAnswer ,
853875 SDP : string (sdpBytes ),
@@ -2264,6 +2286,31 @@ func (pc *PeerConnection) addRTPTransceiver(t *RTPTransceiver) {
22642286 pc .onNegotiationNeeded ()
22652287}
22662288
2289+ // removeRTPTransceiver remove inactive
2290+ // and fires onNegotiationNeeded;
2291+ // caller of this method should hold `pc.mu` lock
2292+ func (pc * PeerConnection ) removeRTPTransceiver (mids []string ) {
2293+ if len (mids ) == 0 {
2294+ return
2295+ }
2296+ n := 0
2297+ for _ , transceiver := range pc .rtpTransceivers {
2298+ needDelete := false
2299+ for _ , mid := range mids {
2300+ if transceiver .Mid () == mid {
2301+ transceiver .Stop ()
2302+ needDelete = true
2303+ }
2304+ }
2305+ if ! needDelete {
2306+ pc .rtpTransceivers [n ] = transceiver
2307+ n ++
2308+ }
2309+ }
2310+ pc .rtpTransceivers = pc .rtpTransceivers [:n ]
2311+ pc .onNegotiationNeeded ()
2312+ }
2313+
22672314// CurrentLocalDescription represents the local description that was
22682315// successfully negotiated the last time the PeerConnection transitioned
22692316// into the stable state plus any local candidates that have been generated
@@ -2628,7 +2675,16 @@ func (pc *PeerConnection) generateMatchedSDP(transceivers []*RTPTransceiver, use
26282675 mediaTransceivers := []* RTPTransceiver {t }
26292676
26302677 extensions , _ := rtpExtensionsFromMediaDescription (media )
2631- mediaSections = append (mediaSections , mediaSection {id : midValue , transceivers : mediaTransceivers , matchExtensions : extensions , rids : getRids (media )})
2678+ rejected := false
2679+ if media .MediaName .Port .Value == 0 {
2680+ for _ , attr := range media .Attributes {
2681+ if attr .Key == sdp .AttrKeyInactive {
2682+ rejected = true
2683+ break
2684+ }
2685+ }
2686+ }
2687+ mediaSections = append (mediaSections , mediaSection {id : midValue , transceivers : mediaTransceivers , matchExtensions : extensions , rids : getRids (media ), rejected : rejected })
26322688 }
26332689 }
26342690
0 commit comments