WebTransportSendStream: getWriter() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The getWriter() method of the WebTransportSendStream interface returns a new WebTransportWriter object and locks the stream to that instance. While the stream is locked, no other writer can be acquired until this one is released.
WebTransportWriter is a subclass of WritableStreamDefaultWriter that additionally provides the atomicWrite() and commit() methods.
Syntax
getWriter()
Parameters
None.
Return value
A WebTransportWriter object instance.
Exceptions
TypeError-
The stream is already locked to another writer.
Examples
The following example shows how to open a unidirectional stream over a WebTransport connection and use getWriter() to write chunks of data to it.
const transport = new WebTransport("https://example.com/webtransport");
await transport.ready;
const stream = await transport.createUnidirectionalStream();
const writer = stream.getWriter();
const encoder = new TextEncoder();
await writer.write(encoder.encode("Hello"));
await writer.write(encoder.encode(", world!"));
await writer.close();
Specifications
| Specification |
|---|
| WebTransport> # dom-webtransportsendstream-getwriter> |