Table of Contents

Class WebTransport

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The WebTransport interface of the {{domxref("WebTransport API", "WebTransport API", "", "nocode")}} provides functionality to enable a user agent to connect to an HTTP/3 server, initiate reliable and unreliable transport in either or both directions, and close the connection once it is no longer needed.

[Value("WebTransport")]
public class WebTransport
Inheritance
WebTransport
Inherited Members

Remarks

-Using WebTransport
-{{domxref("WebSockets API", "WebSockets API", "", "nocode")}}
-{{domxref("Streams API", "Streams API", "", "nocode")}}
-WebTransport over HTTP/3

See also on MDN

Constructors

WebTransport()

public WebTransport()

WebTransport(string, WebTransportOptions)

The WebTransport() constructor creates a new WebTransport object instance.

public WebTransport(string url, WebTransportOptions options = null)

Parameters

url string
options WebTransportOptions

Remarks

-Using WebTransport
-{{domxref("WebSockets API", "WebSockets API", "", "nocode")}}
-{{domxref("Streams API", "Streams API", "", "nocode")}}
-WebTransport over HTTP/3

See also on MDN

Properties

AnticipatedConcurrentIncomingBidirectionalStreams

[Value("anticipatedConcurrentIncomingBidirectionalStreams")]
public ushort? AnticipatedConcurrentIncomingBidirectionalStreams { get; set; }

Property Value

ushort?

AnticipatedConcurrentIncomingUnidirectionalStreams

[Value("anticipatedConcurrentIncomingUnidirectionalStreams")]
public ushort? AnticipatedConcurrentIncomingUnidirectionalStreams { get; set; }

Property Value

ushort?

Closed

The closed read-only property of the WebTransport interface returns a promise that resolves when the transport is closed.

[Value("closed")]
public Task<WebTransportCloseInfo> Closed { get; }

Property Value

Task<WebTransportCloseInfo>

A Promise that resolves to an object containing the following properties:Or, in the case of an unexpected closure, such as network failure, the promise rejects with an error.

Remarks

This promise is created when the WebTransport object is created and is resolved when the transport is closed in any way, such as by calling the Close(WebTransportCloseInfo) method, when the connection failed, or when the connection is closed by the server. Accessing or awaiting this promise does not trigger any action; it only allows actions to be taken when the transport is closed, similar to listening to an event.

-Using WebTransport
-{{domxref(&quot;WebSockets API&quot;, &quot;WebSockets API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-{{domxref(&quot;Streams API&quot;, &quot;Streams API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-WebTransport over HTTP/3

See also on MDN

CongestionControl

NOTE
Experimental
The congestionControl read-only property of the WebTransport interface indicates the application's preference for either high throughput or low-latency when sending data.
[Value("congestionControl")]
public WebTransportCongestionControl CongestionControl { get; }

Property Value

WebTransportCongestionControl

A string with one of the following values:

Remarks

Datagrams

The datagrams read-only property of the WebTransport interface returns a WebTransportDatagramDuplexStream instance that can be used to send and receive datagrams — unreliable data transmission.

[Value("datagrams")]
public WebTransportDatagramDuplexStream Datagrams { get; }

Property Value

WebTransportDatagramDuplexStream

A WebTransportDatagramDuplexStream object.

Remarks

&quot;Unreliable&quot; means that transmission of data is not guaranteed, nor is arrival in a specific order. This is fine in some situations and provides very fast delivery. For example, you might want to transmit regular game state updates where each message supersedes the last one that arrives, and order is not important.

-Using WebTransport
-{{domxref(&quot;WebSockets API&quot;, &quot;WebSockets API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-{{domxref(&quot;Streams API&quot;, &quot;Streams API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-WebTransport over HTTP/3

See also on MDN

Draining

[Value("draining")]
public Task<GlobalObject.Undefined> Draining { get; }

Property Value

Task<GlobalObject.Undefined>

IncomingBidirectionalStreams

The incomingBidirectionalStreams read-only property of the WebTransport interface represents one or more bidirectional streams opened by the server. Returns a ReadableStream of WebTransportBidirectionalStream objects. Each one can be used to reliably read data from the server and write data back to it.

[Value("incomingBidirectionalStreams")]
public ReadableStream IncomingBidirectionalStreams { get; }

Property Value

ReadableStream

A ReadableStream of WebTransportBidirectionalStream objects.

Remarks

"Reliable" means that transmission and order of data are guaranteed. This provides slower delivery (albeit faster than with WebSockets) than Datagrams, but is needed in situations where reliability and ordering are important, like chat applications.

-Using WebTransport
-{{domxref(&quot;WebSockets API&quot;, &quot;WebSockets API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-{{domxref(&quot;Streams API&quot;, &quot;Streams API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-WebTransport over HTTP/3

See also on MDN

IncomingUnidirectionalStreams

The incomingUnidirectionalStreams read-only property of the WebTransport interface represents one or more unidirectional streams opened by the server. Returns a ReadableStream of WebTransportReceiveStream objects. Each one can be used to reliably read data from the server.

[Value("incomingUnidirectionalStreams")]
public ReadableStream IncomingUnidirectionalStreams { get; }

Property Value

ReadableStream

A ReadableStream of WebTransportReceiveStream objects.

Remarks

"Reliable" means that transmission and order of data are guaranteed. This provides slower delivery (albeit faster than with WebSockets) than Datagrams, but is needed in situations where reliability and ordering are important, like chat applications.

-Using WebTransport
-{{domxref(&quot;WebSockets API&quot;, &quot;WebSockets API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-{{domxref(&quot;Streams API&quot;, &quot;Streams API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-WebTransport over HTTP/3

See also on MDN

Protocol

[Value("protocol")]
public string Protocol { get; }

Property Value

string

Ready

The ready read-only property of the WebTransport interface returns a promise that resolves when the transport is ready to use.

[Value("ready")]
public Task<GlobalObject.Undefined> Ready { get; }

Property Value

Task<GlobalObject.Undefined>

A Promise that resolves to undefined.

Remarks

This promise is created when the WebTransport object is created and is resolved when a connection is established. Accessing or awaiting this promise does not trigger any action; it only allows actions to be taken when the transport is ready, similar to listening to an event.

-Using WebTransport
-{{domxref(&quot;WebSockets API&quot;, &quot;WebSockets API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-{{domxref(&quot;Streams API&quot;, &quot;Streams API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-WebTransport over HTTP/3

See also on MDN

Reliability

NOTE
Experimental
The reliability read-only property of the WebTransport interface indicates whether the connection supports reliable transports only, or whether it also supports unreliable transports (such as UDP).
[Value("reliability")]
public WebTransportReliabilityMode Reliability { get; }

Property Value

WebTransportReliabilityMode

A string with one of the following values:

Remarks

SupportsReliableOnly

[Value("supportsReliableOnly")]
public static bool SupportsReliableOnly { get; }

Property Value

bool

Methods

Close(WebTransportCloseInfo)

The close() method of the WebTransport interface closes an ongoing WebTransport session.

[Value("close")]
public GlobalObject.Undefined Close(WebTransportCloseInfo closeInfo = null)

Parameters

closeInfo WebTransportCloseInfo

Returns

GlobalObject.Undefined

undefined.

Remarks

-Using WebTransport
-{{domxref(&quot;WebSockets API&quot;, &quot;WebSockets API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-{{domxref(&quot;Streams API&quot;, &quot;Streams API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-WebTransport over HTTP/3

See also on MDN

CreateBidirectionalStream(WebTransportSendStreamOptions)

The createBidirectionalStream() method of the WebTransport interface asynchronously opens and returns a bidirectional stream.

[Value("createBidirectionalStream")]
public Task<WebTransportBidirectionalStream> CreateBidirectionalStream(WebTransportSendStreamOptions options = null)

Parameters

options WebTransportSendStreamOptions

Returns

Task<WebTransportBidirectionalStream>

A {{jsxref("Promise")}} that resolves to a WebTransportBidirectionalStream object.

Remarks

The method returns a {{jsxref("Promise")}} that resolves to a WebTransportBidirectionalStream object, which has readable and writable properties that can be used to reliably read from and write to the server.
&quot;Reliable&quot; means that transmission and order of data are guaranteed.
This provides slower delivery (albeit faster than with WebSockets) than Datagrams, but is needed in situations where reliability and ordering are important, like chat applications.

The relative order in which queued bytes are emptied from created streams can be specified using the sendOrder option.
If set, queued bytes in streams with a higher send order are guaranteed to be sent before queued bytes for streams with a lower send order.
If the order number is not set then the order in which bytes are sent is implementation dependent.
Note however that even though bytes from higher send-order streams are sent first, they may not arrive first.

-Using WebTransport
-CreateUnidirectionalStream(WebTransportSendStreamOptions)
-{{domxref(&quot;WebSockets API&quot;, &quot;WebSockets API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-{{domxref(&quot;Streams API&quot;, &quot;Streams API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-WebTransport over HTTP/3

See also on MDN

CreateSendGroup()

[Value("createSendGroup")]
public WebTransportSendGroup CreateSendGroup()

Returns

WebTransportSendGroup

CreateUnidirectionalStream(WebTransportSendStreamOptions)

The createUnidirectionalStream() method of the WebTransport interface asynchronously opens a unidirectional stream.

[Value("createUnidirectionalStream")]
public Task<WebTransportSendStream> CreateUnidirectionalStream(WebTransportSendStreamOptions options = null)

Parameters

options WebTransportSendStreamOptions

Returns

Task<WebTransportSendStream>

A Promise that resolves to a WebTransportSendStream object (this is a WritableStream).

Remarks

The method returns a {{jsxref("Promise")}} that resolves to a WritableStream object, which can be used to reliably write data to the server.

"Reliable" means that transmission and order of data are guaranteed. This provides slower delivery (albeit faster than with WebSockets) than Datagrams, but is needed in situations where reliability and ordering are important, like chat applications.

The relative order in which queued bytes are emptied from created streams can be specified using the sendOrder option.
If set, queued bytes in streams with a higher send order are guaranteed to be sent before queued bytes for streams with a lower send order.
If the order number is not set then the order in which bytes are sent is implementation dependent.
Note however that even though bytes from higher send-order streams are sent first, they may not arrive first.

-Using WebTransport
-CreateBidirectionalStream(WebTransportSendStreamOptions)
-{{domxref(&quot;WebSockets API&quot;, &quot;WebSockets API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-{{domxref(&quot;Streams API&quot;, &quot;Streams API&quot;, &quot;&quot;, &quot;nocode&quot;)}}
-WebTransport over HTTP/3

See also on MDN

GetStats()

NOTE
Experimental
The getStats() method of the WebTransport interface asynchronously returns an object containing HTTP/3 connection statistics.
[Value("getStats")]
public Task<WebTransportConnectionStats> GetStats()

Returns

Task<WebTransportConnectionStats>

A Promise that resolves to a object containing HTTP/3 connection statistics.
The returned object may have the following properties/statistics:

Remarks