Instance properties
incomingHighWaterMark-
Gets or sets the high water mark for incoming chunks of data — this is the maximum size, in chunks, that the incoming
ReadableStream's internal queue can reach before it is considered full. See Internal queues and queuing strategies for more information. incomingMaxAge-
Gets or sets the maximum age for incoming datagrams, in milliseconds. Returns
nullif no maximum age has been set. maxDatagramSizeRead only-
Returns the maximum allowable size of outgoing datagrams, in bytes, that can be written to a
WebTransportDatagramsWritableobtained viacreateWritable(), or the deprecatedwritableproperty. outgoingHighWaterMark-
Gets or sets the high water mark for outgoing chunks of data — this is the maximum size, in chunks, that the outgoing
WritableStream's internal queue can reach before it is considered full. See Internal queues and queuing strategies for more information. outgoingMaxAge-
Gets or sets the maximum age for outgoing datagrams, in milliseconds. Returns
nullif no maximum age has been set. readableRead only-
Returns a
ReadableStreaminstance that can be used to read incoming datagrams from the stream. writableRead only-
Returns a
WritableStreaminstance that can be used to write outgoing datagrams to the stream.
Instance methods
createWritable()-
Returns a
WebTransportDatagramsWritableinstance that can be used to write outgoing datagrams to the stream.
Examples
Writing outgoing datagrams
This code uses the createWritable() method, if it is supported, to get a WebTransportDatagramsWritable instance that can be used for writing data to the transport.
Otherwise, it falls back to the writable property , which returns a WritableStream object that you can write data to using a writer instead:
js
const writableStream =
typeof transport.datagrams.createWritable === "function"
? transport.datagrams.createWritable()
: transport.datagrams.writable; // Deprecated and non-standard
const writer = writableStream.getWriter();
const data1 = new Uint8Array([65, 66, 67]);
const data2 = new Uint8Array([68, 69, 70]);
await writer.ready;
writer.write(data1);
await writer.ready;
writer.write(data2);
Reading incoming datagrams
The readable property returns a ReadableStream object that you can use to receive data from the server:
js
async function readData() {
const reader = transport.datagrams.readable.getReader();
while (true) {
const { value, done } = await reader.read();
if (done) {
break;
}
// value is a Uint8Array.
console.log(value);
}
}
Specifications
| Specification |
|---|
| WebTransport # webtransportdatagramduplexstream |