-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API: Use ICECandidateInit in AddICECandidate
Resolves #358
- Loading branch information
Showing
3 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package webrtc | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestICECandidateInit_Serialization(t *testing.T) { | ||
tt := []struct { | ||
candidate ICECandidateInit | ||
serialized string | ||
}{ | ||
{ICECandidateInit{ | ||
Candidate: "candidate:abc123", | ||
SDPMid: refString("0"), | ||
SDPMLineIndex: refUint16(0), | ||
UsernameFragment: "def", | ||
}, `{"candidate":"candidate:abc123","sdpMid":"0","sdpMLineIndex":0,"usernameFragment":"def"}`}, | ||
{ICECandidateInit{ | ||
Candidate: "candidate:abc123", | ||
UsernameFragment: "def", | ||
}, `{"candidate":"candidate:abc123","usernameFragment":"def"}`}, | ||
} | ||
|
||
for i, tc := range tt { | ||
b, err := json.Marshal(tc.candidate) | ||
if err != nil { | ||
t.Errorf("Failed to marshal %d: %v", i, err) | ||
} | ||
actualSerialized := string(b) | ||
if actualSerialized != tc.serialized { | ||
t.Errorf("%d expected %s got %s", i, tc.serialized, actualSerialized) | ||
} | ||
|
||
var actual ICECandidateInit | ||
err = json.Unmarshal(b, &actual) | ||
if err != nil { | ||
t.Errorf("Failed to unmarshal %d: %v", i, err) | ||
} | ||
|
||
assert.Equal(t, tc.candidate, actual, "should match") | ||
} | ||
} | ||
|
||
func refString(s string) *string { | ||
return &s | ||
} | ||
|
||
func refUint16(i uint16) *uint16 { | ||
return &i | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters