forked from w3c/webtransport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.bs
2034 lines (1719 loc) · 82.5 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: Victor Vasiliev, w3cid 113328,Google
Editor: Yutaka Hirano, w3cid 100504,Google
Former Editor: Peter Thatcher, Google
Former Editor: Robin Raymond, Optical Tone Ltd.
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]].
This specification is being developed in conjunction with a protocol
specification 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://tools.ietf.org/html/draft-ietf-quic-transport",
"title": "QUIC: A UDP-Based Multiplexed and Secure Transport",
"status": "Internet-Draft",
"publisher": "IETF"
},
"quic-datagram": {
"authors": ["Tommy Pauly", "Eric Kinnear", "David Schinazi"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-quic-datagram/",
"title": "An Unreliable Datagram Extension to QUIC",
"status": "Internet-Draft",
"publisher": "IETF"
},
"http3-datagram": {
"authors": ["David Schinazi", "Lucas Pardue"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-masque-h3-datagram",
"title": "Using QUIC Datagrams with HTTP/3",
"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-quic": {
"authors": ["Victor Vasiliev"],
"href": "https://datatracker.ietf.org/doc/html/draft-vvv-webtransport-quic",
"title": "WebTransport over QUIC",
"status": "Internet-Draft",
"publisher": "IETF"
},
"web-transport-http3": {
"authors": ["Victor Vasiliev"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/",
"title": "WebTransport over HTTP/3",
"status": "Internet-Draft",
"publisher": "IETF"
}
}
</pre>
<pre class="link-defaults">
spec:streams; type:interface; text:ReadableStream
spec:html; type:dfn; for:/; text:origin
spec:fetch; type:dfn; for:/; text:fetch
spec:url; type:dfn; text:scheme
spec:url; type:dfn; text:fragment
</pre>
<pre class="anchors">
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
urlPrefix: https://heycam.github.io/webidl/; spec: WEBIDL
type: dfn
text: new DOMException(message, name); for:DOMException; url: dom-domexception-domexception
</pre>
# Introduction # {#introduction}
*This section is non-normative.*
This specification uses [[!WEB-TRANSPORT-HTTP3]] 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]]
specification is 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* and *SHOULD* are to be interpreted as described in
[[!RFC2119]].
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.
# Terminology # {#terminology}
The {{EventHandler}} interface, representing a callback used for event
handlers, and the {{ErrorEvent}} interface are defined in [[!HTML]].
The concepts [=queue a task=] and [=networking task source=] are defined in
[[!HTML]].
The terms [=event=], [=event handlers=] and [=event handler event types=] are
defined in [[!HTML]].
When referring to exceptions, the terms [=throw=] and [=create=] are defined in
[[!WEBIDL]].
The terms [=fulfilled=], [=rejected=], [=resolved=], [=pending=] and
[=settled=] used in the context of Promises are defined in [[!ECMASCRIPT-6.0]].
The terms {{ReadableStream}} and {{WritableStream}} are defined in
[[!WHATWG-STREAMS]].
# Protocol concepts # {#protocol-concepts}
A <dfn for="protocol">WebTransport session</dfn> is a session of WebTransport over HTTP/3.
There may be multiple [=WebTransport sessions=] on one [=connection=], when pooling is enabled.
[=WebTransport session=] has the following capabilities defined in [[!WEB-TRANSPORT-HTTP3]].
<table class="data" dfn-for="session">
<thead>
<tr>
<th>capability
<th>definition
</tr>
</thead>
<tbody>
<tr>
<td><dfn>send a datagram</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.4](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.4)
</tr>
<tr>
<td><dfn>receive a datagram</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.4](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.4)
</tr>
<tr>
<td><dfn>create an [=stream/outgoing unidirectional=] stream</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.1](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.1)
</tr>
<tr>
<td><dfn>create a [=stream/bidirectional=] stream</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.2](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.2)
</tr>
<tr>
<td><dfn>receive an [=stream/incoming unidirectional=] stream</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.1](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.1)
</tr>
<tr>
<td><dfn>receive a [=stream/bidirectional=] stream</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.2](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.2)
</tr>
</tbody>
</table>
To <dfn for=session>establish</dfn> a [=WebTransport session=], follow [[!WEB-TRANSPORT-HTTP3]]
[section 3.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-3.3).
To <dfn for=session>terminate</dfn> a [=WebTransport session=] |session| with an optional integer
|code| and an optional [=byte sequence=] |reason|, follow [[!WEB-TRANSPORT-HTTP3]]
[section 5](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-5).
A [=WebTransport session=] |session| is <dfn for=session>terminated</dfn>, with optionally
an integer |code| and a [=byte sequence=] |reason|, when the HTTP/3 stream associated with the
CONNECT request that initiated |session| is closed by the server, as described at
[[!WEB-TRANSPORT-HTTP3]]
[section 5](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-5).
<dfn>WebTransport stream</dfn> is a concept for HTTP/3 stream on a [=WebTransport session=].
A [=WebTransport stream=] is one of <dfn for=stream>incoming unidirectional</dfn>,
<dfn for=stream>outgoing unidirectional</dfn> or <dfn for=stream>bidirectional</dfn>.
[=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>[[!QUIC]]
[section 2.2](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport#section-2.2)
<td>No
<td>Yes
<td>Yes
</tr>
<tr>
<td><dfn>receive</dfn> bytes (potentially with FIN)
<td>[[!QUIC]]
[section 2.2](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport#section-2.2)
<td>Yes
<td>No
<td>Yes
</tr>
<tr>
<td><dfn>send STOP_SENDING</dfn>
<td>[[!QUIC]]
[section 3.5](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport#section-3.5)
<td>Yes
<td>No
<td>Yes
</tr>
<tr>
<td><dfn>reset</dfn> a [=WebTransport stream=]
<td>[[!QUIC]]
[section 19.4](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport#section-19.4)
<td>No
<td>Yes
<td>Yes
</tr>
</tbody>
</table>
[=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>[[!QUIC]]
[section 3.5](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport#section-3.5)
<td>No
<td>Yes
<td>Yes
</tr>
<tr>
<td><dfn>reset</dfn>
<td>[[!QUIC]]
[section 19.4](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport#section-19.4)
<td>Yes
<td>No
<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 double? incomingMaxAge;
attribute double? outgoingMaxAge;
attribute long incomingHighWaterMark;
attribute long outgoingHighWaterMark;
};
</pre>
## Internal slots ## {#datagramduplexstream-internal-slots}
A {{WebTransportDatagramDuplexStream}} object has the following internal slots.
<table class="data" dfn-for="DatagramDuplexStream">
<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 integer representing the [=high water mark=] of the incoming
datagrams.
</tr>
<tr>
<td><dfn>\[[IncomingDatagramsExpirationDuration]]</dfn>
<td class="non-normative">A {{double}} value 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 integer representing the [=high water mark=] of the outgoing
datagrams.
</tr>
<tr>
<td><dfn>\[[OutgoingDatagramsExpirationDuration]]</dfn>
<td class="non-normative">A {{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="DatagramDuplexStream" lt="create|creating">create</dfn> a
{{WebTransportDatagramDuplexStream}} given a
<dfn export for="DatagramDuplexStream/create"><var>readable</var></dfn>, and
a <dfn export for="DatagramDuplexStream/create"><var>writable</var></dfn>,
perform the following steps.
1. Let |stream| be a [=new=] {{WebTransportDatagramDuplexStream}}, with:
: [=[[Readable]]=]
:: |readable|
: [=[[Writable]]=]
:: |writable|
: [=[[IncomingDatagramsQueue]]=]
:: an empty queue
: [=[[IncomingDatagramsPullPromise]]=]
:: null
: [=[[IncomingDatagramsHighWaterMark]]=]
:: an [=implementation-defined=] integer
: [=[[IncomingDatagramsExpirationDuration]]=]
:: null
: [=[[OutgoingDatagramsQueue]]=]
:: an empty queue
: [=[[OutgoingDatagramsHighWaterMark]]=]
:: an [=implementation-defined=] integer
<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=].`[[Readable]]`.
: <dfn for="WebTransportDatagramDuplexStream" attribute>writable</dfn>
:: The getter steps are:
1. Return [=this=].`[[Writable]]`.
: <dfn for="WebTransportDatagramDuplexStream" attribute>incomingMaxAge</dfn>
:: The getter steps are:
1. Return [=this=]'s [=[[IncomingDatagramsExpirationDuration]]=].
:: The setter steps are:
1. Let |value| be the given value.
1. If |value| is null or |value| > 0:
1. Set [=this=]'s [=[[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=]'s [=[[Datagrams]]=]'s [=[[OutgoingMaxDatagramSize]]=].
: <dfn for="WebTransportDatagramDuplexStream" attribute>outgoingMaxAge</dfn>
:: The getter steps are:
1. Return [=this=]'s [=[[OutgoingDatagramsExpirationDuration]]=].
:: The setter steps are:
1. Let |value| be the given value.
1. If |value| is null or |value| > 0:
1. Set [=this=]'s [=[[OutgoingDatagramsExpirationDuration]]=] to |value|.
: <dfn for="WebTransportDatagramDuplexStream" attribute>incomingHighWaterMark</dfn>
:: The getter steps are:
1. Return [=this=]'s [=[[IncomingDatagramsHighWaterMark]]=].
:: The setter steps are:
1. Let |value| be the given value.
1. If |value| ≥ 0:
1. Set [=this=]'s [=[[IncomingDatagramsHighWaterMark]]=] to |value|.
: <dfn for="WebTransportDatagramDuplexStream" attribute>outgoingHighWaterMark</dfn>
:: The getter steps are:
1. Return [=this=]'s [=[[OutgoingDatagramsHighWaterMark]]=].
:: The setter steps are:
1. Let |value| be the given value.
1. If |value| ≥ 0:
1. Set [=this=]'s [=[[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|'s [=[[Datagrams]]=].
1. Assert: |datagrams|'s [=[[IncomingDatagramsPullPromise]]=] is null.
1. Let |queue| be |datagrams|'s [=[[IncomingDatagramsQueue]]=].
1. If |queue| is empty, then:
1. Set |datagrams|'s [=[[IncomingDatagramsPullPromise]]=] to a new promise.
1. Return |datagrams|'s [=[[IncomingDatagramsPullPromise]]=].
1. Let |bytes| and |timestamp| be the result of [=dequeuing=] |queue|.
1. Let |chunk| be a new {{Uint8Array}} object representing |bytes|.
1. [=ReadableStream/Enqueue=] |chunk| to |transport|'s [=[[Datagrams]]=]' s
[=DatagramDuplexStream/[[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|'s [=[[IncomingDatagramsQueue]]=].
1. Let |duration| be |datagrams|'s [=[[IncomingDatagramsExpirationDuration]]=].
1. If |duration| is null, then set |duration| to an [=implementation-defined=] value.
1. Let |session| be |transport|'s [=[[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. [=Enqueue=] |chunk| to |queue|.
1. Let |toBeRemoved| be the length of |queue| minus |datagrams|'s
[=[[IncomingDatagramsHighWaterMark]]=].
1. If |toBeRemoved| is positive, repeat [=dequeuing=] |queue| |toBeRemoved| 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 [=dequeue=] |queue|.
1. Otherwise, [=break=] this loop.
1. If |queue| is not empty and |datagrams|'s [=[[IncomingDatagramsPullPromise]]=] is non-null, then:
1. Let |bytes| and |timestamp| be the result of [=dequeuing=] |queue|.
1. Let |promise| be |datagrams|'s [=[[IncomingDatagramsPullPromise]]=].
1. Set |datagrams|'s [=[[IncomingDatagramsPullPromise]]=] to null.
1. [=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|'s [=DatagramDuplexStream/[[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|'s [=[[Datagrams]]=].
1. If |datagrams|'s [=[[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|'s [=[[OutgoingDatagramsQueue]]=].
1. If the length of |datagrams|'s [=[[OutgoingDatagramsQueue]]=] is less than
|datagrams|'s [=[[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|'s [=[[OutgoingDatagramsQueue]]=].
1. Let |duration| be |datagrams|'s [=[[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|'s [=[[State]]=] is not `"connected"`, then return.
1. Let |maxSize| be |datagrams|'s [=[[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|'s [=[[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 [=[[OutgoingDatagramsExpirationDuration]]=], and they can be discarded
in the same manner as the `"connected"` case. Once the transport's [=[[State]]=] becomes
`"connected"`, it will start sending stored datagrams.
# `WebTransport` Interface # {#web-transport}
`WebTransport` provides an API to the HTTP/3 transport functionality
defined in [[!WEB-TRANSPORT-HTTP3]].
<pre class="idl">
[Exposed=(Window,Worker), SecureContext]
interface WebTransport {
constructor(USVString url, optional WebTransportOptions options = {});
Promise<WebTransportStats> getStats();
readonly attribute Promise<undefined> ready;
readonly attribute Promise<WebTransportCloseInfo> closed;
undefined close(optional WebTransportCloseInfo closeInfo = {});
readonly attribute WebTransportDatagramDuplexStream datagrams;
Promise<WebTransportBidirectionalStream> createBidirectionalStream();
/* a ReadableStream of WebTransportBidirectionalStream objects */
readonly attribute ReadableStream incomingBidirectionalStreams;
Promise<WritableStream> createUnidirectionalStream();
/* a ReadableStream of ReceiveStreams */
readonly attribute ReadableStream incomingUnidirectionalStreams;
};
</pre>
## Internal slots ## {#webtransport-internal-slots}
A {{WebTransport}} object has the following internal slots.
<table class="data" dfn-for="WebTransport">
<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 {{SendStream}}s owned by this {{WebTransport}}.
</tr>
<tr>
<td><dfn>\[[ReceiveStreams]]</dfn>
<td class="non-normative">An [=ordered set=] of {{ReceiveStream}}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 {{ReceiveStream}}s.
</tr>
<tr>
<td><dfn>\[[State]]</dfn>
<td class="non-normative">An enum indicating the state of the transport. One of `"connecting"`,
`"connected"`, `"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>\[[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>\[[Datagrams]]</dfn>
<td class="non-normative">A {{WebTransportDatagramDuplexStream}}.
</tr>
<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 |parsedURL| be the [=URL record=] resulting from [=URL parser|parsing=]
{{WebTransport/constructor(url, options)/url}}.
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}} if it exists, and false otherwise.
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
{{TypeError}}.
1. Let |incomingDatagrams| be a [=new=] {{ReadableStream}}.
1. Let |outgoingDatagrams| be a [=new=] {{WritableStream}}.
1. Let |datagrams| be the result of [=DatagramDuplexStream/creating=] a
{{WebTransportDatagramDuplexStream}}, its [=DatagramDuplexStream/create/readable=] set to
|incomingDatagrams| and its [=DatagramDuplexStream/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
: [=[[Closed]]=]
:: 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|.
1. [=ReadableStream/Set up=] |incomingDatagrams| with [=ReadableStream/set up/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|'s [=[[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|'s [=[[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| and |dedicated|.
1. Return |transport|.
</div>
<div algorithm>
To <dfn>initialize WebTransport over HTTP</dfn>, given a {{WebTransport}} object
<var>transport</var>, a [=URL record=] |url|, and a boolean |dedicated|, run these steps.
1. Let |networkPartitionKey| be the result of [=determining the network partition key=] with
|transport|'s [=relevant settings object=].
1. Run the remaining steps [=in parallel=], but abort them whenever |transport|'s
[=[[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 with [=obtain a connection/http3Only=]
set to true.
1. If |connection| is failure, then abort the remaining steps and [=queue a network task=] with
|transport| to run these steps:
1. If |transport|'s [=[[State]]=] is `"closed"` or `"failed"`, then abort these steps.
1. Let |error| be the result of [=WebTransportError/creating=] a {{WebTransportError}} with
`"session"`.
1. [=Cleanup=] |transport| with |error|, |error| and true.
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|'s [=[[State]]=] is `"closed"` or `"failed"`, then abort these steps.
1. Let |error| be the result of [=WebTransportError/creating=] a {{WebTransportError}} with
`"session"`.
1. [=Cleanup=] |transport| with |error|, |error| and true.
1. [=session/Establish=] a [=WebTransport session=] 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|'s [=[[State]]=] is `"closed"` or `"failed"`, then abort these steps.
1. Let |error| be the result of [=WebTransportError/creating=] a {{WebTransportError}} with
`"session"`.
1. [=Cleanup=] |transport| with |error|, |error| and true.
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|'s [=[[State]]=] is not `"connecting"`:
1. [=In parallel=], [=session/terminate=] |session|.
1. Abort these steps.
1. Set |transport|'s [=[[State]]=] to `"connected"`.
1. Set |transport|'s [=[[Session]]=] to |session|.
1. [=Resolve=] |transport|'s [=[[Ready]]=] with undefined.
</div>
<div algorithm="pullBidirectionalStream">
To <dfn>pullBidirectionalStream</dfn>, given a {{WebTransport}} object <var>transport</var>, run
these steps.
1. If |transport|'s [=[[State]]=] is `"connecting"`, then return the result of performing the
following steps [=upon fulfillment=] of |transport|'s [=[[Ready]]=]:
1. Return the result of [=pullBidirectionalStream=] with |transport|.
1. Let |session| be |transport|'s [=[[Session]]=].
1. Let |p| be a new promise.
1. Return |p| and run the remaining 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|'s [=[[IncomingBidirectionalStreams]]=].
1. [=Resolve=] |p| with undefined.
</div>
<div algorithm>
To <dfn>pullUnidirectionalStream</dfn>, given a {{WebTransport}} object <var>transport</var>, run
these steps.
1. If |transport|'s [=[[State]]=] is `"connecting"`, then return the result of performing the
following steps [=upon fulfillment=] of |transport|'s [=[[Ready]]=]:
1. Return the result of [=pullUnidirectionalStream=] with |transport|.
1. Let |session| be |transport|'s [=[[Session]]=].
1. Let |p| be a new promise.
1. Return |p| and run the remaining 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 [=ReceiveStream/creating=] a {{ReceiveStream}} with
|internalStream| and |transport|.
1. [=ReadableStream/Enqueue=] |stream| to |transport|'s [=[[IncomingUnidirectionalStreams]]=].
1. [=Resolve=] |p| with undefined.
</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]]=].
:: This promise MUST be [=resolved=] when the transport is closed; an
implementation SHOULD include error information in the `reason` and
`closeCode` fields of {{WebTransportCloseInfo}}.
: <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.
The getter steps for the `incomingBidirectionalStreams` attribute SHALL be:
1. Return [=this=]'s [=[[IncomingBidirectionalStreams]]=].
: <dfn for="WebTransport" attribute>incomingUnidirectionalStreams</dfn>
:: A {{ReadableStream}} of unidirectional streams, each represented by a
{{ReceiveStream}}, that have been received from the server.
The getter steps for `incomingUnidirectionalStreams` are:
1. Return [=this=]'s [=[[IncomingUnidirectionalStreams]]=].
## Methods ## {#webtransport-methods}
<div algorithm>
: <dfn for="WebTransport" method>close(closeInfo)</dfn>
:: Terminates the [=WebTransport session=] associated with the WebTransport object.
When close is called, the user agent MUST run the following steps:
1. Let |transport| be [=this=].
1. If |transport|'s [=[[State]]=] is `"closed"` or `"failed"`, then abort these steps.
1. If |transport|'s [=[[State]]=] is `"connecting"`:
1. Let |error| be the result of [=WebTransportError/creating=] a {{WebTransportError}} with
`"session"`.
1. [=Cleanup=] |transport| with |error|, |error| and true.
1. Abort these steps.
1. Let |session| be |transport|'s [=[[Session]]=].
1. Let |reason| be an empty [=byte sequence=].
1. If |closeInfo|.{{WebTransportCloseInfo/reason}} exists, set |reason| be
|closeInfo|.{{WebTransportCloseInfo/reason}}, [=UTF-8 encoded=].
1. If |reason|'s [=byte sequence/length=] exceeds 1024, then set |reason| to a
[=byte sequence/prefix=] of |reason| whose length is 1024.
1. If |closeInfo|.{{WebTransportCloseInfo/closeCode}} exists:
1. [=In parallel=], [=session/terminate=] |session| with
|closeInfo|.{{WebTransportCloseInfo/closeCode}} and |reason|.
1. Otherwise:
1. [=In parallel=], [=session/terminate=] |session|.
Note: This also [=resets=] or [=sends STOP_SENDING=] [=WebTransport streams=] contained in
|transport|'s [=[[SendStreams]]=] and [=[[ReceiveStreams]]=].
1. [=Cleanup=] |transport| with |closeInfo|, an {{AbortError}} and false.
</div>
: <dfn for="WebTransport" method>getStats()</dfn>
:: Gathers stats for this {{WebTransport}}'s HTTP/3
connection and reports the result asynchronously.</p>
When getStats is called, the user agent MUST run the following steps:
1. Let |transport| be [=this=].
1. Let |p| be a new promise.
1. If the URL scheme associated with |transport| is not `https`,
[=reject=] |p| with {{NotSupportedError}} and return |p|.
1. Return |p| and continue the following steps [=in parallel=].
1. Gather the stats from the underlying QUIC connection.
1. Wait for the stats to be ready.
1. [=Queue a network task=] with |transport| to run the following steps:
1. Let |stats| be a [=new=] {{WebTransportStats}} object representing the gathered stats.
1. [=Resolve=] |p| with |stats|.
: <dfn for="WebTransport" method>createBidirectionalStream()</dfn>
:: Creates a {{WebTransportBidirectionalStream}} object for an outgoing bidirectional
stream. Note that the mere creation of a stream is not immediately visible to the peer until
it is used to send data.
When `createBidirectionalStream` is called, the user agent MUST run the
following steps:
1. Let |transport| be [=this=].
1. If |transport|'s [=WebTransport/[[State]]=] is `"closed"` or `"failed"`,
return a new [=rejected=] promise with an {{InvalidStateError}}.
1. Let |p| be a new promise.
1. Run the following steps [=in parallel=], but abort them whenever |transport|'s
[=WebTransport/[[State]]=] becomes `"closed"` or `"failed"`, and instead
[=queue a network task=] with |transport| to [=reject=] |p| with an {{InvalidStateError}}.
1. Wait for |transport|'s [=WebTransport/[[State]]=] to be `"connected"`.
1. Let |internalStream| be the result of [=creating a bidirectional stream=] with
|transport|'s [=[[Session]]=].
Note: This operation may take time, for example when the stream ID is exhausted. [[!QUIC]]
1. [=Queue a network task=] with |transport| to run the following steps:
1. If |transport|'s [=WebTransport/[[State]]=] is `"closed"` or `"failed"`,
[=reject=] |p| with an {{InvalidStateError}} and abort these steps.
1. Let |stream| be the result of [=BidirectionalStream/creating=] a
{{WebTransportBidirectionalStream}} with |internalStream| and |transport|.
1. [=Resolve=] |p| with |stream|.
1. return |p|.
: <dfn for="WebTransport" method>createUnidirectionalStream()</dfn>
:: Creates a {{SendStream}} for an outgoing unidirectional stream. Note
that the mere creation of a stream is not immediately visible to the server until it is used
to send data.
When `createUnidirectionalStream()` method is called, the user agent MUST
run the following steps:
1. Let |transport| be [=this=].
1. If |transport|'s [=WebTransport/[[State]]=] is `"closed"` or `"failed"`,
return a new [=rejected=] promise with an {{InvalidStateError}}.
1. Let |p| be a new promise.
1. Run the following steps [=in parallel=], but abort them whenever |transport|'s
[=WebTransport/[[State]]=] becomes `"closed"` or `"failed"`, and instead
[=queue a network task=] with |transport| to [=reject=] |p| with an {{InvalidStateError}}.
1. Wait for |transport|'s [=WebTransport/[[State]]=] to be `"connected"`.
1. Let |internalStream| be the result of [=creating an outgoing unidirectional stream=] with
|transport|'s [=[[Session]]=].
Note: This operation may take time, for example when the stream ID is exhausted. [[!QUIC]]
1. [=Queue a network task=] with |transport| to run the following steps:
1. If |transport|'s [=WebTransport/[[State]]=] is `"closed"` or `"failed"`,
[=reject=] |p| with an {{InvalidStateError}} and abort these steps.
1. Let |stream| be the result of [=SendStream/creating=] a {{SendStream}} with
|internalStream| and |transport|.
1. [=Resolve=] |p| with |stream|.
1. return |p|.
## Procedures ## {#webtransport-procedures}
<div algorithm="cleanup a WebTransport">
To <dfn for="WebTransport">cleanup</dfn> a {{WebTransport}} |transport| with |reason|,
|error| and a boolean |abruptly|, run these steps:
1. Let |sendStreams| be a copy of |transport|'s [=[[SendStreams]]=].
1. Let |receiveStreams| be a copy of |transport|'s [=[[ReceiveStreams]]=].
1. Let |ready| be |transport|'s [=[[Ready]]=].
1. Let |closed| be |transport|'s [=[[Closed]]=].
1. Let |incomingBidirectionalStreams| be |transport|'s [=[[IncomingBidirectionalStreams]]=].
1. Let |incomingUnidirectionalStreams| be |transport|'s [=[[IncomingUnidirectionalStreams]]=].
1. Set |transport|'s [=[[SendStreams]]=] to an empty [=set=].
1. Set |transport|'s [=[[ReceiveStreams]]=] to an empty [=set=].
1. If |abruptly| is true, then set |transport|'s [=[[State]]=] to `"failed"`.
1. Otherwise, set |transport|'s [=[[State]]=] to `"closed"`.
1. [=For each=] |sendStream| in |sendStreams|, [=WritableStream/error=] |sendStream| with |error|.
1. [=For each=] |receiveStream| in |receiveStreams|, [=ReadableStream/error=] |receiveStream|
with |error|.
Note: Script authors can inject code which runs in Promise resolution synchronously. Hence
from here, do not touch |transport| as it may be mutated by scripts in an unpredictable way.
This applies to logic calling this procedure, too.
1. If |abruptly| is true, then:
1. [=Reject=] |closed| with |error|.
1. [=Reject=] |ready| with |error|.
1. [=ReadableStream/Error=] |incomingBidirectionalStreams| with |error|.
1. [=ReadableStream/Error=] |incomingUnidirectionalStreams| with |error|.
1. Otherwise:
1. [=Resolve=] |closed| with |reason|.
1. Assert: |ready| is [=settled=].
1. [=ReadableStream/Close=] |incomingBidirectionalStreams|.
1. [=ReadableStream/Close=] |incomingUnidirectionalStreams|.
</div>
<div algorithm>
To <dfn for="WebTransport">queue a network task</dfn> with a {{WebTransport}} |transport| and a
series of steps |steps|, run these steps:
1. [=Queue a global task=] on the [=network task source=] with |transport|'s
[=relevant global object=] to run |steps|.
</div>
## Session termination not initiated by the client ## {#web-transport-termination}
<div algorithm="termination-initiated-by-server">
Whenever a [=WebTransport session=] which is associated with a {{WebTransport}} |transport| is
[=session/terminated=] with optionally |code| and |reasonBytes|, run these steps:
1. Let |cleanly| be a boolean representing whether the HTTP/3 stream associated with the CONNECT
request that initiated |transport|'s [=[[Session]]=] is in the "Data Recvd" state. [[!QUIC]]
1. [=Queue a network task=] with |transport| to run these steps:
1. If |transport|'s [=[[State]]=] is `"closed"` or `"failed"`, abort these steps.
1. Let |error| be the result of [=WebTransportError/creating=] a {{WebTransportError}} with
`"session"`.
1. Let |reason| be |error|.
1. If |cleanly| is true:
1. Set |reason| to a [=new=] {{WebTransportCloseInfo}}.
1. If |code| is given, set |reason|'s {{WebTransportCloseInfo/closeCode}} to |code|.
1. If |reasonBytes| is given, set |reason|'s {{WebTransportCloseInfo/reason}} to |reasonBytes|,
[=UTF-8 decoded=].
1. [=Cleanup=] |transport| with |reason|, |error| and the negation of |cleanly|.
</div>
<div algorithm="termination-caused-by-connection-error">
Whenever a [=connection=] associated with a {{WebTransport}} |transport| gets a connection error,
run these steps:
1. [=Queue a network task=] with |transport| to run these steps:
1. If |transport|'s [=[[State]]=] is `"closed"` or `"failed"`, abort these steps.
1. Let |error| be the result of [=WebTransportError/creating=] a {{WebTransportError}} with
`"session"`.
1. [=Cleanup=] |transport| with |error|, |error| and true.
</div>