SetLocalDescription sets the SessionDescription of the local peer nolint:cyclop
(desc SessionDescription)
| 1105 | // |
| 1106 | //nolint:cyclop |
| 1107 | func (pc *PeerConnection) SetLocalDescription(desc SessionDescription) error { |
| 1108 | if pc.isClosed.Load() { |
| 1109 | return &rtcerr.InvalidStateError{Err: ErrConnectionClosed} |
| 1110 | } |
| 1111 | |
| 1112 | haveLocalDescription := pc.currentLocalDescription != nil |
| 1113 | |
| 1114 | // JSEP 5.4 |
| 1115 | if desc.SDP == "" { |
| 1116 | switch desc.Type { |
| 1117 | case SDPTypeAnswer, SDPTypePranswer: |
| 1118 | desc.SDP = pc.lastAnswer |
| 1119 | case SDPTypeOffer: |
| 1120 | desc.SDP = pc.lastOffer |
| 1121 | default: |
| 1122 | return &rtcerr.InvalidModificationError{ |
| 1123 | Err: fmt.Errorf("%w: %s", errPeerConnSDPTypeInvalidValueSetLocalDescription, desc.Type), |
| 1124 | } |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | desc.parsed = &sdp.SessionDescription{} |
| 1129 | if err := desc.parsed.UnmarshalString(desc.SDP); err != nil { |
| 1130 | return err |
| 1131 | } |
| 1132 | if err := pc.setDescription(&desc, stateChangeOpSetLocal); err != nil { |
| 1133 | return err |
| 1134 | } |
| 1135 | |
| 1136 | currentTransceivers := append([]*RTPTransceiver{}, pc.GetTransceivers()...) |
| 1137 | |
| 1138 | weAnswer := desc.Type == SDPTypeAnswer |
| 1139 | remoteDesc := pc.RemoteDescription() |
| 1140 | if weAnswer && remoteDesc != nil { |
| 1141 | _ = setRTPTransceiverCurrentDirection(&desc, currentTransceivers, false) |
| 1142 | if err := pc.startRTPSenders(currentTransceivers); err != nil { |
| 1143 | return err |
| 1144 | } |
| 1145 | pc.configureRTPReceivers(haveLocalDescription, remoteDesc, currentTransceivers) |
| 1146 | pc.ops.Enqueue(func() { |
| 1147 | pc.startRTP(haveLocalDescription, remoteDesc, currentTransceivers) |
| 1148 | }) |
| 1149 | } |
| 1150 | |
| 1151 | mediaSection, ok := selectCandidateMediaSection(desc.parsed) |
| 1152 | if ok { |
| 1153 | pc.iceGatherer.setMediaStreamIdentification(mediaSection.SDPMid, mediaSection.SDPMLineIndex) |
| 1154 | } |
| 1155 | |
| 1156 | pc.iceGatherer.flushCandidates() |
| 1157 | |
| 1158 | if pc.iceGatherer.State() == ICEGathererStateNew { |
| 1159 | return pc.iceGatherer.Gather() |
| 1160 | } |
| 1161 | |
| 1162 | return nil |
| 1163 | } |
| 1164 |