mirror of
https://github.com/pion/webrtc.git
synced 2025-09-27 19:42:19 +08:00
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:
@@ -185,7 +185,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
|
|||||||
* [Sam Lancia](https://github.com/nerd2)
|
* [Sam Lancia](https://github.com/nerd2)
|
||||||
* [Henry](https://github.com/cryptix)
|
* [Henry](https://github.com/cryptix)
|
||||||
* [Jeff Tchang](https://github.com/tachang)
|
* [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)
|
* [Sidney San Martín](https://github.com/s4y)
|
||||||
* [soolaugust](https://github.com/soolaugust)
|
* [soolaugust](https://github.com/soolaugust)
|
||||||
* [Kuzmin Vladimir](https://github.com/tekig)
|
* [Kuzmin Vladimir](https://github.com/tekig)
|
||||||
|
@@ -203,9 +203,7 @@ func newICECandidateFromSDP(c sdp.ICECandidate) (ICECandidate, error) {
|
|||||||
// ToJSON returns an ICECandidateInit
|
// ToJSON returns an ICECandidateInit
|
||||||
// as indicated by the spec https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-tojson
|
// as indicated by the spec https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-tojson
|
||||||
func (c ICECandidate) ToJSON() ICECandidateInit {
|
func (c ICECandidate) ToJSON() ICECandidateInit {
|
||||||
var sdpmLineIndex uint16
|
|
||||||
return ICECandidateInit{
|
return ICECandidateInit{
|
||||||
Candidate: fmt.Sprintf("candidate:%s", iceCandidateToSDP(c).Marshal()),
|
Candidate: fmt.Sprintf("candidate:%s", iceCandidateToSDP(c).Marshal()),
|
||||||
SDPMLineIndex: &sdpmLineIndex,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -215,6 +215,7 @@ func TestICECandidate_ToJSON(t *testing.T) {
|
|||||||
|
|
||||||
candidateInit := candidate.ToJSON()
|
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)
|
assert.Equal(t, "candidate:foundation 1 udp 128 1.0.0.1 1234 typ host", candidateInit.Candidate)
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@ package webrtc
|
|||||||
// ICECandidateInit is used to serialize ice candidates
|
// ICECandidateInit is used to serialize ice candidates
|
||||||
type ICECandidateInit struct {
|
type ICECandidateInit struct {
|
||||||
Candidate string `json:"candidate"`
|
Candidate string `json:"candidate"`
|
||||||
SDPMid *string `json:"sdpMid,omitempty"`
|
SDPMid *string `json:"sdpMid"`
|
||||||
SDPMLineIndex *uint16 `json:"sdpMLineIndex,omitempty"`
|
SDPMLineIndex *uint16 `json:"sdpMLineIndex"`
|
||||||
UsernameFragment string `json:"usernameFragment"`
|
UsernameFragment *string `json:"usernameFragment"`
|
||||||
}
|
}
|
||||||
|
@@ -16,12 +16,11 @@ func TestICECandidateInit_Serialization(t *testing.T) {
|
|||||||
Candidate: "candidate:abc123",
|
Candidate: "candidate:abc123",
|
||||||
SDPMid: refString("0"),
|
SDPMid: refString("0"),
|
||||||
SDPMLineIndex: refUint16(0),
|
SDPMLineIndex: refUint16(0),
|
||||||
UsernameFragment: "def",
|
UsernameFragment: refString("def"),
|
||||||
}, `{"candidate":"candidate:abc123","sdpMid":"0","sdpMLineIndex":0,"usernameFragment":"def"}`},
|
}, `{"candidate":"candidate:abc123","sdpMid":"0","sdpMLineIndex":0,"usernameFragment":"def"}`},
|
||||||
{ICECandidateInit{
|
{ICECandidateInit{
|
||||||
Candidate: "candidate:abc123",
|
Candidate: "candidate:abc123",
|
||||||
UsernameFragment: "def",
|
}, `{"candidate":"candidate:abc123","sdpMid":null,"sdpMLineIndex":null,"usernameFragment":null}`},
|
||||||
}, `{"candidate":"candidate:abc123","usernameFragment":"def"}`},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range tt {
|
for i, tc := range tt {
|
||||||
|
Reference in New Issue
Block a user