Don't use omitempty for ICECandidateInit

Always return sdpMid & sdpMLineindex value if it
is null. The W3C starts every attribute definition with
`If not null ...`
This commit is contained in:
JooYoung 2020-08-19 17:48:39 +09:00 committed by Sean DuBois
parent cdc726201b
commit 6d3633e589
5 changed files with 10 additions and 12 deletions

View File

@ -185,7 +185,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
* [Sam Lancia](https://github.com/nerd2)
* [Henry](https://github.com/cryptix)
* [Jeff Tchang](https://github.com/tachang)
* [JooYoung](https://github.com/DevRockstarZ)
* [JooYoung Lim](https://github.com/DevRockstarZ)
* [Sidney San Martín](https://github.com/s4y)
* [soolaugust](https://github.com/soolaugust)
* [Kuzmin Vladimir](https://github.com/tekig)

View File

@ -203,9 +203,7 @@ func newICECandidateFromSDP(c sdp.ICECandidate) (ICECandidate, error) {
// ToJSON returns an ICECandidateInit
// as indicated by the spec https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-tojson
func (c ICECandidate) ToJSON() ICECandidateInit {
var sdpmLineIndex uint16
return ICECandidateInit{
Candidate: fmt.Sprintf("candidate:%s", iceCandidateToSDP(c).Marshal()),
SDPMLineIndex: &sdpmLineIndex,
Candidate: fmt.Sprintf("candidate:%s", iceCandidateToSDP(c).Marshal()),
}
}

View File

@ -215,6 +215,7 @@ func TestICECandidate_ToJSON(t *testing.T) {
candidateInit := candidate.ToJSON()
assert.Equal(t, uint16(0), *candidateInit.SDPMLineIndex)
var nilUint16Ptr *uint16
assert.Equal(t, nilUint16Ptr, candidateInit.SDPMLineIndex)
assert.Equal(t, "candidate:foundation 1 udp 128 1.0.0.1 1234 typ host", candidateInit.Candidate)
}

View File

@ -3,7 +3,7 @@ package webrtc
// ICECandidateInit is used to serialize ice candidates
type ICECandidateInit struct {
Candidate string `json:"candidate"`
SDPMid *string `json:"sdpMid,omitempty"`
SDPMLineIndex *uint16 `json:"sdpMLineIndex,omitempty"`
UsernameFragment string `json:"usernameFragment"`
SDPMid *string `json:"sdpMid"`
SDPMLineIndex *uint16 `json:"sdpMLineIndex"`
UsernameFragment *string `json:"usernameFragment"`
}

View File

@ -16,12 +16,11 @@ func TestICECandidateInit_Serialization(t *testing.T) {
Candidate: "candidate:abc123",
SDPMid: refString("0"),
SDPMLineIndex: refUint16(0),
UsernameFragment: "def",
UsernameFragment: refString("def"),
}, `{"candidate":"candidate:abc123","sdpMid":"0","sdpMLineIndex":0,"usernameFragment":"def"}`},
{ICECandidateInit{
Candidate: "candidate:abc123",
UsernameFragment: "def",
}, `{"candidate":"candidate:abc123","usernameFragment":"def"}`},
Candidate: "candidate:abc123",
}, `{"candidate":"candidate:abc123","sdpMid":null,"sdpMLineIndex":null,"usernameFragment":null}`},
}
for i, tc := range tt {