Bug 1263312 - Have addIceCandidate take a dictionary.
MozReview-Commit-ID: HuWYZkGS2Wg
--- a/dom/bindings/test/test_exceptions_from_jsimplemented.html
+++ b/dom/bindings/test/test_exceptions_from_jsimplemented.html
@@ -8,24 +8,24 @@ https://bugzilla.mozilla.org/show_bug.cg
<title>Test for Bug 923010</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 923010 **/
try {
var conn = new RTCPeerConnection();
- var candidate = new RTCIceCandidate({candidate: null });
+ var candidate = new RTCIceCandidate({candidate: "x" });
conn.addIceCandidate(candidate)
.then(function() {
ok(false, "addIceCandidate succeeded when it should have failed");
}, function(reason) {
is(reason.lineNumber, 17, "Rejection should have been on line 17");
is(reason.message,
- "Invalid candidate passed to addIceCandidate!",
+ "Invalid candidate (both sdpMid and sdpMLineIndex are null).",
"Should have the rejection we expect");
})
.catch(function(reason) {
ok(false, "unexpected error: " + reason);
});
} catch (e) {
// b2g has no WebRTC, apparently
todo(false, "No WebRTC on b2g yet");
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -972,22 +972,25 @@ RTCPeerConnection.prototype = {
}
let sections = desc.sdp.split(/(?:\r\n?|\n)m=/);
let topSection = sections.shift();
this._canTrickle =
containsTrickle(topSection) || sections.every(containsTrickle);
},
-
addIceCandidate: function(c, onSuccess, onError) {
return this._legacyCatchAndCloseGuard(onSuccess, onError, () => {
- if (!c.candidate && !c.sdpMLineIndex) {
- throw new this._win.DOMException("Invalid candidate passed to addIceCandidate!",
- "InvalidParameterError");
+ if (!c) {
+ // TODO: Implement processing for end-of-candidates (bug 1318167)
+ return Promise.resolve();
+ }
+ if (c.sdpMid === null && c.sdpMLineIndex === null) {
+ throw new this._win.DOMException("Invalid candidate (both sdpMid and sdpMLineIndex are null).",
+ "TypeError");
}
return this._chain(() => new this._win.Promise((resolve, reject) => {
this._onAddIceCandidateSuccess = resolve;
this._onAddIceCandidateError = reject;
this._impl.addIceCandidate(c.candidate, c.sdpMid || "", c.sdpMLineIndex);
}));
});
},
--- a/dom/media/tests/mochitest/test_peerConnection_addIceCandidate.html
+++ b/dom/media/tests/mochitest/test_peerConnection_addIceCandidate.html
@@ -49,55 +49,58 @@
return test.pcRemote._pc.addIceCandidate(bogus)
.then(
generateErrorCallback("addIceCandidate should have failed."),
err => {
is(err.name, "InvalidCandidateError", "Error is InvalidCandidateError");
}
);
},
- function PC_REMOTE_ADD_CANDIDATE_MISSING_INDEX(test) {
- // Note: it is probably not a good idea to automatically fill a missing
- // MLineIndex with a default value of zero, see bug 1157034
+ function PC_REMOTE_ADD_MISSING_MID_AND_MISSING_INDEX(test) {
var broken = new RTCIceCandidate(
{candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host"});
return test.pcRemote._pc.addIceCandidate(broken)
.then(
- // FIXME this needs to be updated once bug 1157034 is fixed
- todo(false, "Missing index in got automatically set to a valid value bz://1157034")
+ generateErrorCallback("addIceCandidate should have failed."),
+ err => {
+ is(err.name, "TypeError", "Error is TypeError");
+ }
);
},
function PC_REMOTE_ADD_VALID_CANDIDATE(test) {
var candidate = new RTCIceCandidate(
{candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
sdpMLineIndex: 0});
return test.pcRemote._pc.addIceCandidate(candidate)
- .then(ok(true, "Successfully added valid ICE candidate"));
+ .then(() => ok(true, "Successfully added valid ICE candidate"));
},
// bug 1095793
function PC_REMOTE_ADD_MISMATCHED_MID_AND_LEVEL_CANDIDATE(test) {
var bogus = new mozRTCIceCandidate(
{candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
sdpMLineIndex: 0,
sdpMid: "sdparta_1"});
return test.pcRemote._pc.addIceCandidate(bogus)
- .then(
- generateErrorCallback("addIceCandidate should have failed."),
- err => {
- is(err.name, "InvalidCandidateError", "Error is InvalidCandidateError");
- }
- );
+ .then(generateErrorCallback("addIceCandidate should have failed."),
+ err => is(err.name, "InvalidCandidateError", "Error is InvalidCandidateError"));
+ },
+ function PC_REMOTE_ADD_MID_AND_MISSING_INDEX(test) {
+ var candidate = new RTCIceCandidate(
+ {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
+ sdpMid: "sdparta_0"});
+ return test.pcRemote._pc.addIceCandidate(candidate)
+ .then(() => ok(true, "Successfully added valid ICE candidate"));
},
function PC_REMOTE_ADD_MATCHING_MID_AND_LEVEL_CANDIDATE(test) {
var candidate = new mozRTCIceCandidate(
{candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
sdpMLineIndex: 0,
sdpMid: "sdparta_0"});
return test.pcRemote._pc.addIceCandidate(candidate)
- .then(ok(true, "Successfully added valid ICE candidate with matching mid and level"));
+ .then(() => ok(true, "Successfully added valid ICE candidate with matching mid and level"));
}
]);
test.run();
});
</script>
</pre>
</body>
</html>
--- a/dom/webidl/RTCPeerConnection.webidl
+++ b/dom/webidl/RTCPeerConnection.webidl
@@ -84,17 +84,17 @@ interface RTCPeerConnection : EventTarge
Promise<DOMString> getIdentityAssertion();
Promise<RTCSessionDescription> createOffer (optional RTCOfferOptions options);
Promise<RTCSessionDescription> createAnswer (optional RTCAnswerOptions options);
Promise<void> setLocalDescription (RTCSessionDescription description);
Promise<void> setRemoteDescription (RTCSessionDescription description);
readonly attribute RTCSessionDescription? localDescription;
readonly attribute RTCSessionDescription? remoteDescription;
readonly attribute RTCSignalingState signalingState;
- Promise<void> addIceCandidate (RTCIceCandidate candidate);
+ Promise<void> addIceCandidate ((RTCIceCandidateInit or RTCIceCandidate)? candidate);
readonly attribute boolean? canTrickleIceCandidates;
readonly attribute RTCIceGatheringState iceGatheringState;
readonly attribute RTCIceConnectionState iceConnectionState;
[Pref="media.peerconnection.identity.enabled"]
readonly attribute Promise<RTCIdentityAssertion> peerIdentity;
[Pref="media.peerconnection.identity.enabled"]
readonly attribute DOMString? idpLoginUrl;