mirror of
https://github.com/pion/webrtc.git
synced 2025-11-02 19:44:01 +08:00
Split ICE and DTLS related SDP parsing out
Move this stuff out of SetRemoteDescription so it will be easier to test Relates to #1023
This commit is contained in:
67
sdp.go
67
sdp.go
@@ -265,3 +265,70 @@ func getPeerDirection(media *sdp.MediaDescription) RTPTransceiverDirection {
|
||||
}
|
||||
return RTPTransceiverDirection(Unknown)
|
||||
}
|
||||
|
||||
func extractFingerprint(desc *sdp.SessionDescription) (string, string, error) {
|
||||
fingerprints := []string{}
|
||||
|
||||
if fingerprint, haveFingerprint := desc.Attribute("fingerprint"); haveFingerprint {
|
||||
fingerprints = append(fingerprints, fingerprint)
|
||||
}
|
||||
|
||||
for _, m := range desc.MediaDescriptions {
|
||||
if fingerprint, haveFingerprint := m.Attribute("fingerprint"); haveFingerprint {
|
||||
fingerprints = append(fingerprints, fingerprint)
|
||||
}
|
||||
}
|
||||
|
||||
if len(fingerprints) < 1 {
|
||||
return "", "", ErrSessionDescriptionNoFingerprint
|
||||
}
|
||||
|
||||
for _, m := range fingerprints {
|
||||
if m != fingerprints[0] {
|
||||
return "", "", ErrSessionDescriptionConflictingFingerprints
|
||||
}
|
||||
}
|
||||
|
||||
parts := strings.Split(fingerprints[0], " ")
|
||||
if len(parts) != 2 {
|
||||
return "", "", ErrSessionDescriptionInvalidFingerprint
|
||||
}
|
||||
return parts[1], parts[0], nil
|
||||
}
|
||||
|
||||
func extractICEDetails(desc *sdp.SessionDescription) (string, string, []ICECandidate, error) {
|
||||
candidates := []ICECandidate{}
|
||||
remotePwd := ""
|
||||
remoteUfrag := ""
|
||||
|
||||
for _, m := range desc.MediaDescriptions {
|
||||
for _, a := range m.Attributes {
|
||||
switch {
|
||||
case a.IsICECandidate():
|
||||
sdpCandidate, err := a.ToICECandidate()
|
||||
if err != nil {
|
||||
return "", "", nil, err
|
||||
}
|
||||
|
||||
candidate, err := newICECandidateFromSDP(sdpCandidate)
|
||||
if err != nil {
|
||||
return "", "", nil, err
|
||||
}
|
||||
|
||||
candidates = append(candidates, candidate)
|
||||
case strings.HasPrefix(*a.String(), "ice-ufrag"):
|
||||
remoteUfrag = (*a.String())[len("ice-ufrag:"):]
|
||||
case strings.HasPrefix(*a.String(), "ice-pwd"):
|
||||
remotePwd = (*a.String())[len("ice-pwd:"):]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if remoteUfrag == "" {
|
||||
return "", "", nil, ErrSessionDescriptionMissingIceUfrag
|
||||
} else if remotePwd == "" {
|
||||
return "", "", nil, ErrSessionDescriptionMissingIcePwd
|
||||
}
|
||||
|
||||
return remoteUfrag, remotePwd, candidates, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user