SetRemoteDescription sets the SessionDescription of the remote peer nolint:gocognit,gocyclo,cyclop,maintidx
(desc SessionDescription)
| 1178 | // |
| 1179 | //nolint:gocognit,gocyclo,cyclop,maintidx |
| 1180 | func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error { |
| 1181 | if pc.isClosed.Load() { |
| 1182 | return &rtcerr.InvalidStateError{Err: ErrConnectionClosed} |
| 1183 | } |
| 1184 | |
| 1185 | isRenegotiation := pc.currentRemoteDescription != nil |
| 1186 | |
| 1187 | if _, err := desc.Unmarshal(); err != nil { |
| 1188 | return err |
| 1189 | } |
| 1190 | |
| 1191 | if err := pc.setDescription(&desc, stateChangeOpSetRemote); err != nil { |
| 1192 | return err |
| 1193 | } |
| 1194 | |
| 1195 | if err := pc.api.mediaEngine.updateFromRemoteDescription(*desc.parsed); err != nil { |
| 1196 | return err |
| 1197 | } |
| 1198 | |
| 1199 | canTrickle := hasICETrickleOption(desc.parsed) |
| 1200 | pc.mu.Lock() |
| 1201 | switch desc.Type { |
| 1202 | case SDPTypeOffer, SDPTypeAnswer, SDPTypePranswer: |
| 1203 | if canTrickle { |
| 1204 | pc.canTrickleICECandidates = ICETrickleCapabilitySupported |
| 1205 | } else { |
| 1206 | pc.canTrickleICECandidates = ICETrickleCapabilityUnsupported |
| 1207 | } |
| 1208 | default: |
| 1209 | pc.canTrickleICECandidates = ICETrickleCapabilityUnknown |
| 1210 | } |
| 1211 | pc.mu.Unlock() |
| 1212 | |
| 1213 | // Disable RTX/FEC on RTPSenders if the remote didn't support it |
| 1214 | for _, sender := range pc.GetSenders() { |
| 1215 | sender.configureRTXAndFEC() |
| 1216 | } |
| 1217 | |
| 1218 | var transceiver *RTPTransceiver |
| 1219 | localTransceivers := append([]*RTPTransceiver{}, pc.GetTransceivers()...) |
| 1220 | detectedPlanB := descriptionIsPlanB(pc.RemoteDescription(), pc.log) |
| 1221 | if pc.configuration.SDPSemantics != SDPSemanticsUnifiedPlan { |
| 1222 | detectedPlanB = descriptionPossiblyPlanB(pc.RemoteDescription()) |
| 1223 | } |
| 1224 | |
| 1225 | weOffer := desc.Type == SDPTypeAnswer |
| 1226 | |
| 1227 | if !weOffer && !detectedPlanB { //nolint:nestif |
| 1228 | for _, media := range pc.RemoteDescription().parsed.MediaDescriptions { |
| 1229 | midValue := getMidValue(media) |
| 1230 | if midValue == "" { |
| 1231 | return errPeerConnRemoteDescriptionWithoutMidValue |
| 1232 | } |
| 1233 | |
| 1234 | if media.MediaName.Media == mediaSectionApplication { |
| 1235 | continue |
| 1236 | } |
| 1237 |