web api instance method
WebTransportSendStream: getWriter() method
Secure context Available in 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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.