Bug 1322186 - Make RTCIceCandidate members readonly and add members parsed from candidate string. r=bwc,webidl,smaug

Differential Revision: https://phabricator.services.mozilla.com/D204089
This commit is contained in:
Jan-Ivar Bruaroey 2024-03-19 17:46:39 +00:00
Родитель 150e89d066
Коммит f7ac7716e6
7 изменённых файлов: 106 добавлений и 101 удалений

Просмотреть файл

@ -217,6 +217,51 @@ setupPrototype(GlobalPCList, {
var _globalPCList = new GlobalPCList();
// Parses grammar in RFC5245 section 15 and ICE TCP from RFC6544 section 4.5.
function parseCandidate(line) {
const match = line.match(
/^(a=)?candidate:([A-Za-z0-9+\/]{1,32}) (\d+) (UDP|TCP) (\d+) ([A-Za-z0-9.:-]+) (\d+) typ (host|srflx|prflx|relay)(?: raddr ([A-Za-z0-9.:-]+) rport (\d+))?(.*)$/i
);
if (!match) {
return null;
}
const candidate = {
foundation: match[2],
componentId: parseInt(match[3], 10),
transport: match[4],
priority: parseInt(match[5], 10),
address: match[6],
port: parseInt(match[7], 10),
type: match[8],
relatedAddress: match[9],
relatedPort: match[10],
};
if (candidate.componentId < 1 || candidate.componentId > 256) {
return null;
}
if (candidate.priority < 0 || candidate.priority > 4294967295) {
return null;
}
if (candidate.port < 0 || candidate.port > 65535) {
return null;
}
candidate.component = { 1: "rtp", 2: "rtcp" }[candidate.componentId] || null;
candidate.protocol =
{ udp: "udp", tcp: "tcp" }[candidate.transport.toLowerCase()] || null;
const tcpTypeMatch = match[11].match(/tcptype (\S+)/i);
if (tcpTypeMatch) {
candidate.tcpType = tcpTypeMatch[1];
if (
candidate.protocol != "tcp" ||
!["active", "passive", "so"].includes(candidate.tcpType)
) {
return null;
}
}
return candidate;
}
export class RTCIceCandidate {
init(win) {
this._win = win;
@ -229,6 +274,20 @@ export class RTCIceCandidate {
);
}
Object.assign(this, dict);
const candidate = parseCandidate(this.candidate);
if (!candidate) {
return;
}
Object.assign(this, candidate);
}
toJSON() {
return {
candidate: this.candidate,
sdpMid: this.sdpMid,
sdpMLineIndex: this.sdpMLineIndex,
usernameFragment: this.usernameFragment,
};
}
}

Просмотреть файл

@ -28,10 +28,11 @@
sdpMid: "test",
sdpMLineIndex: 3 });
jsonCopy = JSON.parse(JSON.stringify(rtcIceCandidate));
for (key in rtcIceCandidate) {
if (typeof(rtcIceCandidate[key]) == "function") continue;
is(rtcIceCandidate[key], jsonCopy[key], "key " + key + " should match.");
}
is(jsonCopy.candidate, "dummy");
is(jsonCopy.sdpMid, "test");
is(jsonCopy.sdpMLineIndex, 3);
is(jsonCopy.usernameFragment, rtcIceCandidate.usernameFragment);
is(Object.keys(jsonCopy).length, 4, "JSON limited to those four members.");
});
</script>
</pre>

Просмотреть файл

@ -4,7 +4,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* http://dev.w3.org/2011/webrtc/editor/webrtc.html#idl-def-RTCIceCandidate
* https://w3c.github.io/webrtc-pc/#rtcicecandidate-interface
*/
dictionary RTCIceCandidateInit {
@ -14,16 +14,51 @@ dictionary RTCIceCandidateInit {
DOMString? usernameFragment = null;
};
enum RTCIceComponent {
"rtp",
"rtcp"
};
enum RTCIceProtocol {
"udp",
"tcp"
};
enum RTCIceCandidateType {
"host",
"srflx",
"prflx",
"relay"
};
enum RTCIceTcpCandidateType {
"active",
"passive",
"so"
};
[Pref="media.peerconnection.enabled",
JSImplementation="@mozilla.org/dom/rtcicecandidate;1",
Exposed=Window]
interface RTCIceCandidate {
[Throws]
constructor(optional RTCIceCandidateInit candidateInitDict = {});
attribute DOMString candidate;
attribute DOMString? sdpMid;
attribute unsigned short? sdpMLineIndex;
attribute DOMString? usernameFragment;
[Default] object toJSON();
readonly attribute DOMString candidate;
readonly attribute DOMString? sdpMid;
readonly attribute unsigned short? sdpMLineIndex;
readonly attribute DOMString? foundation;
readonly attribute RTCIceComponent? component;
readonly attribute unsigned long? priority;
readonly attribute DOMString? address;
readonly attribute RTCIceProtocol? protocol;
readonly attribute unsigned short? port;
readonly attribute RTCIceCandidateType? type;
readonly attribute RTCIceTcpCandidateType? tcpType;
readonly attribute DOMString? relatedAddress;
readonly attribute unsigned short? relatedPort;
readonly attribute DOMString? usernameFragment;
// TODO: add remaining members relayProtocol and url (bug 1886013)
// readonly attribute RTCIceServerTransportProtocol? relayProtocol;
// readonly attribute DOMString? url;
RTCIceCandidateInit toJSON();
};

Просмотреть файл

@ -200,13 +200,6 @@ dictionary RTCIceCandidatePairStats : RTCStats {
unsigned long componentId; // moz
};
enum RTCIceCandidateType {
"host",
"srflx",
"prflx",
"relay"
};
dictionary RTCIceCandidateStats : RTCStats {
DOMString address;
long port;

Просмотреть файл

@ -1,8 +0,0 @@
[RTCIceCandidate-constructor.html]
[new RTCIceCandidate({ ... }) with nondefault values for all fields, tcp candidate]
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1322186
expected: FAIL
[new RTCIceCandidate({ ... }) with nondefault values for all fields]
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1322186
expected: FAIL

Просмотреть файл

@ -1,82 +1,16 @@
[idlharness.https.window.html]
[RTCIceCandidate interface: new RTCIceCandidate({ sdpMid: 1 }) must inherit property "protocol" with the proper type]
expected: FAIL
[RTCIceCandidate interface: new RTCIceCandidate({ sdpMid: 1 }) must inherit property "foundation" with the proper type]
expected: FAIL
[RTCIceCandidate interface: new RTCIceCandidate({ sdpMid: 1 }) must inherit property "relatedAddress" with the proper type]
expected: FAIL
[RTCIceCandidate interface: attribute tcpType]
expected: FAIL
[RTCIceCandidate interface: new RTCIceCandidate({ sdpMid: 1 }) must inherit property "type" with the proper type]
expected: FAIL
[RTCIceCandidate interface: attribute candidate]
expected: FAIL
[RTCIceCandidate interface: attribute priority]
expected: FAIL
[RTCIceCandidate interface: attribute foundation]
expected: FAIL
[RTCIceCandidate interface: attribute port]
expected: FAIL
[RTCPeerConnection interface: attribute onicecandidateerror]
expected: FAIL
[RTCIceCandidate interface: new RTCIceCandidate({ sdpMid: 1 }) must inherit property "relatedPort" with the proper type]
expected: FAIL
[RTCIceCandidate interface: new RTCIceCandidate({ sdpMid: 1 }) must inherit property "tcpType" with the proper type]
expected: FAIL
[RTCIceCandidate interface: attribute usernameFragment]
expected: FAIL
[RTCIceCandidate interface: new RTCIceCandidate({ sdpMid: 1 }) must inherit property "component" with the proper type]
expected: FAIL
[RTCSessionDescription interface: attribute type]
expected: FAIL
[RTCIceCandidate interface: attribute sdpMLineIndex]
expected: FAIL
[RTCIceCandidate interface: attribute protocol]
expected: FAIL
[RTCIceCandidate interface: attribute component]
expected: FAIL
[RTCIceCandidate interface: attribute relatedPort]
expected: FAIL
[RTCPeerConnection interface: new RTCPeerConnection() must inherit property "onicecandidateerror" with the proper type]
expected: FAIL
[RTCIceCandidate interface: attribute type]
expected: FAIL
[RTCIceCandidate interface: new RTCIceCandidate({ sdpMid: 1 }) must inherit property "port" with the proper type]
expected: FAIL
[RTCSessionDescription interface: attribute sdp]
expected: FAIL
[RTCIceCandidate interface: attribute sdpMid]
expected: FAIL
[RTCIceCandidate interface: attribute relatedAddress]
expected: FAIL
[RTCIceCandidate interface: new RTCIceCandidate({ sdpMid: 1 }) must inherit property "priority" with the proper type]
expected: FAIL
[RTCIceTransport interface: operation getSelectedCandidatePair()]
expected: FAIL
@ -215,12 +149,6 @@
[RTCErrorEvent interface: existence and properties of interface prototype object]
expected: FAIL
[RTCIceCandidate interface: new RTCIceCandidate({ sdpMid: 1 }) must inherit property "address" with the proper type]
expected: FAIL
[RTCIceCandidate interface: attribute address]
expected: FAIL
[RTCError interface: attribute sentAlert]
expected: FAIL

Просмотреть файл

@ -1,7 +1,4 @@
[munge-dont.html]
[RTCIceCandidate.candidate is read-only]
expected: FAIL
[Rejects SDP munging between createOffer and setLocalDescription]
expected: FAIL