-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathindex.bs
More file actions
3729 lines (3186 loc) · 166 KB
/
Copy pathindex.bs
File metadata and controls
3729 lines (3186 loc) · 166 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class="metadata">
Title: WebTransport
Shortname: webtransport
Level: none
Status: w3c/ED
Group: webtransport
ED: https://w3c.github.io/webtransport/
TR: https://www.w3.org/TR/webtransport/
Editor: Nidhi Jaju, w3cid 136840, Google
Editor: Victor Vasiliev, w3cid 113328, Google
Editor: Jan-Ivar Bruaroey, w3cid 79152, Mozilla
Former Editor: Bernard Aboba, Microsoft Corporation
Former Editor: Peter Thatcher, Google
Former Editor: Robin Raymond, Optical Tone Ltd.
Former Editor: Yutaka Hirano, Google
Abstract:
This document defines a set of ECMAScript APIs in WebIDL to allow data to be
sent and received between a browser and server, utilizing [[!WEB-TRANSPORT-OVERVIEW]].
This specification is being developed in conjunction with protocol specifications
developed by the IETF WEBTRANS Working Group.
Repository: w3c/webtransport
Indent: 2
Markup Shorthands: markdown yes
Boilerplate: omit conformance
</pre>
<pre class="biblio">
{
"quic": {
"authors": ["Jana Iyengar", "Martin Thomson"],
"href": "https://www.rfc-editor.org/rfc/rfc9000",
"title": "QUIC: A UDP-Based Multiplexed and Secure Transport",
"status": "Proposed Standard",
"publisher": "IETF"
},
"quic-datagram": {
"authors": ["Tommy Pauly", "Eric Kinnear", "David Schinazi"],
"href": "https://www.rfc-editor.org/rfc/rfc9221",
"title": "An Unreliable Datagram Extension to QUIC",
"status": "Proposed Standard",
"publisher": "IETF"
},
"reliable-reset": {
"authors": ["Marten Seemann", "奥一穂"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-quic-reliable-stream-reset",
"title": "QUIC Stream Resets with Partial Delivery",
"status": "Internet-Draft",
"publisher": "IETF"
},
"web-transport-overview": {
"authors": ["Victor Vasiliev"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview",
"title": "WebTransport Protocol Framework",
"status": "Internet-Draft",
"publisher": "IETF"
},
"web-transport-http3": {
"authors": ["Alan Frindell", "Eric Kinnear", "Victor Vasiliev"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3",
"title": "WebTransport over HTTP/3",
"status": "Internet-Draft",
"publisher": "IETF"
},
"web-transport-http2": {
"authors": ["Alan Frindell", "Eric Kinnear", "Tommy Pauly", "Martin Thomson", "Victor Vasiliev", "Guowu Xie"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http2",
"title": "WebTransport over HTTP/2",
"status": "Internet-Draft",
"publisher": "IETF"
}
}
</pre>
<pre class="link-defaults">
spec:infra; type:dfn; for:set; text:for each
spec:infra; type:dfn; for:/; text:set
spec:streams; type:interface; text:ReadableStream
spec:fetch; type:dfn; for:/; text:fetch
spec:fetch; type:dfn; for:/; text:credentials
spec:fetch; type:dfn; for:fetch record; text:request
spec:fetch; type:dfn; for:request; text:header list
spec:url; type:dfn; text:scheme
spec:url; type:dfn; text:fragment
spec:infra; type:dfn; for:/; text:ASCII case-insensitive
spec:infra; type:dfn; text:list
</pre>
<pre class="anchors">
url: https://html.spec.whatwg.org/multipage/origin.html#concept-origin; type: dfn; text: origin; for:/
urlPrefix: http://www.ecma-international.org/ecma-262/6.0/index.html; spec: ECMASCRIPT-6.0
type: dfn
text: fulfilled; url: sec-promise-objects
text: rejected; url: sec-promise-objects
text: pending; url: sec-promise-objects
text: resolved; url: sec-promise-objects
text: settled; url: sec-promise-objects
text: the typed array constructors table; url: #table-49
urlPrefix: https://heycam.github.io/webidl/; spec: WEBIDL
type: dfn
text: created; for:DOMException; url: dfn-create-exception
text: name; for:DOMException; url: domexception-name
text: message; for:DOMException; url: domexception-message
urlPrefix: https://w3ctag.github.io/privacy-principles/;
type: dfn
text: cross-site recognition; url: dfn-cross-site-recognition
</pre>
# Introduction # {#introduction}
*This section is non-normative.*
This specification uses [[!WEB-TRANSPORT-OVERVIEW]] to send data to and receive
data from servers. It can be used like WebSockets but with support for multiple
streams, unidirectional streams, out-of-order delivery, and reliable as well as
unreliable transport.
Note: The API presented in this specification represents a preliminary proposal
based on work-in-progress within the IETF WEBTRANS WG. Since the [[!WEB-TRANSPORT-HTTP3]]
and [[!WEB-TRANSPORT-HTTP2]] specifications are a work-in-progress, both the protocol
and API are likely to change significantly going forward.
# Conformance # {#conformance}
As well as sections marked as non-normative, all authoring guidelines,
diagrams, examples, and notes in this specification are non-normative.
Everything else in this specification is normative.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
"SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" are to be interpreted as described in
[[!RFC2119]] and [[!RFC8174]] when, and only when, they appear in all capitals, as shown here.
This specification defines conformance criteria that apply to a single product:
the user agent that implements the interfaces that it contains.
Conformance requirements phrased as algorithms or specific steps may be
implemented in any manner, so long as the end result is equivalent. (In
particular, the algorithms defined in this specification are intended to be
easy to follow, and not intended to be performant.)
Implementations that use ECMAScript to implement the APIs defined in this
specification MUST implement them in a manner consistent with the ECMAScript
Bindings defined in the Web IDL specification [[!WEBIDL]], as this
specification uses that specification and terminology.
# Protocol concepts # {#protocol-concepts}
There are two main protocol concepts for WebTransport: sessions and streams. Each [=WebTransport
session=] can contain multiple [=WebTransport streams=].
These should not be confused with [=protocol names=] which is an application-level API construct.
## WebTransport session ## {#webtransport-session}
A <dfn for="protocol">WebTransport session</dfn> is a session of WebTransport over an HTTP/3
or HTTP/2 <dfn>underlying [=connection=]</dfn>.
There may be multiple [=WebTransport sessions=] on one [=connection=], when pooling is enabled.
A [=WebTransport session=] has the following capabilities defined in [[!WEB-TRANSPORT-OVERVIEW]]:
<table class="data" dfn-for="session">
<thead>
<tr>
<th>capability
<th>definition
</tr>
</thead>
<tbody>
<tr>
<td><dfn>send a [datagram](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#name-datagrams)</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.2](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.2-6.2.1)
</tr>
<tr>
<td><dfn>receive a [datagram](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#name-datagrams)</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.2](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.2-6.4.1)
</tr>
<tr>
<td><dfn>create an [=stream/outgoing unidirectional=] stream</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.3-7.2.1)
</tr>
<tr>
<td><dfn>create a [=stream/bidirectional=] stream</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.3-7.4.1)
</tr>
<tr>
<td><dfn>receive an [=stream/incoming unidirectional=] stream</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.3-7.6.1)
</tr>
<tr>
<td><dfn>receive a [=stream/bidirectional=] stream</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.3-7.8.1)
</tr>
</tbody>
</table>
A [=WebTransport session=] |session| is <dfn for=session>draining</dfn> when the [=CONNECT stream=] is
asked to gracefully close by the server, as described in [[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.1](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11/#section-4.1).
To <dfn for=session>terminate</dfn> a [=WebTransport session=] |session| with an optional integer
|code| and an optional [=byte sequence=] |reason|, follow [[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.1](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.1-2.2.1).
A [=WebTransport session=] |session| is <dfn for=session>terminated</dfn>, with optionally
an integer |code| and a [=byte sequence=] |reason|, when the [=CONNECT stream=] is closed by the server,
as described at [[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.1](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.1-4.2.1).
## WebTransport stream ## {#webtransport-stream}
A <dfn for="protocol">WebTransport stream</dfn> is a concept for a reliable in-order stream of
bytes on a [=WebTransport session=], as described in [[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.3).
A [=WebTransport stream=] is one of <dfn for=stream>incoming unidirectional</dfn>,
<dfn for=stream>outgoing unidirectional</dfn> or <dfn for=stream>bidirectional</dfn>.
<div class=note>
Data sent on a [=WebTransport stream | stream=] is delivered
as an undifferentiated sequence of bytes.
The number of bytes in a single write operation on the sending side might not match
the number of bytes read in single operation at the receiving side.
Separate writes can be merged and delivered as a single byte sequence;
a single write might be delivered separately.
This includes {{WebTransportWriter/atomicWrite|atomic writes}},
which exist to prevent flow control deadlocks,
not to guarantee that data is delivered together.
Applications that depend on having a message-based protocol
that preserves message boundaries between sender and receiver
need to add a framing layer so that messages can be reconstructed.
</div>
A [=WebTransport stream=] has the following capabilities:
<table class="data" dfn-for="stream">
<thead>
<tr>
<th>capability
<th>definition
<th>[=stream/incoming unidirectional=]
<th>[=stream/outgoing unidirectional=]
<th>[=stream/bidirectional=]
</tr>
</thead>
<tbody>
<tr>
<td><dfn>send</dfn> bytes (potentially with FIN)
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.3-9.2.1)
<td>No
<td>Yes
<td>Yes
</tr>
<tr>
<td><dfn>receive</dfn> bytes (potentially with FIN)
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.3-9.4.1)
<td>Yes
<td>No
<td>Yes
</tr>
<tr>
<td><dfn>abort receiving</dfn> on a [=WebTransport stream=]
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11.html#section-4.3-9.8.1)
<td>Yes
<td>No
<td>Yes
</tr>
<tr>
<td><dfn>abort sending</dfn> on a [=WebTransport stream=]
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11.html#section-4.3-9.6.1)
<td>No
<td>Yes
<td>Yes
</tr>
</tbody>
</table>
A [=WebTransport stream=] has the following signals:
<table class="data" dfn-for="stream-signal">
<thead>
<tr>
<th>event
<th>definition
<th>[=stream/incoming unidirectional=]
<th>[=stream/outgoing unidirectional=]
<th>[=stream/bidirectional=]
</tr>
</thead>
<tbody>
<tr>
<td><dfn>receiving aborted</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11.html#section-4.3-11.4.1)
<td>No
<td>Yes
<td>Yes
</tr>
<tr>
<td><dfn>sending aborted</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11.html#section-4.3-11.2.1)
<td>Yes
<td>No
<td>Yes
</tr>
<tr>
<td><dfn>flow control</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11#section-4.3-5)
<td>No
<td>Yes
<td>Yes
</tr>
</tbody>
</table>
# `WebTransportDatagramsWritable` Interface # {#datagram-writable}
A <dfn interface>WebTransportDatagramsWritable</dfn> is a {{WritableStream}} providing outgoing streaming
features to [=send a datagram | send datagrams=].
<pre class="idl">
[Exposed=(Window,Worker), SecureContext, Transferable]
interface WebTransportDatagramsWritable : WritableStream {
attribute WebTransportSendGroup? sendGroup;
attribute long long sendOrder;
};
</pre>
## Internal slots ## {#datagram-writable-internal-slots}
A {{WebTransportDatagramsWritable}} object has the following internal slot.
<table class="data" dfn-for="WebTransportDatagramsWritable" dfn-type="attribute">
<thead>
<tr>
<th>Internal Slot
<th>Description (<em>non-normative</em>)
</tr>
</thead>
<tbody>
<tr>
<td><dfn>`[[OutgoingDatagramsQueue]]`</dfn>
<td class="non-normative">A queue of tuples of an outgoing datagram, a timestamp and a promise
which is resolved when the datagram is sent or discarded.
</tr>
<tr>
<td><dfn>`[[Transport]]`</dfn>
<td class="non-normative">The {{WebTransport}} that owns this {{WebTransportDatagramsWritable}}.
</tr>
<tr>
<td><dfn>`[[SendGroup]]`</dfn>
<td class="non-normative">An optional {{WebTransportSendGroup}}, or null.
</tr>
<tr>
<td><dfn>`[[SendOrder]]`</dfn>
<td class="non-normative">An optional send order number, defaulting to 0.
</tr>
</tbody>
</table>
<div algorithm="create writable">
To <dfn export for="WebTransportDatagramsWritable" lt="create|creating">create</dfn> a
{{WebTransportDatagramsWritable}}, given a {{WebTransport}} |transport|, a |sendGroup|,
and a |sendOrder|, perform the following steps.
1. Let |stream| be a [=new=] {{WebTransportDatagramsWritable}}, with:
: {{WebTransportDatagramsWritable/[[OutgoingDatagramsQueue]]}}
:: an empty queue
: {{WebTransportDatagramsWritable/[[Transport]]}}
:: |transport|
: {{WebTransportDatagramsWritable/[[SendGroup]]}}
:: |sendGroup|
: {{WebTransportDatagramsWritable/[[SendOrder]]}}
:: |sendOrder|
1. Let |writeDatagramsAlgorithm| be an action that runs [=writeDatagrams=] with
|transport| and |stream|.
1. [=WritableStream/Set up=] |stream| with [=WritableStream/set up/writeAlgorithm=]
set to |writeDatagramsAlgorithm|.
1. Return |stream|.
</div>
## Attributes ## {#datagram-writable-attributes}
: <dfn for="WebTransportDatagramsWritable" attribute>sendGroup</dfn>
:: The getter steps are:
1. Return [=this=]'s {{WebTransportDatagramsWritable/[[SendGroup]]}}.
:: The setter steps, given |value|, are:
1. If |value| is non-null, and
|value|.{{WebTransportSendGroup/[[Transport]]}} is not
[=this=].{{WebTransportDatagramsWritable/[[Transport]]}}, [=throw=]
an {{InvalidStateError}}.
1. Set [=this=].{{WebTransportDatagramsWritable/[[SendGroup]]}} to |value|.
: <dfn for="WebTransportDatagramsWritable" attribute>sendOrder</dfn>
:: The getter steps are:
1. Return [=this=]'s {{WebTransportDatagramsWritable/[[SendOrder]]}}.
:: The setter steps, given |value|, are:
1. Set [=this=].{{WebTransportDatagramsWritable/[[SendOrder]]}} to |value|.
## Procedures ## {#datagram-writable-procedures}
<div algorithm>
The <dfn>writeDatagrams</dfn> algorithm is given a |transport| and |writable| as parameters and
|data| as input. It is defined by running the following steps:
1. Let |timestamp| be a timestamp representing now.
1. If |data| is not a {{BufferSource}} object, then return [=a promise rejected with=] a {{TypeError}}.
1. Let |datagrams| be |transport|.{{[[Datagrams]]}}.
1. If |datagrams|.{{[[OutgoingMaxDatagramSize]]}} is less than |data|'s \[[ByteLength]], return
[=a promise resolved with=] undefined.
1. Let |promise| be a new promise.
1. Let |bytes| be a copy of bytes which |data| represents.
1. Let |chunk| be a tuple of |bytes|, |timestamp| and |promise|.
1. Enqueue |chunk| to |writable|.{{[[OutgoingDatagramsQueue]]}}.
1. If the length of |writable|.{{[[OutgoingDatagramsQueue]]}} is less than
|datagrams|.{{[[OutgoingMaxBufferedDatagrams]]}}, then [=resolve=] |promise| with undefined.
1. Return |promise|.
Note: The associated {{WritableStream}} calls [=writeDatagrams=] only when all the promises that
have been returned by [=writeDatagrams=] for that stream have been resolved. Hence the
timestamp and the expiration duration work well only when the web developer pays attention to
{{WritableStreamDefaultWriter/ready|WritableStreamDefaultWriter.ready}}.
</div>
<div algorithm>
To <dfn>sendDatagrams</dfn>, given a {{WebTransport}} object |transport| and a
{{WebTransportDatagramsWritable}} object |writable|, [=queue a network task=]
with |transport| to run the following steps:
1. Let |queue| be a copy of |writable|.{{[[OutgoingDatagramsQueue]]}}.
Note: The above copy, as well as the queueing of a network task to run these steps, can be optimized.
1. Let |maxSize| be |transport|.{{[[Datagrams]]}}.{{[[OutgoingMaxDatagramSize]]}}.
1. Let |duration| be |transport|.{{[[Datagrams]]}}.{{[[OutgoingDatagramsExpirationDuration]]}}.
1. If |duration| is null, then set |duration| to an [=implementation-defined=] value.
1. Run the following steps [=in parallel=]:
1. While |queue| is not empty:
1. Let |bytes|, |timestamp| and |promise| be |queue|'s first element.
1. If more than |duration| milliseconds have passed since |timestamp|, then:
1. Remove the first element from |queue|.
1. [=Queue a network task=] with |transport| to [=resolve=] |promise| with undefined.
1. Otherwise, break this loop.
1. If |transport|.{{[[State]]}} is not `"connected"`, then return.
1. While |queue| is not empty:
1. Let |bytes|, |timestamp| and |promise| be |queue|'s first element.
1. If |bytes|'s length ≤ |maxSize|:
1. If it is not possible to send |bytes| to the network immediately, then break this loop.
1. [=session/Send a datagram=], with |transport|.{{[[Session]]}} and |bytes|.
1. Remove the first element from |queue|.
1. [=Queue a network task=] with |transport| to [=resolve=] |promise| with undefined.
</div>
The user agent MUST, for any {{WebTransport}} object whose
{{[[State]]}} is `"connecting"` or `"connected"`, run [=sendDatagrams=] on a
subset (determined by [=send-order rules=]) of its associated {{WebTransportDatagramsWritable}}
objects, and SHOULD do so as soon as reasonably possible whenever the
algorithm can make progress.
Note: Writing datagrams while the transport's {{[[State]]}} is `"connecting"` is allowed. The
datagrams are stored in {{[[OutgoingDatagramsQueue]]}}, and they can be discarded
in the same manner as when in the `"connected"` state. Once the transport's {{[[State]]}} becomes
`"connected"`, it will start sending the queued datagrams.
The <dfn>send-order rules</dfn> are that sending in general MAY be interleaved with
sending of previously queued streams and datagrams, as well as streams and datagrams
yet to be queued to be sent over this transport, except that sending MUST starve until
all bytes queued for sending on streams and datagrams with the same
{{WebTransportDatagramsWritable/[[SendGroup]]}} and a higher
{{WebTransportDatagramsWritable/[[SendOrder]]}}, that are neither
[=WritableStream/Error | errored=] nor blocked by [=flow control=], have been sent.
Note: the default [=null sendGroup=] is a valid sendGroup.
# `WebTransportDatagramDuplexStream` Interface # {#datagram-duplex-stream}
A <dfn interface>WebTransportDatagramDuplexStream</dfn> is a generic duplex stream.
<pre class="idl">
[Exposed=(Window,Worker), SecureContext]
interface WebTransportDatagramDuplexStream {
WebTransportDatagramsWritable createWritable(
optional WebTransportSendOptions options = {});
readonly attribute ReadableStream readable;
readonly attribute unsigned long maxDatagramSize;
attribute unrestricted double? incomingMaxAge;
attribute unrestricted double? outgoingMaxAge;
attribute unsigned long incomingMaxBufferedDatagrams;
attribute unsigned long outgoingMaxBufferedDatagrams;
};
</pre>
## Internal slots ## {#datagram-duplex-stream-internal-slots}
A {{WebTransportDatagramDuplexStream}} object has the following internal slots.
<table class="data" dfn-for="WebTransportDatagramDuplexStream" dfn-type="attribute">
<thead>
<tr>
<th>Internal Slot
<th>Description (<em>non-normative</em>)
</tr>
</thead>
<tbody>
<tr>
<td><dfn>`[[Transport]]`</dfn>
<td class="non-normative">The {{WebTransport}} that owns this {{WebTransportDatagramDuplexStream}}.
</tr>
<tr>
<td><dfn>`[[Readable]]`</dfn>
<td class="non-normative">A {{ReadableStream}} for incoming datagrams.
</tr>
<tr>
<td><dfn>`[[ReadableType]]`</dfn>
<td class="non-normative">The {{ReadableStreamType}} used for incoming datagrams.
</tr>
<tr>
<td><dfn>`[[Writables]]`</dfn>
<td class="non-normative">An [=ordered set=] of {{WebTransportDatagramsWritable}} streams,
initially empty.
</tr>
<tr>
<td><dfn>`[[IncomingDatagramsQueue]]`</dfn>
<td class="non-normative">A queue of pairs of an incoming datagram and a timestamp.
</tr>
<tr>
<td><dfn>`[[IncomingDatagramsPullPromise]]`</dfn>
<td class="non-normative">A promise set by [=pullDatagrams=], to wait for an incoming datagram.
</tr>
<tr>
<td><dfn>`[[IncomingMaxBufferedDatagrams]]`</dfn>
<td class="non-normative">An {{unsigned long}} representing the
length of the incoming queue in number of datagrams, beyond which
datagrams are dropped from the head of the queue.
</tr>
<tr>
<td><dfn>`[[IncomingDatagramsExpirationDuration]]`</dfn>
<td class="non-normative">An {{unrestricted double}} representing the
expiration duration for incoming datagrams (in milliseconds), or null.
</tr>
<tr>
<td><dfn>`[[OutgoingMaxBufferedDatagrams]]`</dfn>
<td class="non-normative">An {{unsigned long}} representing the
length of the underlying sink's outgoing queue in number of datagrams,
beyond which backpressure is exerted.
</tr>
<tr>
<td><dfn>`[[OutgoingDatagramsExpirationDuration]]`</dfn>
<td class="non-normative">An {{unrestricted double}} value representing the
expiration duration for outgoing datagrams (in milliseconds), or null.
</tr>
<tr>
<td><dfn>`[[OutgoingMaxDatagramSize]]`</dfn>
<td class="non-normative">An integer representing the maximum size for an outgoing datagram.
<div class=note>
The maximum datagram size depends on the protocol that is in use.
In HTTP/3 [[WEB-TRANSPORT-HTTP3]], the value is related to the estimate of the
path <abbr title="Maximum Transmission Unit">MTU</abbr>,
which is reduced by some implementation-defined amount to account for any overheads.
In HTTP/2 [[WEB-TRANSPORT-HTTP2]], there is no equivalent limit.
As the processing of datagrams generally involves holding
the entire datagram in memory,
implementations will have limits on size.
A future protocol extension could enable the signaling of these size limits
for all protocol variants.
</div>
</tr>
</tbody>
</table>
The user agent MAY update {{[[OutgoingMaxDatagramSize]]}} for any {{WebTransport}} object whose
{{[[State]]}} is either `"connecting"` or `"connected"`.
<div algorithm="create datagrams duplex stream">
To <dfn export for="WebTransportDatagramDuplexStream" lt="create|creating">create</dfn> a
{{WebTransportDatagramDuplexStream}} given a {{WebTransport}} |transport|, a
|readable| and |readableType|, perform the following steps.
1. Let |stream| be a [=new=] {{WebTransportDatagramDuplexStream}}, with:
: {{WebTransportDatagramDuplexStream/[[Transport]]}}
:: |transport|
: {{WebTransportDatagramDuplexStream/[[Readable]]}}
:: |readable|
: {{WebTransportDatagramDuplexStream/[[ReadableType]]}}
:: |readableType|
: {{WebTransportDatagramDuplexStream/[[Writables]]}}
:: an empty [=ordered set=].
: {{[[IncomingDatagramsQueue]]}}
:: an empty queue
: {{[[IncomingDatagramsPullPromise]]}}
:: null
: {{[[IncomingMaxBufferedDatagrams]]}}
:: an [=implementation-defined=] value
: {{[[IncomingDatagramsExpirationDuration]]}}
:: null
: {{[[OutgoingMaxBufferedDatagrams]]}}
:: an [=implementation-defined=] value
<div class="note">
<p>This implementation-defined value should be tuned to ensure decent throughput, without
jeopardizing the timeliness of transmitted data.</p>
</div>
: {{[[OutgoingDatagramsExpirationDuration]]}}
:: null
: {{[[OutgoingMaxDatagramSize]]}}
:: an [=implementation-defined=] integer.
1. Return |stream|.
</div>
## Methods ## {#datagram-duplex-stream-methods}
: <dfn for="WebTransportDatagramDuplexStream" method>createWritable()</dfn>
:: Creates a {{WebTransportDatagramsWritable}}.
<div algorithm="createWritable">
When `createWritable()` method is called, the user agent MUST
run the following steps:
1. Let |transport| be {{WebTransport}} object associated with [=this=].
1. If |transport|.{{[[State]]}} is `"closed"` or `"failed"`,
[=throw=] an {{InvalidStateError}}.
1. Let |sendGroup| be {{WebTransportDatagramDuplexStream/createWritable(options)/options}}'s
{{WebTransportSendOptions/sendGroup}}.
1. If |sendGroup| is not null, and
|sendGroup|.{{WebTransportSendGroup/[[Transport]]}} is not
[=this=].{{WebTransportDatagramDuplexStream/[[Transport]]}}, [=throw=]
an {{InvalidStateError}}.
1. Let |sendOrder| be {{WebTransportDatagramDuplexStream/createWritable(options)/options}}'s
{{WebTransportSendOptions/sendOrder}}.
1. Return the result of [=WebTransportDatagramsWritable/creating=] a {{WebTransportDatagramsWritable}}
with |transport|, |sendGroup| and |sendOrder|.
</div>
## Attributes ## {#datagram-duplex-stream-attributes}
: <dfn for="WebTransportDatagramDuplexStream" attribute>readable</dfn>
:: The getter steps are:
1. Return [=this=].{{WebTransportDatagramDuplexStream/[[Readable]]}}.
: <dfn for="WebTransportDatagramDuplexStream" attribute>incomingMaxAge</dfn>
:: The getter steps are:
1. Return [=this=].{{[[IncomingDatagramsExpirationDuration]]}}.
:: The setter steps, given |value|, are:
1. If |value| is negative or NaN, [=throw=] a {{RangeError}}.
1. If |value| is `0`, set |value| to null.
1. Set [=this=].{{[[IncomingDatagramsExpirationDuration]]}} to |value|.
: <dfn for="WebTransportDatagramDuplexStream" attribute>maxDatagramSize</dfn>
:: The maximum size data that may be passed to a {{WebTransportDatagramsWritable}}.
The getter steps are to return [=this=].{{[[OutgoingMaxDatagramSize]]}}.
: <dfn for="WebTransportDatagramDuplexStream" attribute>outgoingMaxAge</dfn>
:: The getter steps are:
1. Return [=this=]'s {{[[OutgoingDatagramsExpirationDuration]]}}.
:: The setter steps, given |value|, are:
1. If |value| is negative or NaN, [=throw=] a {{RangeError}}.
1. If |value| is `0`, set |value| to null.
1. Set [=this=].{{[[OutgoingDatagramsExpirationDuration]]}} to |value|.
: <dfn for="WebTransportDatagramDuplexStream" attribute>incomingMaxBufferedDatagrams</dfn>
:: The getter steps are:
1. Return [=this=].{{[[IncomingMaxBufferedDatagrams]]}}.
:: The setter steps, given |value|, are:
1. If |value| is < `1`, set |value| to `1`.
1. Set [=this=].{{[[IncomingMaxBufferedDatagrams]]}} to |value|.
: <dfn for="WebTransportDatagramDuplexStream" attribute>outgoingMaxBufferedDatagrams</dfn>
:: The getter steps are:
1. Return [=this=].{{[[OutgoingMaxBufferedDatagrams]]}}.
:: The setter steps, given |value|, are:
1. If |value| is < `1`, set |value| to `1`.
1. Set [=this=].{{[[OutgoingMaxBufferedDatagrams]]}} to |value|.
## Procedures ## {#datagram-duplex-stream-procedures}
To <dfn>pullDatagrams</dfn>, given a {{WebTransport}} object |transport|, run these steps:
1. Let |datagrams| be |transport|.{{[[Datagrams]]}}.
1. Assert: |datagrams|.{{[[IncomingDatagramsPullPromise]]}} is null.
1. Let |queue| be |datagrams|.{{[[IncomingDatagramsQueue]]}}.
1. If |queue| is empty, then:
1. Set |datagrams|.{{[[IncomingDatagramsPullPromise]]}} to a new promise.
1. Return |datagrams|.{{[[IncomingDatagramsPullPromise]]}}.
1. Let |datagram| and |timestamp| be the result of [=dequeuing=] |queue|.
1. If |datagrams|.{{WebTransportDatagramDuplexStream/[[ReadableType]]}} is `"bytes"`, then:
1. If |datagrams|.{{WebTransportDatagramDuplexStream/[[Readable]]}}'s
[=ReadableStream/current BYOB request view=] is not null, then:
1. Let |view| be |datagrams|.{{WebTransportDatagramDuplexStream/[[Readable]]}}'s
[=ReadableStream/current BYOB request view=].
1. If |view|'s [=BufferSource/byte length=] is less than the size of |datagram|, return
[=a promise rejected with=] a {{RangeError}}.
1. Let |elementSize| be the element size specified in [=the typed array constructors table=] for
|view|.\[[TypedArrayName]]. If |view| does not have a \[[TypedArrayName]] internal slot
(i.e. it is a {{DataView}}), let |elementSize| be 0.
1. If |elementSize| is not 1, return [=a promise rejected with=] a {{TypeError}}.
1. [=ReadableStream/Pull from bytes=] |datagram| into
|datagrams|.{{WebTransportDatagramDuplexStream/[[Readable]]}}.
1. Otherwise:
1. Let |chunk| be a new {{Uint8Array}} object representing |datagram|.
1. [=ReadableStream/Enqueue=] |chunk| to
|transport|.{{[[Datagrams]]}}.{{WebTransportDatagramDuplexStream/[[Readable]]}}.
1. Return [=a promise resolved with=] undefined.
To <dfn>receiveDatagrams</dfn>, given a {{WebTransport}} object |transport|, run these steps:
1. Let |timestamp| be a timestamp representing now.
1. Let |queue| be |datagrams|.{{[[IncomingDatagramsQueue]]}}.
1. Let |duration| be |datagrams|.{{[[IncomingDatagramsExpirationDuration]]}}.
1. If |duration| is null, then set |duration| to an [=implementation-defined=] value.
1. Let |session| be |transport|.{{[[Session]]}}.
1. While there are [=session/receive a datagram|available incoming datagrams=] on |session|:
1. Let |datagram| be the result of [=session/receiving a datagram=] with |session|.
1. Let |timestamp| be a timestamp representing now.
1. Let |chunk| be a pair of |datagram| and |timestamp|.
1. [=queue/Enqueue=] |chunk| to |queue|.
1. Let |toBeRemoved| be the length of |queue| minus |datagrams|.{{[[IncomingMaxBufferedDatagrams]]}}.
1. If |toBeRemoved| is positive, repeat [=queue/dequeuing=] |queue| |toBeRemoved|
([rounded down](https://tc39.github.io/ecma262/#eqn-floor)) times.
1. While |queue| is not empty:
1. Let |bytes| and |timestamp| be |queue|'s first element.
1. If more than |duration| milliseconds have passed since |timestamp|, then [=queue/dequeue=] |queue|.
1. Otherwise, [=iteration/break=] this loop.
1. If |queue| is not empty and |datagrams|.{{[[IncomingDatagramsPullPromise]]}} is non-null, then:
1. Let |bytes| and |timestamp| be the result of [=queue/dequeuing=] |queue|.
1. Let |promise| be |datagrams|.{{[[IncomingDatagramsPullPromise]]}}.
1. Set |datagrams|.{{[[IncomingDatagramsPullPromise]]}} to null.
1. [=WebTransport/Queue a network task=] with |transport| to run the following steps:
1. Let |chunk| be a new {{Uint8Array}} object representing |bytes|.
1. [=ReadableStream/Enqueue=] |chunk| to |datagrams|.{{WebTransportDatagramDuplexStream/[[Readable]]}}.
1. [=Resolve=] |promise| with undefined.
The user agent SHOULD run [=receiveDatagrams=] for any {{WebTransport}} object whose
{{[[State]]}} is `"connected"` as soon as reasonably possible whenever the algorithm can make
progress.
# `WebTransport` Interface # {#web-transport}
`WebTransport` provides an API to the underlying transport functionality
defined in [[!WEB-TRANSPORT-OVERVIEW]].
<pre class="idl">
[Exposed=(Window,Worker), SecureContext]
interface WebTransport {
constructor(USVString url, optional WebTransportOptions options = {});
Promise<WebTransportConnectionStats> getStats();
[NewObject] Promise<Uint8Array> exportKeyingMaterial(BufferSource label, BufferSource context, unsigned long outputLength);
readonly attribute Promise<undefined> ready;
readonly attribute WebTransportReliabilityMode reliability;
readonly attribute WebTransportCongestionControl congestionControl;
attribute [EnforceRange] unsigned short? anticipatedConcurrentIncomingUnidirectionalStreams;
attribute [EnforceRange] unsigned short? anticipatedConcurrentIncomingBidirectionalStreams;
[SameObject] readonly attribute Headers? responseHeaders;
readonly attribute DOMString protocol;
readonly attribute Promise<WebTransportCloseInfo> closed;
readonly attribute Promise<undefined> draining;
undefined close(optional WebTransportCloseInfo closeInfo = {});
readonly attribute WebTransportDatagramDuplexStream datagrams;
Promise<WebTransportBidirectionalStream> createBidirectionalStream(
optional WebTransportSendStreamOptions options = {});
/* a ReadableStream of WebTransportBidirectionalStream objects */
readonly attribute ReadableStream incomingBidirectionalStreams;
Promise<WebTransportSendStream> createUnidirectionalStream(
optional WebTransportSendStreamOptions options = {});
/* a ReadableStream of WebTransportReceiveStream objects */
readonly attribute ReadableStream incomingUnidirectionalStreams;
WebTransportSendGroup createSendGroup();
static readonly attribute boolean supportsReliableOnly;
};
enum WebTransportReliabilityMode {
"pending",
"reliable-only",
"supports-unreliable",
};
</pre>
## Internal slots ## {#webtransport-internal-slots}
A {{WebTransport}} object has the following internal slots.
<table class="data" dfn-for="WebTransport" dfn-type="attribute">
<thead>
<tr>
<th>Internal Slot
<th>Description (<em>non-normative</em>)
</tr>
</thead>
<tbody>
<tr>
<td><dfn>`[[SendStreams]]`</dfn>
<td class="non-normative">An [=ordered set=] of {{WebTransportSendStream}}s owned by this {{WebTransport}}.
</tr>
<tr>
<td><dfn>`[[ReceiveStreams]]`</dfn>
<td class="non-normative">An [=ordered set=] of {{WebTransportReceiveStream}}s owned by this
{{WebTransport}}.
</tr>
<tr>
<td><dfn>`[[IncomingBidirectionalStreams]]`</dfn>
<td class="non-normative">A {{ReadableStream}} consisting of {{WebTransportBidirectionalStream}}
objects.
</tr>
<tr>
<td><dfn>`[[IncomingUnidirectionalStreams]]`</dfn>
<td class="non-normative">A {{ReadableStream}} consisting of {{WebTransportReceiveStream}}s.
</tr>
<tr>
<td><dfn>`[[State]]`</dfn>
<td class="non-normative">An enum indicating the state of the transport. One of `"connecting"`,
`"connected"`, `"draining"`, `"closed"`, and `"failed"`.
</tr>
<tr>
<td><dfn>`[[Ready]]`</dfn>
<td class="non-normative">A promise fulfilled when the associated [=WebTransport session=]
gets [=session/established=], or rejected if the [=session/establish|establishment process=]
failed.
</tr>
<tr>
<td><dfn>`[[Reliability]]`</dfn>
<td class="non-normative">A {{WebTransportReliabilityMode}} indicating whether
the first hop supports unreliable (UDP) transport or whether only reliable
(TCP fallback) transport is available. Returns `"pending"` until a connection
has been established.
</tr>
<tr>
<td><dfn>`[[CongestionControl]]`</dfn>
<td class="non-normative">A {{WebTransportCongestionControl}} indicating
whether a preference for a congestion control algorithm optimized for
throughput or low latency was requested by the application and satisfied
by the user agent, or `"default"`.
</tr>
<tr>
<td><dfn>`[[AnticipatedConcurrentIncomingUnidirectionalStreams]]`</dfn>
<td class="non-normative">The number of concurrently open
[=incoming unidirectional=] streams the application anticipates the server creating, or null.
</tr>
<tr>
<td><dfn>`[[AnticipatedConcurrentIncomingBidirectionalStreams]]`</dfn>
<td class="non-normative">The number of concurrently open
[=bidirectional=] streams the application anticipates the server creating, or null.
</tr>
<tr>
<td><dfn>`[[ResponseHeaders]]`</dfn>
<td class="non-normative">A {{Headers}} object or null. Initially null.
</tr>
<tr>
<td><dfn>`[[Protocol]]`</dfn>
<td class="non-normative">A string indicating the application-level protocol selected by the server,
if any. Initially an empty string.
</tr>
<tr>
<td><dfn>`[[Closed]]`</dfn>
<td class="non-normative">A promise fulfilled when the associated {{WebTransport}} object is
closed gracefully, or rejected when it is closed abruptly or failed on initialization.
</tr>
<tr>
<td><dfn>`[[Draining]]`</dfn>
<td class="non-normative">A promise fulfilled when the associated [=WebTransport session=]
starts [=session/draining=].
</tr>
<tr>
<td><dfn>`[[Datagrams]]`</dfn>
<td class="non-normative">A {{WebTransportDatagramDuplexStream}}.
</tr>
<tr>
<td><dfn>`[[Session]]`</dfn>
<td class="non-normative">A [=WebTransport session=] for this {{WebTransport}} object, or null.
</tr>
<tr>
<td><dfn>`[[NewConnection]]`</dfn>
<td class="non-normative">Either "`no`" or "`yes-and-dedicated`".
</tr>
<tr>
<td><dfn>`[[RequireUnreliable]]`</dfn>
<td class="non-normative">A boolean indicating whether UDP is required.
</tr>
</table>
## Constructor ## {#webtransport-constructor}
<div algorithm="webtransport-contructor">
When the {{WebTransport/constructor()}} constructor is invoked, the user
agent MUST run the following steps:
1. Let |baseURL| be [=this=]'s [=relevant settings object=]'s [=API base URL=].
1. Let |url| be the [=URL record=] resulting from [=URL parser|parsing=]
{{WebTransport/constructor(url, options)/url}} with |baseURL|.
1. If |url| is failure, [=throw=] a {{SyntaxError}} exception.
1. If |url|'s [=scheme=] is not `https`, [=throw=] a {{SyntaxError}} exception.
1. If |url|'s [=fragment=] is not null, [=throw=] a {{SyntaxError}} exception.
1. Let |newConnection| be "`no`" if {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/allowPooling}} is true; otherwise "`yes-and-dedicated`".
1. Let |serverCertificateHashes| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/serverCertificateHashes}}.
1. If |newConnection| is "`no`" and |serverCertificateHashes| [=set/is empty|is not empty=], then [=throw=] a
{{NotSupportedError}} exception.
1. Let |requireUnreliable| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/requireUnreliable}}.
1. Let |congestionControl| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/congestionControl}}.
1. If |congestionControl| is not `"default"`, and the user agent does not support any
congestion control algorithms that optimize for |congestionControl|, as allowed by
[[!RFC9002]] [Section 7](https://www.rfc-editor.org/rfc/rfc9002#section-7),
then set |congestionControl| to `"default"`.
1. Let |protocols| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/protocols}}.
1. If any of the values in |protocols| occur more than once, fail to match
the requirements for elements that comprise the value of the negotiated
application protocol as defined by the WebTransport protocol, or have an [=isomorphic encoded=]
length of 0 or exceeding 512, [=throw=] a {{SyntaxError}} exception.
[[!WEB-TRANSPORT-OVERVIEW]]
[Section 3.1](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-11/#section-3.1).
1. Let |anticipatedConcurrentIncomingUnidirectionalStreams| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/anticipatedConcurrentIncomingUnidirectionalStreams}}.
1. Let |anticipatedConcurrentIncomingBidirectionalStreams| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/anticipatedConcurrentIncomingBidirectionalStreams}}.
1. Let |datagramsReadableType| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/datagramsReadableType}}.
1. Let |incomingDatagrams| be a [=new=] {{ReadableStream}}.
1. Let |transport| be a newly constructed {{WebTransport}} object, with:
: {{[[SendStreams]]}}
:: an empty [=ordered set=]
: {{[[ReceiveStreams]]}}
:: an empty [=ordered set=]
: {{[[IncomingBidirectionalStreams]]}}
:: a new {{ReadableStream}}
: {{[[IncomingUnidirectionalStreams]]}}
:: a new {{ReadableStream}}
: {{[[State]]}}
:: `"connecting"`
: {{[[Ready]]}}
:: a new promise
: {{[[Reliability]]}}
:: "pending"
: {{[[CongestionControl]]}}
:: |congestionControl|
: {{[[AnticipatedConcurrentIncomingUnidirectionalStreams]]}}
:: |anticipatedConcurrentIncomingUnidirectionalStreams|
: {{[[AnticipatedConcurrentIncomingBidirectionalStreams]]}}
:: |anticipatedConcurrentIncomingBidirectionalStreams|
: {{[[ResponseHeaders]]}}
:: null
: {{[[Protocol]]}}
:: an empty string
: {{[[Closed]]}}
:: a new promise
: {{[[Draining]]}}
:: a new promise
: {{[[Datagrams]]}}
:: undefined
: {{[[Session]]}}
:: null
: {{[[NewConnection]]}}
:: |newConnection|
: {{[[RequireUnreliable]]}}
:: |requireUnreliable|
1. Set |transport|.{{[[Datagrams]]}} to the result of [=WebTransportDatagramDuplexStream/creating=]
a {{WebTransportDatagramDuplexStream}}, with |transport|, |incomingDatagrams| and
|datagramsReadableType|.
1. Let |pullDatagramsAlgorithm| be an action that runs [=pullDatagrams=] with |transport|.
Note: Using 64 kibibytes buffers with datagrams is recommended because the effective
maximum WebTransport datagram frame size has an upper bound of the QUIC maximum datagram frame size
which is recommended to be 64 kibibytes (See [[!QUIC-DATAGRAM]] [Section 3](https://datatracker.ietf.org/doc/html/rfc9221#section-3)).
This will ensure the stream is not errored due to a datagram being larger than the buffer.
1. If |datagramsReadableType| is `"bytes"`, [=ReadableStream/set up with byte reading support=]
|incomingDatagrams| with [=ReadableStream/set up with byte reading support/pullAlgorithm=] set
to |pullDatagramsAlgorithm|, and [=ReadableStream/set up with byte reading support/highWaterMark=]
set to 0. Otherwise, [=ReadableStream/set up=] |incomingDatagrams| with
[=ReadableStream/set up/pullAlgorithm=] set to |pullDatagramsAlgorithm|, and
[=ReadableStream/set up/highWaterMark=] set to 0.
1. Let |pullBidirectionalStreamAlgorithm| be an action that runs [=pullBidirectionalStream=]
with |transport|.
1. [=ReadableStream/Set up=] |transport|.{{[[IncomingBidirectionalStreams]]}} with
[=ReadableStream/set up/pullAlgorithm=] set to |pullBidirectionalStreamAlgorithm|, and
[=ReadableStream/set up/highWaterMark=] set to 0.
1. Let |pullUnidirectionalStreamAlgorithm| be an action that runs [=pullUnidirectionalStream=]
with |transport|.
1. [=ReadableStream/Set up=] |transport|.{{[[IncomingUnidirectionalStreams]]}} with
[=ReadableStream/set up/pullAlgorithm=] set to |pullUnidirectionalStreamAlgorithm|, and
[=ReadableStream/set up/highWaterMark=] set to 0.