Skip to content

Commit 629c47d

Browse files
author
Ahmad Saleem
committed
Sync RTCDataChannelInit as per Web Specification
https://bugs.webkit.org/show_bug.cgi?id=277604 rdar://problem/133630397 Reviewed by Youenn Fablet. This patch aligns 'RTCDataChannelInit' with Web Specification [1]: [1] https://w3c.github.io/webrtc-pc/#dom-rtcdatachannelinit It adds '[EnforceRange]' to 'maxPacketLifeTime' and 'maxRetransmits'. Additionally, I just did fly-by fix of adding link of web specification for easier reference. NOTE: We match now with Gecko / Firefox as well. * Source/WebCore/Modules/mediastream/RTCPeerConnection.idl: * LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannelInit-maxPacketLifeTime-enforce-range-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannelInit-maxPacketLifeTime-enforce-range.html: Added. * LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannelInit-maxRetransmits-enforce-range-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannelInit-maxRetransmits-enforce-range.html: Added. Canonical link: https://commits.webkit.org/304499@main
1 parent 53a061b commit 629c47d

File tree

5 files changed

+247
-7
lines changed

5 files changed

+247
-7
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
PASS maxPacketLifeTime with value 0 should succeed
3+
PASS maxPacketLifeTime with value 1 should succeed
4+
PASS maxPacketLifeTime with value 1000 should succeed
5+
PASS maxPacketLifeTime with maximum value 65535 should succeed
6+
PASS maxPacketLifeTime with value 65534 (max-1) should succeed
7+
PASS maxPacketLifeTime with value 3 should succeed
8+
PASS maxPacketLifeTime with value 10 should succeed
9+
PASS maxPacketLifeTime with value -1 should throw TypeError
10+
PASS maxPacketLifeTime with value -100 should throw TypeError
11+
PASS maxPacketLifeTime with value 65536 should throw TypeError
12+
PASS maxPacketLifeTime with value 100000 should throw TypeError
13+
PASS maxPacketLifeTime with Infinity should throw TypeError
14+
PASS maxPacketLifeTime with -Infinity should throw TypeError
15+
PASS maxPacketLifeTime with NaN should throw TypeError
16+
PASS maxPacketLifeTime with string "65536" should throw TypeError
17+
PASS maxPacketLifeTime with numeric string "100" should be converted to 100
18+
PASS maxPacketLifeTime when omitted should be null
19+
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>RTCDataChannelInit maxPacketLifeTime [EnforceRange] unsigned short tests</title>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script>
7+
'use strict';
8+
9+
// Helper to create a basic RTCPeerConnection
10+
function createPC() {
11+
return new RTCPeerConnection();
12+
}
13+
14+
// Test valid values within unsigned short range (0-65535)
15+
test(() => {
16+
const pc = createPC();
17+
const channel = pc.createDataChannel('test', { maxPacketLifeTime: 0 });
18+
assert_equals(channel.maxPacketLifeTime, 0);
19+
pc.close();
20+
}, 'maxPacketLifeTime with value 0 should succeed');
21+
22+
test(() => {
23+
const pc = createPC();
24+
const channel = pc.createDataChannel('test', { maxPacketLifeTime: 1 });
25+
assert_equals(channel.maxPacketLifeTime, 1);
26+
pc.close();
27+
}, 'maxPacketLifeTime with value 1 should succeed');
28+
29+
test(() => {
30+
const pc = createPC();
31+
const channel = pc.createDataChannel('test', { maxPacketLifeTime: 1000 });
32+
assert_equals(channel.maxPacketLifeTime, 1000);
33+
pc.close();
34+
}, 'maxPacketLifeTime with value 1000 should succeed');
35+
36+
test(() => {
37+
const pc = createPC();
38+
const channel = pc.createDataChannel('test', { maxPacketLifeTime: 65535 });
39+
assert_equals(channel.maxPacketLifeTime, 65535);
40+
pc.close();
41+
}, 'maxPacketLifeTime with maximum value 65535 should succeed');
42+
43+
test(() => {
44+
const pc = createPC();
45+
const channel = pc.createDataChannel('test', { maxPacketLifeTime: 65534 });
46+
assert_equals(channel.maxPacketLifeTime, 65534);
47+
pc.close();
48+
}, 'maxPacketLifeTime with value 65534 (max-1) should succeed');
49+
50+
test(() => {
51+
const pc = createPC();
52+
const channel = pc.createDataChannel('test', { maxPacketLifeTime: 3 });
53+
assert_equals(channel.maxPacketLifeTime, 3);
54+
pc.close();
55+
}, 'maxPacketLifeTime with value 3 should succeed');
56+
57+
test(() => {
58+
const pc = createPC();
59+
const channel = pc.createDataChannel('test', { maxPacketLifeTime: 10 });
60+
assert_equals(channel.maxPacketLifeTime, 10);
61+
pc.close();
62+
}, 'maxPacketLifeTime with value 10 should succeed');
63+
64+
// Test [EnforceRange] behavior - values outside range should throw TypeError
65+
const badValues = [
66+
{ value: -1, description: 'value -1' },
67+
{ value: -100, description: 'value -100' },
68+
{ value: 65536, description: 'value 65536' },
69+
{ value: 100000, description: 'value 100000' },
70+
{ value: Infinity, description: 'Infinity' },
71+
{ value: -Infinity, description: '-Infinity' },
72+
{ value: NaN, description: 'NaN' },
73+
{ value: "65536", description: 'string "65536"' }
74+
];
75+
76+
badValues.forEach(({ value, description }) => {
77+
test(() => {
78+
const pc = createPC();
79+
assert_throws_js(TypeError, () => {
80+
pc.createDataChannel('test', { maxPacketLifeTime: value });
81+
});
82+
pc.close();
83+
}, `maxPacketLifeTime with ${description} should throw TypeError`);
84+
});
85+
86+
// Test numeric strings (should be converted to numbers)
87+
test(() => {
88+
const pc = createPC();
89+
const channel = pc.createDataChannel('test', { maxPacketLifeTime: "100" });
90+
assert_equals(channel.maxPacketLifeTime, 100);
91+
pc.close();
92+
}, 'maxPacketLifeTime with numeric string "100" should be converted to 100');
93+
94+
test(() => {
95+
const pc = createPC();
96+
const channel = pc.createDataChannel('test', {});
97+
assert_equals(channel.maxPacketLifeTime, null);
98+
pc.close();
99+
}, 'maxPacketLifeTime when omitted should be null');
100+
101+
</script>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
PASS maxRetransmits with value 0 should succeed
3+
PASS maxRetransmits with value 1 should succeed
4+
PASS maxRetransmits with value 1000 should succeed
5+
PASS maxRetransmits with maximum value 65535 should succeed
6+
PASS maxRetransmits with value 65534 (max-1) should succeed
7+
PASS maxRetransmits with value 3 should succeed
8+
PASS maxRetransmits with value 10 should succeed
9+
PASS maxRetransmits with value -1 should throw TypeError
10+
PASS maxRetransmits with value -100 should throw TypeError
11+
PASS maxRetransmits with value 65536 should throw TypeError
12+
PASS maxRetransmits with value 100000 should throw TypeError
13+
PASS maxRetransmits with Infinity should throw TypeError
14+
PASS maxRetransmits with -Infinity should throw TypeError
15+
PASS maxRetransmits with NaN should throw TypeError
16+
PASS maxRetransmits with string "65536" should throw TypeError
17+
PASS maxRetransmits with numeric string "100" should be converted to 100
18+
PASS maxRetransmits when omitted should be null
19+
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>RTCDataChannelInit maxRetransmits [EnforceRange] unsigned short tests</title>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script>
7+
'use strict';
8+
9+
// Helper to create a basic RTCPeerConnection
10+
function createPC() {
11+
return new RTCPeerConnection();
12+
}
13+
14+
// Test valid values within unsigned short range (0-65535)
15+
test(() => {
16+
const pc = createPC();
17+
const channel = pc.createDataChannel('test', { maxRetransmits: 0 });
18+
assert_equals(channel.maxRetransmits, 0);
19+
pc.close();
20+
}, 'maxRetransmits with value 0 should succeed');
21+
22+
test(() => {
23+
const pc = createPC();
24+
const channel = pc.createDataChannel('test', { maxRetransmits: 1 });
25+
assert_equals(channel.maxRetransmits, 1);
26+
pc.close();
27+
}, 'maxRetransmits with value 1 should succeed');
28+
29+
test(() => {
30+
const pc = createPC();
31+
const channel = pc.createDataChannel('test', { maxRetransmits: 1000 });
32+
assert_equals(channel.maxRetransmits, 1000);
33+
pc.close();
34+
}, 'maxRetransmits with value 1000 should succeed');
35+
36+
test(() => {
37+
const pc = createPC();
38+
const channel = pc.createDataChannel('test', { maxRetransmits: 65535 });
39+
assert_equals(channel.maxRetransmits, 65535);
40+
pc.close();
41+
}, 'maxRetransmits with maximum value 65535 should succeed');
42+
43+
test(() => {
44+
const pc = createPC();
45+
const channel = pc.createDataChannel('test', { maxRetransmits: 65534 });
46+
assert_equals(channel.maxRetransmits, 65534);
47+
pc.close();
48+
}, 'maxRetransmits with value 65534 (max-1) should succeed');
49+
50+
test(() => {
51+
const pc = createPC();
52+
const channel = pc.createDataChannel('test', { maxRetransmits: 3 });
53+
assert_equals(channel.maxRetransmits, 3);
54+
pc.close();
55+
}, 'maxRetransmits with value 3 should succeed');
56+
57+
test(() => {
58+
const pc = createPC();
59+
const channel = pc.createDataChannel('test', { maxRetransmits: 10 });
60+
assert_equals(channel.maxRetransmits, 10);
61+
pc.close();
62+
}, 'maxRetransmits with value 10 should succeed');
63+
64+
// Test [EnforceRange] behavior - values outside range should throw TypeError
65+
const badValues = [
66+
{ value: -1, description: 'value -1' },
67+
{ value: -100, description: 'value -100' },
68+
{ value: 65536, description: 'value 65536' },
69+
{ value: 100000, description: 'value 100000' },
70+
{ value: Infinity, description: 'Infinity' },
71+
{ value: -Infinity, description: '-Infinity' },
72+
{ value: NaN, description: 'NaN' },
73+
{ value: "65536", description: 'string "65536"' }
74+
];
75+
76+
badValues.forEach(({ value, description }) => {
77+
test(() => {
78+
const pc = createPC();
79+
assert_throws_js(TypeError, () => {
80+
pc.createDataChannel('test', { maxRetransmits: value });
81+
});
82+
pc.close();
83+
}, `maxRetransmits with ${description} should throw TypeError`);
84+
});
85+
86+
// Test numeric strings (should be converted to numbers)
87+
test(() => {
88+
const pc = createPC();
89+
const channel = pc.createDataChannel('test', { maxRetransmits: "100" });
90+
assert_equals(channel.maxRetransmits, 100);
91+
pc.close();
92+
}, 'maxRetransmits with numeric string "100" should be converted to 100');
93+
94+
test(() => {
95+
const pc = createPC();
96+
const channel = pc.createDataChannel('test', {});
97+
assert_equals(channel.maxRetransmits, null);
98+
pc.close();
99+
}, 'maxRetransmits when omitted should be null');
100+
101+
</script>

Source/WebCore/Modules/mediastream/RTCPeerConnection.idl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (C) 2012 Google Inc. All rights reserved.
33
* Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
44
* Copyright (C) 2015, 2016 Ericsson AB. All rights reserved.
5-
* Copyright (C) 2017 Apple Inc. All rights reserved.
5+
* Copyright (C) 2017-2025 Apple Inc. All rights reserved.
66
*
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions
@@ -35,17 +35,18 @@
3535

3636
typedef RTCRtpTransceiverDirection RtpTransceiverDirection;
3737

38+
// https://w3c.github.io/webrtc-pc/#dom-rtcdatachannelinit
3839
[
3940
Conditional=WEB_RTC,
4041
EnabledBySetting=PeerConnectionEnabled
4142
] dictionary RTCDataChannelInit {
4243
boolean ordered = true;
43-
unsigned short maxPacketLifeTime;
44-
unsigned short maxRetransmits;
44+
[EnforceRange] unsigned short maxPacketLifeTime;
45+
[EnforceRange] unsigned short maxRetransmits;
4546
USVString protocol = "";
4647
boolean negotiated = false;
4748
[EnforceRange] unsigned short id;
48-
// FIXME 169644: missing priority
49+
// FIXME: webkit.org/b/277605 - missing priority
4950
};
5051

5152
[
@@ -133,12 +134,11 @@ typedef (object or DOMString) AlgorithmIdentifier;
133134
attribute EventHandler ontrack;
134135

135136
// 6.1 Peer-to-peer data API
137+
// https://w3c.github.io/webrtc-pc/#rtcpeerconnection-interface-extensions-0
136138
readonly attribute RTCSctpTransport? sctp;
137-
138-
RTCDataChannel createDataChannel(USVString label, optional RTCDataChannelInit options);
139+
RTCDataChannel createDataChannel(USVString label, optional RTCDataChannelInit options = {});
139140
attribute EventHandler ondatachannel;
140141

141-
142142
// 8.2 Statistics API
143143
Promise<RTCStatsReport> getStats(optional MediaStreamTrack? selector = null);
144144
};

0 commit comments

Comments
 (0)