Skip to content

Commit

Permalink
Don't use omitempty for ICECandidateInit
Browse files Browse the repository at this point in the history
Always return sdpMid & sdpMLineindex value if it
is null. The W3C starts every attribute definition with
`If not null ...`
  • Loading branch information
DevRockstarZ authored and Sean-Der committed Aug 21, 2020
1 parent cdc7262 commit 6d3633e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions icecandidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}
3 changes: 2 additions & 1 deletion icecandidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions icecandidateinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
7 changes: 3 additions & 4 deletions icecandidateinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6d3633e

Please sign in to comment.