WebTransportSession class

Manages the state of a single WebTransport session over HTTP/3.

A WebTransportSession represents one WebTransport session mapped onto a QUIC bidirectional stream (the session's control stream). Per RFC 9220, endpoints exchange typed capsules on this stream to open streams, send datagrams, drain, or close the session.

The session tracks incoming capsules via onCapsuleReceived, surfacing registered stream IDs and received datagrams. Callers can initiate a graceful close with initiateClose, or send a drain signal with initiateDrain.

Example

final session = WebTransportSession(0);

// Process an incoming datagram WebTransportCapsule.
session.onCapsuleReceived(WebTransportCapsule(
  type: CapsuleType.datagram,
  payload: Uint8List.fromList([1, 2, 3]),
));
print('Datagrams: ${session.receivedDatagrams.length}');

// Gracefully close the session with an error code.
final closeCapsule = session.initiateClose(
  errorCode: 0,
  reasonPhrase: 'done',
);
print('Session closed: ${session.isClosed}');

See also:

  • Http3Connection — the HTTP/3 layer that carries WebTransport capsules.
  • WebTransportCapsule — a typed WebTransportCapsule exchanged on the session's control stream.
  • RFC 9220 — WebTransport over HTTP/3.

Constructors

WebTransportSession(int _sessionId)
Creates a WebTransport session identified by sessionId.

Properties

hashCode int
The hash code for this object.
no setterinherited
isActive bool
Whether the session is still active (not draining and not closed).
no setter
isClosed bool
Whether the session is fully closed.
no setter
isDraining bool
Whether the peer has initiated a drain.
no setter
receivedDatagrams List<Uint8List>
Datagrams received via CapsuleType.datagram capsules.
no setter
receivedGoaway bool
Whether a GOAWAY WebTransportCapsule has been received from the peer.
no setter
registeredBidirectionalStreams List<int>
Bidirectional stream IDs registered by the peer.
no setter
registeredUnidirectionalStreams List<int>
Unidirectional stream IDs registered by the peer.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sessionId int
The QUIC stream ID that serves as this session's identifier.
no setter

Methods

initiateClose({int errorCode = 0, String? reasonPhrase}) WebTransportCapsule
Initiate a graceful close of this session.
initiateDrain() WebTransportCapsule
Initiate a drain of this session.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onCapsuleReceived(WebTransportCapsule capsule) → void
Handle an incoming WebTransportCapsule on the session's control stream.
onCloseAcknowledged() → void
Called when the locally-initiated CLOSE has been acknowledged.
sendDatagram(Uint8List data) WebTransportCapsule
Send a datagram via a WebTransportCapsule of type CapsuleType.datagram.
sendGoaway({int? streamId}) GoawayCapsule
Send a GOAWAY WebTransportCapsule to signal that no new sessions will be accepted.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited