Skip to content

Commit

Permalink
Make data channels transferable to DedicatedWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
dontcallmedom committed Sep 5, 2024
1 parent 6813b14 commit af08381
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 9 deletions.
63 changes: 63 additions & 0 deletions amendments.json
Original file line number Diff line number Diff line change
Expand Up @@ -1017,5 +1017,68 @@
"web-platform-tests/wpt#47663"
]
}
],
"webidl-rtcdatachannel": [
{
"description": "Make RTCDataChannel transferable to DedicatedWorker",
"pr": 2988,
"type": "addition",
"status": "candidate",
"id": 48,
"tests": [
"webrtc/transfer-datachannel.html"
],
"testUpdates": [
"web-platform-tests/wpt#47707"
]
}
],
"rtcdatachannel-slots-init": [
{
"description": "Make RTCDataChannel transferable to DedicatedWorker",
"pr": 2988,
"type": "addition",
"status": "candidate",
"difftype": "append",
"id": 48,
"tests": [
"webrtc/transfer-datachannel.html"
],
"testUpdates": [
"web-platform-tests/wpt#47707"
]
}
],
"rtcdatachannel-send-1": [
{
"description": "Make RTCDataChannel transferable to DedicatedWorker",
"pr": 2988,
"type": "addition",
"status": "candidate",
"difftype": "append",
"id": 48,
"tests": [
"webrtc/transfer-datachannel.html"
],
"testUpdates": [
"web-platform-tests/wpt#47707"
]
}
],
"announcing-a-data-channel-as-closed": [
{
"description": "Make RTCDataChannel transferable to DedicatedWorker",
"pr": 2988,
"type": "addition",
"status": "candidate",
"difftype": "append",
"id": 48,
"tests": [
"webrtc/transfer-datachannel.html"
],
"testUpdates": [
"web-platform-tests/wpt#47707"
]
}
]
}
6 changes: 3 additions & 3 deletions base-rec.html
Original file line number Diff line number Diff line change
Expand Up @@ -13525,7 +13525,7 @@ <h4 id="x6-2-1-creating-a-data-channel"><bdi class="secno">6.2.1 </bdi>
internal slot initialized to <code>0</code>.
</p>
</li>
<li class="no-test-needed">
<li class="no-test-needed" id="rtcdatachannel-slots-init">
<p>
Let <var>channel</var> have internal slots named
<dfn data-dfn-type="idl" id="dfn-datachannellabel">[[DataChannelLabel]]</dfn>, <dfn data-dfn-type="idl" id="dfn-ordered">[[Ordered]]</dfn>,
Expand Down Expand Up @@ -13891,7 +13891,7 @@ <h4 id="x6-2-7-receiving-messages-on-a-data-channel"><bdi class="secno">6.2.7 </
</ol>
</section>
<div>
<pre class="idl has-tests def" data-tests="idlharness.https.window.js" id="webidl-1143016005"><span class="idlHeader"><a class="self-link" href="#webidl-1143016005">WebIDL</a></span><span data-idl="" class="idlInterface" id="idl-def-rtcdatachannel" data-title="RTCDataChannel">[<span class="extAttr"><a data-type="extended-attribute" href="https://heycam.github.io/webidl/#Exposed">Exposed</a>=<a data-type="interface" href="https://html.spec.whatwg.org/multipage/window-object.html#window">Window</a></span>]
<pre class="idl has-tests def" data-tests="idlharness.https.window.js" id="webidl-rtcdatachannel"><span class="idlHeader"><a class="self-link" href="#webidl-1143016005">WebIDL</a></span><span data-idl="" class="idlInterface" id="idl-def-rtcdatachannel" data-title="RTCDataChannel">[<span class="extAttr"><a data-type="extended-attribute" href="https://heycam.github.io/webidl/#Exposed">Exposed</a>=<a data-type="interface" href="https://html.spec.whatwg.org/multipage/window-object.html#window">Window</a></span>]
interface <a class="internalDFN idlID" data-link-type="interface" href="#dom-rtcdatachannel" id="ref-for-dom-rtcdatachannel-42"><code>RTCDataChannel</code></a> : <span class="idlSuperclass"><a data-type="interface" href="https://dom.spec.whatwg.org/#eventtarget">EventTarget</a></span> {<span data-idl="" class="idlAttribute" id="idl-def-rtcdatachannel-label" data-title="label" data-dfn-for="RTCDataChannel">
readonly attribute<span class="idlType"> <a data-type="interface" href="https://heycam.github.io/webidl/#idl-USVString">USVString</a></span> <a class="internalDFN idlName" data-link-type="attribute" href="#dom-datachannel-label" id="ref-for-dom-datachannel-label-1"><code>label</code></a>;</span><span data-idl="" class="idlAttribute" id="idl-def-rtcdatachannel-ordered" data-title="ordered" data-dfn-for="RTCDataChannel">
readonly attribute<span class="idlType"> <a data-type="interface" href="https://heycam.github.io/webidl/#idl-boolean">boolean</a></span> <a class="internalDFN idlName" data-link-type="attribute" href="#dom-datachannel-ordered" id="ref-for-dom-datachannel-ordered-1"><code>ordered</code></a>;</span><span data-idl="" class="idlAttribute" id="idl-def-rtcdatachannel-maxpacketlifetime" data-title="maxPacketLifeTime" data-dfn-for="RTCDataChannel">
Expand Down Expand Up @@ -14231,7 +14231,7 @@ <h4 id="methods-12">
steps</dfn>:
</p>
<ol>
<li class="no-test-needed">
<li class="no-test-needed" id="rtcdatachannel-send-1">
<p>
Let <var>channel</var> be the <a data-link-type="idl" href="#dom-rtcdatachannel" class="internalDFN" id="ref-for-dom-rtcdatachannel-56"><code><code>RTCDataChannel</code></code></a> object on
which data is to be sent.
Expand Down
58 changes: 52 additions & 6 deletions webrtc.html
Original file line number Diff line number Diff line change
Expand Up @@ -14032,7 +14032,7 @@ <h4>
internal slot initialized to <code>0</code>.
</p>
</li>
<li class="no-test-needed">
<li class="no-test-needed" id="rtcdatachannel-slots-init">
<p>
Let <var>channel</var> have internal slots named
<dfn data-dfn-for="RTCDataChannel">[[\DataChannelLabel]]</dfn>, <dfn data-dfn-for="RTCDataChannel">[[\Ordered]]</dfn>,
Expand All @@ -14042,6 +14042,14 @@ <h4>
<dfn data-dfn-for="RTCDataChannel">[[\Negotiated]]</dfn>, and <dfn data-dfn-for="RTCDataChannel">[[\DataChannelId]]</dfn>.
</p>
</li>
<li class="add-to-rtcdatachannel-slots-init">Let <var>channel</var> have a <dfn data-dfn-for="RTCDataChannel">[[\IsTransferable]]</dfn> internal slot initialized to <code>true</code>.</li>
<li class="add-to-rtcdatachannel-slots-init">[=Queue a task=] to run the following step:<ol>
<li>Set <var>channel</var>.{{RTCDataChannel/[[IsTransferable]]}} to <code>false</code>.
</li>
</ol>
<p>This task needs to run before any task enqueued by the [=receiving messages on a data channel=] algorithm for <var>channel</var>.
This ensures that no message is lost during the transfer of a {{RTCDataChannel}}.</p>
</li>
<li class="no-test-needed">
<p>
Return <var>channel</var>.
Expand Down Expand Up @@ -14254,9 +14262,9 @@ <h4>
</li>
</ol>
</section>
<section>
<section id="announcing-a-data-channel-as-closed">
<h4>
Announcing a data channel as closed
<dfn class="abstract-op">Announcing a data channel as closed</dfn>
</h4>
<p>
When an {{RTCDataChannel}} object's [= underlying data transport =]
Expand Down Expand Up @@ -14302,6 +14310,42 @@ <h4>
</li>
</ol>
</section>
<section class="add-to-announcing-a-data-channel-as-closed">
<h4>Transfering data channel</h4>
<p>The {{RTCDataChannel}} [=transfer steps=], given <var>value</var> and <var>dataHolder</var>, are:</p>
<ol>
<li><p>If <var>value</var>.{{RTCDataChannel/[[IsTransferable]]}} is <code>false</code>, throw a {{DataCloneError}} DOMException.</p></li>
<li><p>Set <var>dataHolder</var>.{{RTCDataChannel/[[ReadyState]]}} to <var>value</var>.{{RTCDataChannel/[[ReadyState]]}}.</p></li>
<li><p>Set <var>dataHolder</var>.{{RTCDataChannel/[[DataChannelLabel]]}} to <var>value</var>.{{RTCDataChannel/[[DataChannelLabel]]}}.</p></li>
<li><p>Set <var>dataHolder</var>.{{RTCDataChannel/[[Ordered]]}} to <var>value</var>.{{RTCDataChannel/[[Ordered]]}}.</p></li>
<li><p>Set <var>dataHolder</var>.{{RTCDataChannel/[[MaxPacketLifeTime]]}} to <var>value</var>..{{RTCDataChannel/[[MaxPacketLifeTime]]}}</p></li>
<li><p>Set <var>dataHolder</var>.{{RTCDataChannel/[[MaxRetransmits]]}} to <var>value</var>.{{RTCDataChannel/[[MaxRetransmits]]}}.</p></li>
<li><p>Set <var>dataHolder</var>.{{RTCDataChannel/[[DataChannelProtocol]]}} to <var>value</var>.{{RTCDataChannel/[[DataChannelProtocol]]}}.</p></li>
<li><p>Set <var>dataHolder</var>.{{RTCDataChannel/[[Negotiated]]}} to <var>value</var>.{{RTCDataChannel/[[Negotiated]]}}.</p></li>
<li><p>Set <var>dataHolder</var>.{{RTCDataChannel/[[DataChannelId]]}} to <var>value</var>.{{RTCDataChannel/[[DataChannelId]]}}.</p></li>
<li><p>Set <var>dataHolder</var>’s [= underlying data transport =] to <var>value</var> [=underlying data transport=].</p></li>
<li><p>Set <var>value</var>.{{RTCDataChannel/[[IsTransferable]]}} to <code>false</code>.</p></li>
<li><p>Set <var>value</var>.{{RTCDataChannel/[[ReadyState]]}} to "closed".</p></li>
</ol>
</div>
<div><p>The {{RTCDataChannel}} [=transfer-receiving steps=], given <var>dataHolder</var> and <var>channel</var>, are:</p>
<ol>
<li><p>Initialize <var>channel</var>.{{RTCDataChannel/[[ReadyState]]}} to <var>dataHolder</var>.{{RTCDataChannel/[[ReadyState]]}}.</p></li>
<li><p>Initialize <var>channel</var>.{{RTCDataChannel/[[DataChannelLabel]]}} to <var>dataHolder</var>.{{RTCDataChannel/[[DataChannelLabel]]}}.</p></li>
<li><p>Initialize <var>channel</var>.{{RTCDataChannel/[[Ordered]]}} to <var>dataHolder</var>.{{RTCDataChannel/[[Ordered]]}}.</p></li>
<li><p>Initialize <var>channel</var>.{{RTCDataChannel/[[MaxPacketLifeTime]]}} to <var>dataHolder</var>.{{RTCDataChannel/[[MaxPacketLifeTime]]}}.</p></li>
<li><p>Initialize <var>channel</var>.{{RTCDataChannel/[[MaxRetransmits]]}} to <var>dataHolder</var>.{{RTCDataChannel/[[MaxRetransmits]]}}.</p></li>
<li><p>Initialize <var>channel</var>.{{RTCDataChannel/[[DataChannelProtocol]]}} to <var>dataHolder</var>.{{RTCDataChannel/[[DataChannelProtocol]]}}.</p></li>
<li><p>Initialize <var>channel</var>.{{RTCDataChannel/[[Negotiated]]}} to <var>dataHolder</var>.{{RTCDataChannel/[[Negotiated]]}}.</p></li>
<li><p>Initialize <var>channel</var>.{{RTCDataChannel/[[DataChannelId]]}} to <var>dataHolder</var>.{{RTCDataChannel/[[DataChannelId]]}}.</p></li>
<li><p>Initialize <var>channel</var>’s [=underlying data transport=] to <var>dataHolder</var>’s [= underlying data transport =].</p></li>
</ol>
<p>The above steps do not need to transfer {{RTCDataChannel/[[BufferedAmount]]}} as its value will always be equal to <code>0</code>.
The reason is an {{RTCDataChannel}} can be transferred only if its [=send() algorithm=] was not called prior the transfer.</p>
<p>If the [=underlying data transport=] is closed at the time of the [=transfer-receiving steps=],
the {{RTCDataChannel}} object will be closed by running the [=announcing a data channel as closed=] algorithm immediately after the [=transfer-receiving steps=].</p>

</section>
<section>
<h4>
Error on creating data channels
Expand Down Expand Up @@ -14347,7 +14391,7 @@ <h4>
</section>
<section>
<h4>
Receiving messages on a data channel
<dfn class="abstract-op">Receiving messages on a data channel</dfn>
</h4>
<p>
When an {{RTCDataChannel}} message has
Expand Down Expand Up @@ -14432,7 +14476,7 @@ <h4>
</ol>
</section>
<div>
<pre class="idl" data-tests="idlharness.https.window.js">[Exposed=Window]
<pre class="idl" id="webidl-rtcdatachannel" data-tests="idlharness.https.window.js">[Exposed=(Window,DedicatedWorker), Transferable]
interface RTCDataChannel : EventTarget {
readonly attribute USVString label;
readonly attribute boolean ordered;
Expand Down Expand Up @@ -14788,12 +14832,14 @@ <h2>
steps</dfn>:
</p>
<ol class=algorithm>
<li class="no-test-needed">
<li class="no-test-needed" id="rtcdatachannel-send-1">
<p>
Let <var>channel</var> be the {{RTCDataChannel}} object on
which data is to be sent.
</p>
</li>
<li class="add-to-rtcdatachannel-send-1"><p>Set <var>channel</var>.{{RTCDataChannel/[[IsTransferable]]}} to <code>false</code>.</p></li>

<li data-tests="RTCDataChannel-send.html">
<p>
If <var>channel</var>.{{RTCDataChannel/[[ReadyState]]}} is not
Expand Down

0 comments on commit af08381

Please sign in to comment.