Use constants (#875)

This commit is contained in:
Raja Subramanian
2022-08-06 00:15:00 +05:30
committed by GitHub
parent ab4d57ab5b
commit 4703e30047
2 changed files with 11 additions and 11 deletions
+2 -2
View File
@@ -695,7 +695,7 @@ func (t *PCTransport) filterCandidates(sd webrtc.SessionDescription) webrtc.Sess
filterAttributes := func(attrs []sdp.Attribute) []sdp.Attribute { filterAttributes := func(attrs []sdp.Attribute) []sdp.Attribute {
filteredAttrs := make([]sdp.Attribute, 0, len(attrs)) filteredAttrs := make([]sdp.Attribute, 0, len(attrs))
for _, a := range attrs { for _, a := range attrs {
if a.Key == "candidate" { if a.Key == sdp.AttrKeyCandidate {
if t.preferTCP { if t.preferTCP {
if strings.Contains(a.Value, "tcp") { if strings.Contains(a.Value, "tcp") {
filteredAttrs = append(filteredAttrs, a) filteredAttrs = append(filteredAttrs, a)
@@ -729,7 +729,7 @@ func (t *PCTransport) filterCandidates(sd webrtc.SessionDescription) webrtc.Sess
func getMidValue(media *sdp.MediaDescription) string { func getMidValue(media *sdp.MediaDescription) string {
for _, attr := range media.Attributes { for _, attr := range media.Attributes {
if attr.Key == "mid" { if attr.Key == sdp.AttrKeyMID {
return attr.Value return attr.Value
} }
} }
+9 -9
View File
@@ -314,18 +314,18 @@ func TestFilteringCandidates(t *testing.T) {
done := false done := false
for _, m := range parsed.MediaDescriptions { for _, m := range parsed.MediaDescriptions {
for _, a := range m.Attributes { for _, a := range m.Attributes {
if a.Key == "candidate" { if a.Key == sdp.AttrKeyCandidate {
for idx, aa := range m.Attributes { for idx, aa := range m.Attributes {
if aa.Key == "end-of-candidates" { if aa.Key == sdp.AttrKeyEndOfCandidates {
modifiedAttributes := make([]sdp.Attribute, idx) modifiedAttributes := make([]sdp.Attribute, idx)
copy(modifiedAttributes, m.Attributes[:idx]) copy(modifiedAttributes, m.Attributes[:idx])
modifiedAttributes = append(modifiedAttributes, []sdp.Attribute{ modifiedAttributes = append(modifiedAttributes, []sdp.Attribute{
{ {
Key: "candidate", Key: sdp.AttrKeyCandidate,
Value: "054225987 1 tcp 2124414975 159.203.70.248 7881 typ host tcptype passive", Value: "054225987 1 tcp 2124414975 159.203.70.248 7881 typ host tcptype passive",
}, },
{ {
Key: "candidate", Key: sdp.AttrKeyCandidate,
Value: "054225987 2 tcp 2124414975 159.203.70.248 7881 typ host tcptype passive", Value: "054225987 2 tcp 2124414975 159.203.70.248 7881 typ host tcptype passive",
}, },
}...) }...)
@@ -350,11 +350,11 @@ func TestFilteringCandidates(t *testing.T) {
parsed, err = offer.Unmarshal() parsed, err = offer.Unmarshal()
require.NoError(t, err) require.NoError(t, err)
getNumTransportTypeCandidates := func(sdp *sdp.SessionDescription) (int, int) { getNumTransportTypeCandidates := func(sd *sdp.SessionDescription) (int, int) {
numUDPCandidates := 0 numUDPCandidates := 0
numTCPCandidates := 0 numTCPCandidates := 0
for _, a := range sdp.Attributes { for _, a := range sd.Attributes {
if a.Key == "candidate" { if a.Key == sdp.AttrKeyCandidate {
if strings.Contains(a.Value, "udp") { if strings.Contains(a.Value, "udp") {
numUDPCandidates++ numUDPCandidates++
} }
@@ -363,9 +363,9 @@ func TestFilteringCandidates(t *testing.T) {
} }
} }
} }
for _, m := range sdp.MediaDescriptions { for _, m := range sd.MediaDescriptions {
for _, a := range m.Attributes { for _, a := range m.Attributes {
if a.Key == "candidate" { if a.Key == sdp.AttrKeyCandidate {
if strings.Contains(a.Value, "udp") { if strings.Contains(a.Value, "udp") {
numUDPCandidates++ numUDPCandidates++
} }