-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.bs
3325 lines (2834 loc) · 146 KB
/
index.bs
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: Bernard Aboba, w3cid 65611, Microsoft Corporation
Editor: Nidhi Jaju, w3cid 136840, Google
Editor: Victor Vasiliev, w3cid 113328, Google
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-HTTP3]]
and [[!WEB-TRANSPORT-HTTP2]]. 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"
},
"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: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
</pre>
# Introduction # {#introduction}
*This section is non-normative.*
This specification uses [[!WEB-TRANSPORT-HTTP3]] and [[!WEB-TRANSPORT-HTTP2]] 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-06#name-datagrams)</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.2](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-06#section-4.2-6.2.1)
</tr>
<tr>
<td><dfn>receive a [datagram](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-06#name-datagrams)</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.2](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-06#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-06#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-06#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-06#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-06#section-4.3-7.8.1)
</tr>
</tbody>
</table>
To <dfn for=session>establish</dfn> a [=WebTransport session=] with an [=/origin=] |origin| and a
|protocols| array, follow [[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.1](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-06#section-4.1-2.2.1),
with using |origin|, [=ASCII serialization of an origin|serialized=] and [=isomorphic encoded=],
as the [:Origin:] header of the request.
When establishing a session, the client MUST NOT provide any [=credentials=].
The resulting underlying transport stream is referred to as the session's <dfn>CONNECT stream</dfn>.
Additionally, if the |protocols| array is non-empty,
add a `WT-Available-Protocols` header field to the CONNECT request, containing
[=isomorphic encoded=] protocols from |protocols| in the order given, following [[!WEB-TRANSPORT-HTTP3]]
[Section 3.4](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-3.4).
<div class="note">
This should reference [[!WEB-TRANSPORT-OVERVIEW]] instead pending
[issue 15](https://github.com/ietf-wg-webtrans/draft-ietf-webtrans-overview/issues/15).
</div>
A [=WebTransport session=] |session| is <dfn for=session>draining</dfn> when the
[=CONNECT stream=] receives an [=session-signal/DRAIN_WEBTRANSPORT_SESSION=] capsule, or when a
[=session-signal/GOAWAY=] frame is received, as described in [[!WEB-TRANSPORT-HTTP3]]
[Section 4.6](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.6).
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-06#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-06#section-4.1-4.2.1).
A [=WebTransport session=] has the following signals:
<table class="data" dfn-for="session-signal">
<thead>
<tr>
<th>event
<th>definition
</tr>
</thead>
<tbody>
<tr>
<td><dfn>DRAIN_WEBTRANSPORT_SESSION</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[Section 4.6](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.6)
</tr>
<tr>
<td><dfn>GOAWAY</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[Section 4.6](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.6)
</tr>
</tbody>
</table>
## 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-06#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>.
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-06#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-06#section-4.3-9.4.1)
<td>Yes
<td>No
<td>Yes
</tr>
<tr>
<td><dfn>send STOP_SENDING</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-06#section-4.3-9.8.1)
<td>Yes
<td>No
<td>Yes
</tr>
<tr>
<td><dfn>reset</dfn> a [=WebTransport stream=]
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-06#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>STOP_SENDING</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-06#section-4.3-9.8.1)
<td>No
<td>Yes
<td>Yes
</tr>
<tr>
<td><dfn>RESET_STREAM</dfn>
<td>[[!WEB-TRANSPORT-OVERVIEW]]
[Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview-06#section-4.3-9.6.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-06#section-4.3-5)
<td>No
<td>Yes
<td>Yes
</tr>
</tbody>
</table>
# `WebTransportDatagramDuplexStream` Interface # {#duplex-stream}
A <dfn interface>WebTransportDatagramDuplexStream</dfn> is a generic duplex stream.
<pre class="idl">
[Exposed=(Window,Worker), SecureContext]
interface WebTransportDatagramDuplexStream {
readonly attribute ReadableStream readable;
readonly attribute WritableStream writable;
readonly attribute unsigned long maxDatagramSize;
attribute unrestricted double? incomingMaxAge;
attribute unrestricted double? outgoingMaxAge;
attribute unrestricted double incomingHighWaterMark;
attribute unrestricted double outgoingHighWaterMark;
};
</pre>
## Internal slots ## {#datagramduplexstream-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>`[[Readable]]`</dfn>
<td class="non-normative">A {{ReadableStream}} for incoming datagrams.
</tr>
<tr>
<td><dfn>`[[Writable]]`</dfn>
<td class="non-normative">A {{WritableStream}} for outgoing datagrams.
</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>`[[IncomingDatagramsHighWaterMark]]`</dfn>
<td class="non-normative">An {{unrestricted double}} representing the
[=high water mark=] of the incoming datagrams.
</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>`[[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>`[[OutgoingDatagramsHighWaterMark]]`</dfn>
<td class="non-normative">An {{unrestricted double}} representing the
[=high water mark=] of the outgoing datagrams.
</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.
</tr>
</tbody>
</table>
The user agent MAY update {{[[OutgoingMaxDatagramSize]]}} for any {{WebTransport}} object whose
{{[[State]]}} is either `"connecting"` or `"connected"`.
To <dfn export for="WebTransportDatagramDuplexStream" lt="create|creating">create</dfn> a
{{WebTransportDatagramDuplexStream}} given a
<dfn export for="WebTransportDatagramDuplexStream/create"><var>readable</var></dfn>, and
a <dfn export for="WebTransportDatagramDuplexStream/create"><var>writable</var></dfn>,
perform the following steps.
1. Let |stream| be a [=new=] {{WebTransportDatagramDuplexStream}}, with:
: {{WebTransportDatagramDuplexStream/[[Readable]]}}
:: |readable|
: {{WebTransportDatagramDuplexStream/[[Writable]]}}
:: |writable|
: {{[[IncomingDatagramsQueue]]}}
:: an empty queue
: {{[[IncomingDatagramsPullPromise]]}}
:: null
: {{[[IncomingDatagramsHighWaterMark]]}}
:: an [=implementation-defined=] value
: {{[[IncomingDatagramsExpirationDuration]]}}
:: null
: {{[[OutgoingDatagramsQueue]]}}
:: an empty queue
: {{[[OutgoingDatagramsHighWaterMark]]}}
:: 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|.
## Attributes ## {#datagram-duplex-stream-attributes}
: <dfn for="WebTransportDatagramDuplexStream" attribute>readable</dfn>
:: The getter steps are:
1. Return [=this=].{{WebTransportDatagramDuplexStream/[[Readable]]}}.
: <dfn for="WebTransportDatagramDuplexStream" attribute>writable</dfn>
:: The getter steps are:
1. Return [=this=].{{WebTransportDatagramDuplexStream/[[Writable]]}}.
: <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 {{WebTransportDatagramDuplexStream/writable}}.
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>incomingHighWaterMark</dfn>
:: The getter steps are:
1. Return [=this=].{{[[IncomingDatagramsHighWaterMark]]}}.
:: The setter steps, given |value|, are:
1. If |value| is negative or NaN, [=throw=] a {{RangeError}}.
1. If |value| is < `1`, set |value| to `1`.
1. Set [=this=].{{[[IncomingDatagramsHighWaterMark]]}} to |value|.
: <dfn for="WebTransportDatagramDuplexStream" attribute>outgoingHighWaterMark</dfn>
:: The getter steps are:
1. Return [=this=].{{[[OutgoingDatagramsHighWaterMark]]}}.
:: The setter steps, given |value|, are:
1. If |value| is negative or NaN, [=throw=] a {{RangeError}}.
1. If |value| is < `1`, set |value| to `1`.
1. Set [=this=].{{[[OutgoingDatagramsHighWaterMark]]}} 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/[[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. 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|.{{[[IncomingDatagramsHighWaterMark]]}}.
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.
<div algorithm>
The <dfn>writeDatagrams</dfn> algorithm is given a |transport| as parameter 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 |datagrams|.{{[[OutgoingDatagramsQueue]]}}.
1. If the length of |datagrams|.{{[[OutgoingDatagramsQueue]]}} is less than
|datagrams|.{{[[OutgoingDatagramsHighWaterMark]]}}, 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=] 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|, run these steps:
1. Let |queue| be |datagrams|.{{[[OutgoingDatagramsQueue]]}}.
1. Let |duration| be |datagrams|.{{[[OutgoingDatagramsExpirationDuration]]}}.
1. If |duration| is null, then set |duration| to an [=implementation-defined=] value.
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. Let |maxSize| be |datagrams|.{{[[OutgoingMaxDatagramSize]]}}.
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 SHOULD run [=sendDatagrams=] for any {{WebTransport}} object whose
{{[[State]]}} is `"connecting"` or `"connected"` 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.
# `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();
readonly attribute Promise<undefined> ready;
readonly attribute WebTransportReliabilityMode reliability;
readonly attribute WebTransportCongestionControl congestionControl;
[EnforceRange] attribute unsigned short? anticipatedConcurrentIncomingUnidirectionalStreams;
[EnforceRange] attribute unsigned short? anticipatedConcurrentIncomingBidirectionalStreams;
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]]`</dsfn>
<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>`[[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=]
receives a [=session-signal/DRAIN_WEBTRANSPORT_SESSION=] capsule or a
[=session-signal/GOAWAY=] frame.
</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>
</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 |parsedURL| be the [=URL record=] resulting from [=URL parser|parsing=]
{{WebTransport/constructor(url, options)/url}} with |baseURL|.
1. If |parsedURL| is a failure, [=throw=] a {{SyntaxError}} exception.
1. If |parsedURL| [=scheme=] is not `https`, [=throw=] a {{SyntaxError}} exception.
1. If |parsedURL| [=fragment=] is not null, [=throw=] a {{SyntaxError}} exception.
1. Let |allowPooling| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/allowPooling}}.
1. Let |dedicated| be the negation of |allowPooling|.
1. Let |serverCertificateHashes| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/serverCertificateHashes}} if it exists, and null otherwise.
1. If |dedicated| is false and |serverCertificateHashes| is non-null, 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 `WT-Protocol`
fields as defined by the WebTransport protocol, or have an [=isomorphic encoded=]
length of 0 or exceeding 512, [=throw=] a {{SyntaxError}} exception.
[[!WEB-TRANSPORT-HTTP3]]
[Section 3.4](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-3.4).
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 |incomingDatagrams| be a [=new=] {{ReadableStream}}.
1. Let |outgoingDatagrams| be a [=new=] {{WritableStream}}.
1. Let |datagrams| be the result of [=WebTransportDatagramDuplexStream/creating=] a
{{WebTransportDatagramDuplexStream}}, its [=WebTransportDatagramDuplexStream/create/readable=] set to
|incomingDatagrams| and its [=WebTransportDatagramDuplexStream/create/writable=] set to |outgoingDatagrams|.
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|
: {{[[Protocol]]}}
:: an empty string
: {{[[Closed]]}}
:: a new promise
: {{[[Draining]]}}
:: a new promise
: {{[[Datagrams]]}}
:: |datagrams|
: {{[[Session]]}}
:: null
1. Let |pullDatagramsAlgorithm| be an action that runs [=pullDatagrams=] with |transport|.
1. Let |writeDatagramsAlgorithm| be an action that runs [=writeDatagrams=] with |transport|.
Note: Using 64kB 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 64kB (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. [=ReadableStream/Set up with byte reading support=] |incomingDatagrams| with
[=ReadableStream/set up with byte reading support/pullAlgorithm=] set to
|pullDatagramsAlgorithm|, and [=ReadableStream/set up/highWaterMark=] set to 0.
1. [=WritableStream/Set up=] |outgoingDatagrams| with [=WritableStream/set up/writeAlgorithm=]
set to |writeDatagramsAlgorithm|.
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.
1. [=Initialize WebTransport over HTTP=] with |transport|, |parsedURL|, |dedicated|,
|requireUnreliable|, |congestionControl|, |protocols|, and |serverCertificateHashes|.
1. Return |transport|.
</div>
<div algorithm>
To <dfn>initialize WebTransport over HTTP</dfn>, given a {{WebTransport}} object
<var>transport</var>, a [=URL record=] |url|, a boolean |dedicated|, a boolean
|requireUnreliable|, a {{WebTransportCongestionControl}} |congestionControl|,
a |protocols| array, and a
sequence<{{WebTransportHash}}> |serverCertificateHashes|, run these steps.
1. Let |client| be |transport|'s [=relevant settings object=].
1. Let |origin| be |client|'s [=environment settings object/origin=].
1. Let |request| be a new [=/request=] whose [=request/URL=] is |url|, [=request/client=] is
|client|, [=request/policy container=] is |client|'s
[=environment settings object/policy container=], [=request/destination=] is an empty string,
[=request/origin=] is |origin| and [=request/redirect mode=] is "error".
1. Run <a>report Content Security Policy violations for |request|</a>.
1. If [=should request be blocked by Content Security Policy?=] with |request| returns
<b>"Blocked"</b>, or if |request| [=block bad port|should be blocked due to a bad port=]
returns <b>blocked</b>, then abort the remaining steps and [=queue a network task=] with |transport|
to run these steps:
1. If |transport|.{{[[State]]}} is `"closed"` or `"failed"`, then abort these steps.
1. Let |error| be a newly [=DOMException/created=] {{WebTransportError}} whose
{{WebTransportErrorOptions/source}} is `"session"`.
1. [=Cleanup=] |transport| with |error|.
1. Let |networkPartitionKey| be the result of [=determining the network partition key=] with
|transport|'s [=relevant settings object=].
1. Run the following steps [=in parallel=], but [=abort when=] |transport|.{{[[State]]}} becomes `"closed"` or `"failed"`:
1. Let |newConnection| be "`no`" if |dedicated| is false; otherwise "`yes-and-dedicated`".
1. Let |connection| be the result of [=obtain a connection|obtaining a connection=] with
|networkPartitionKey|, |url|, false, |newConnection|, and |requireUnreliable|. If the user agent
supports more than one congestion control algorithm, choose one appropriate for
|congestionControl| for sending of data on this |connection|. When obtaining a connection, if
|serverCertificateHashes| is specified, instead of using the default certificate verification
algorithm, consider the certificate valid if it meets the [=custom certificate
requirements=] and if [=verify a certificate hash|verifying the certificate hash=] against
|serverCertificateHashes| returns true. If either condition is not met, let |connection| be
failure.
1. If |connection| is failure, then abort the remaining steps and [=queue a network task=] with
|transport| to run these steps:
1. If |transport|.{{[[State]]}} is `"closed"` or `"failed"`, then abort these steps.
1. Let |error| be a newly [=DOMException/created=] {{WebTransportError}} whose
{{WebTransportErrorOptions/source}} is `"session"`.
1. [=Cleanup=] |transport| with |error|.
Note: Redirects are not followed. Network errors caused by redirection are intentionally
indistinguishable from other network errors. In cross-origin contexts, this would reveal
information that would normally be blocked by CORS. In same-origin contexts, it might
encourage applications to abuse the handshake as a vector for passing information.
1. Wait for |connection| to receive the first SETTINGS frame, and let |settings| be a dictionary that
represents the SETTINGS frame.
1. If |settings| doesn't contain SETTINGS_ENABLE_WEBTRANPORT with a value of 1, or it doesn't
contain H3_DATAGRAM with a value of 1, then abort the remaining steps and [=queue a network
task=] with |transport| to run these steps:
1. If |transport|.{{[[State]]}} is `"closed"` or `"failed"`, then abort these steps.
1. Let |error| be a newly [=DOMException/created=] {{WebTransportError}} whose
{{WebTransportErrorOptions/source}} is `"session"`.
1. [=Cleanup=] |transport| with |error|.
1. [=session/Establish=] a [=WebTransport session=] with |origin| and |protocols| on |connection|.
Note: This step also contains the transport parameter exchange specified in [[!QUIC-DATAGRAM]].
1. If the previous step fails, abort the remaining steps and [=queue a network task=] with
|transport| to run these steps:
1. If |transport|.{{[[State]]}} is `"closed"` or `"failed"`, then abort these steps.
1. Let |error| be a newly [=DOMException/created=] {{WebTransportError}} whose
{{WebTransportErrorOptions/source}} is `"session"`.
1. [=Cleanup=] |transport| with |error|.
1. Let |session| be the established [=WebTransport session=].
1. Assert: |maxDatagramSize| is an integer.
1. [=Queue a network task=] with |transport| to run these steps:
1. If |transport|.{{[[State]]}} is not `"connecting"`:
1. [=In parallel=], [=session/terminate=] |session|.
1. Abort these steps.
1. Set |transport|.{{[[State]]}} to `"connected"`.
1. Set |transport|.{{[[Session]]}} to |session|.
1. Set |transport|.{{[[Protocol]]}} to either the string value of the `WT-Protocol` header field
in the 2xx response to the CONNECT request if present, following [[!WEB-TRANSPORT-HTTP3]]
[Section 3.4](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-3.4),
or `""` if not present.
<div class="note">
This should reference [[!WEB-TRANSPORT-OVERVIEW]] instead pending
[issue 15](https://github.com/ietf-wg-webtrans/draft-ietf-webtrans-overview/issues/15).
</div>
1. If the connection is an HTTP/3 connection, set |transport|.{{[[Reliability]]}} to `"supports-unreliable"`.
1. If the connection is an HTTP/2 connection [[!WEB-TRANSPORT-HTTP2]], set |transport|'s {{[[Reliability]]}} to `"reliable-only"`.
1. [=Resolve=] |transport|.{{[[Ready]]}} with undefined.
</div>
<div algorithm="pullBidirectionalStream">
To <dfn>pullBidirectionalStream</dfn>, given a {{WebTransport}} object <var>transport</var>, run
these steps.
1. If |transport|.{{[[State]]}} is `"connecting"`, then return the result of performing the
following steps [=upon fulfillment=] of |transport|.{{[[Ready]]}}:
1. Return the result of [=pullBidirectionalStream=] with |transport|.
1. If |transport|.{{[[State]]}} is not `"connected"`, then return a new [=rejected=] promise with
an {{InvalidStateError}}.
1. Let |session| be |transport|.{{[[Session]]}}.
1. Let |p| be a new promise.
1. Run the following steps [=in parallel=]:
1. Wait until there is an [=session/receive a bidirectional stream|available incoming bidirectional
stream=].
1. Let |internalStream| be the result of [=session/receiving a bidirectional stream=].
1. [=Queue a network task=] with |transport| to run these steps:
1. Let |stream| be the result of [=BidirectionalStream/creating=] a
{{WebTransportBidirectionalStream}} with |internalStream| and |transport|.
1. [=ReadableStream/Enqueue=] |stream| to |transport|.{{[[IncomingBidirectionalStreams]]}}.
1. [=Resolve=] |p| with undefined.
1. Return |p|.
</div>
<div algorithm>
To <dfn>pullUnidirectionalStream</dfn>, given a {{WebTransport}} object <var>transport</var>, run
these steps.
1. If |transport|.{{[[State]]}} is `"connecting"`, then return the result of performing the
following steps [=upon fulfillment=] of |transport|.{{[[Ready]]}}:
1. Return the result of [=pullUnidirectionalStream=] with |transport|.
1. If |transport|.{{[[State]]}} is not `"connected"`, then return a new [=rejected=] promise with
an {{InvalidStateError}}.
1. Let |session| be |transport|.{{[[Session]]}}.
1. Let |p| be a new promise.
1. Run the following steps [=in parallel=]:
1. Wait until there is an
[=session/receive an incoming unidirectional stream|available incoming unidirectional stream=].
1. Let |internalStream| be the result of [=session/receiving an incoming unidirectional stream=].
1. [=Queue a network task=] with |transport| to run these steps:
1. Let |stream| be the result of [=WebTransportReceiveStream/creating=] a {{WebTransportReceiveStream}} with
|internalStream| and |transport|.
1. [=ReadableStream/Enqueue=] |stream| to |transport|.{{[[IncomingUnidirectionalStreams]]}}.
1. [=Resolve=] |p| with undefined.
1. Return |p|.
</div>
## Attributes ## {#webtransport-attributes}
: <dfn for="WebTransport" attribute>ready</dfn>
:: On getting, it MUST return [=this=]'s {{[[Ready]]}}.
: <dfn for="WebTransport" attribute>closed</dfn>
:: On getting, it MUST return [=this=]'s {{[[Closed]]}}.
: <dfn for="WebTransport" attribute>draining</dfn>
:: On getting, it MUST return [=this=]'s {{[[Draining]]}}.
: <dfn for="WebTransport" attribute>datagrams</dfn>
:: A single duplex stream for sending and receiving datagrams over this session.
The getter steps for the `datagrams` attribute SHALL be:
1. Return [=this=]'s {{[[Datagrams]]}}.
: <dfn for="WebTransport" attribute>incomingBidirectionalStreams</dfn>
:: Returns a {{ReadableStream}} of {{WebTransportBidirectionalStream}}s that have been
received from the server.
Note: Whether the incoming streams already have data on them will depend on server behavior.
The getter steps for the `incomingBidirectionalStreams` attribute SHALL be: