Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WASM: Fallback to SDP line for candiate callback
On Firefox, the RTCIceCandidate interface appears to just be an RTCIceCandidateInit in disguise. That is, it does not have properties for each individual component of the candidate line. It only has the raw SDP string in the candidate property. This change falls back to parsing the candidate line if some expected property is missing when preparing the candidate for the callback OnICECandidate. https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate https://caniuse.com/#feat=mdn-api_rtcicecandidate_priority
- Loading branch information
Showing
5 changed files
with
106 additions
and
24 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
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
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
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
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,69 @@ | ||
package webrtc | ||
|
||
import ( | ||
"encoding/json" | ||
"syscall/js" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValueToICECandidate(t *testing.T) { | ||
testCases := []struct { | ||
jsonCandidate string | ||
expect ICECandidate | ||
}{ | ||
{ | ||
// Firefox-style ICECandidateInit: | ||
`{"candidate":"1966762133 1 udp 2122260222 192.168.20.128 47298 typ srflx raddr 203.0.113.1 rport 5000"}`, | ||
ICECandidate{ | ||
Foundation: "1966762133", | ||
Priority: 2122260222, | ||
Address: "192.168.20.128", | ||
Protocol: ICEProtocolUDP, | ||
Port: 47298, | ||
Typ: ICECandidateTypeSrflx, | ||
Component: 1, | ||
RelatedAddress: "203.0.113.1", | ||
RelatedPort: 5000, | ||
}, | ||
}, { | ||
// Chrome/Webkit-style ICECandidate: | ||
`{"foundation":"1966762134", "component":"rtp", "protocol":"udp", "priority":2122260223, "address":"192.168.20.129", "port":47299, "type":"host", "relatedAddress":null}`, | ||
ICECandidate{ | ||
Foundation: "1966762134", | ||
Priority: 2122260223, | ||
Address: "192.168.20.129", | ||
Protocol: ICEProtocolUDP, | ||
Port: 47299, | ||
Typ: ICECandidateTypeHost, | ||
Component: 1, | ||
RelatedAddress: "<null>", | ||
RelatedPort: 0, | ||
}, | ||
}, { | ||
// Both are present, Chrome/Webkit-style takes precedent: | ||
`{"candidate":"1966762133 1 udp 2122260222 192.168.20.128 47298 typ srflx raddr 203.0.113.1 rport 5000", "foundation":"1966762134", "component":"rtp", "protocol":"udp", "priority":2122260223, "address":"192.168.20.129", "port":47299, "type":"host", "relatedAddress":null}`, | ||
ICECandidate{ | ||
Foundation: "1966762134", | ||
Priority: 2122260223, | ||
Address: "192.168.20.129", | ||
Protocol: ICEProtocolUDP, | ||
Port: 47299, | ||
Typ: ICECandidateTypeHost, | ||
Component: 1, | ||
RelatedAddress: "<null>", | ||
RelatedPort: 0, | ||
}, | ||
}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
v := map[string]interface{}{} | ||
err := json.Unmarshal([]byte(testCase.jsonCandidate), &v) | ||
if err != nil { | ||
t.Errorf("Case %d: bad test, got error: %v", i, err) | ||
} | ||
assert.Equal(t, testCase.expect, *valueToICECandidate(js.ValueOf(v))) | ||
} | ||
} |