@@ -847,7 +847,29 @@ func (pc *PeerConnection) CreateAnswer(*AnswerOptions) (SessionDescription, erro
847
847
if err != nil {
848
848
return SessionDescription {}, err
849
849
}
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 )
851
873
desc := SessionDescription {
852
874
Type : SDPTypeAnswer ,
853
875
SDP : string (sdpBytes ),
@@ -2264,6 +2286,31 @@ func (pc *PeerConnection) addRTPTransceiver(t *RTPTransceiver) {
2264
2286
pc .onNegotiationNeeded ()
2265
2287
}
2266
2288
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
+
2267
2314
// CurrentLocalDescription represents the local description that was
2268
2315
// successfully negotiated the last time the PeerConnection transitioned
2269
2316
// into the stable state plus any local candidates that have been generated
@@ -2628,7 +2675,16 @@ func (pc *PeerConnection) generateMatchedSDP(transceivers []*RTPTransceiver, use
2628
2675
mediaTransceivers := []* RTPTransceiver {t }
2629
2676
2630
2677
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 })
2632
2688
}
2633
2689
}
2634
2690
0 commit comments