Abstract
Whether this stream is inbound or outbound
Unique identifier for a stream. Identifiers are not unique across muxers.
If no data is transmitted over the stream in this many ms, the stream will be aborted with an InactivityTimeoutError
Readonly
logA logging implementation that can be used to log stream-specific messages
Optional
maxThe maximum number of bytes to store when paused. If receipt of more bytes from the remote end of the stream causes the buffer size to exceed this value the stream will be reset and a 'close' event emitted.
This value can be changed at runtime.
Optional
maxWhen the .send
method returns false it means that the underlying resource
has signalled that it's write buffer is full. If the user continues to call
.send
, outgoing bytes are stored in an internal buffer until the
underlying resource signals that it can accept more data.
If the size of that internal buffer exceed this value the stream will be reset and a 'close' event emitted.
This value can be changed at runtime.
The protocol negotiated for this stream
Protected
Readonly
readAny data stored here is emitted before any new incoming data.
This is used when the stream is paused or if data is pushed onto the stream
The status of the readable end of the stream
The status of the readable end of the remote end of the stream - n.b. this requires the underlying stream transport to support sending STOP_SENDING messages or similar.
The status of the writable end of the remote end of the stream
Protected
sendingThe current status of the message stream
Readonly
timelineTimestamps of when stream events occurred
If this property is true
, the underlying transport has signalled that its
write buffer is full and that .send
should not be called again.
A drain
event will be emitted after which is its safe to call .send
again to resume sending.
Protected
Readonly
writeThe status of the writable end of the stream
Returns the number of bytes that are queued to be read
Returns the number of bytes that are queued to be written
Close immediately for reading and writing and send a reset message (local error)
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
Optional
options: boolean | AddEventListenerOptionsOptional
options: boolean | AddEventListenerOptionsStop accepting new data to send and return a promise that resolves when any unsent data has been written into the underlying resource.
Optional
options: AbortOptionsSend a message to the remote end of the stream informing them that any incoming data will be discarded so they should stop sending.
This requires the underlying resource to support this operation - for example the QUIC, WebTransport, WebRTC transports do but anything multiplexed using Yamux or Mplex do not.
Optional
options: AbortOptionsDispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
Protected
dispatchWhen an extending class reads data from it's implementation-specific source, call this method to allow the stream consumer to read the data.
Returns a promise that resolves when the stream can accept new data or rejects if the stream is closed or reset before this occurs.
Optional
options: AbortOptionsCalled by extending classes when the remote closes its readable end
Called by extending classes when the remote closes its writable end
Receive a reset message - close immediately for reading and writing (remote error)
The underlying resource or transport this stream uses has closed - it is not possible to send any more messages though any data still in the read buffer may still be read
Optional
err: ErrorStop emitting further 'message' events. Any received data will be stored in
an internal buffer. If the buffer size reaches maxReadBufferLength
, the
stream will be reset and a StreamAbortEvent emitted.
If the underlying resource supports it, the remote peer will be instructed to pause transmission of further data.
Protected
processQueue the passed data to be emitted as a 'message' event either during the next tick or sooner if data is received from the underlying resource.
Removes the event listener in target's event listener list with the same type, callback, and options.
Optional
listener: null | EventHandler<MessageStreamEvents[K]>Optional
options: boolean | EventListenerOptionsResume emitting 'message' events.
If the underlying resource supports it, the remote peer will be informed that it is ok to start sending data again.
Optional
detail: CustomEventInit<Detail>Write data to the stream. If the method returns false it means the internal buffer is now full and the caller should wait for the 'drain' event before sending more data.
This method may throw if:
Abstract
sendIf supported, send a message to the remote end of the stream, informing them that we will read no more data messages.
Optional
options: AbortOptionsAbstract
sendSend a message to the remote end of the stream, informing them that we will send no more data messages.
Optional
options: AbortOptionsAbstract
sendSend a data message to the remote end of the stream. Implementations of this method should return the number of bytes from the passed buffer that were sent successfully and if the underlying resource can accept more data.
The implementation should always attempt to send the maximum amount of data possible.
Returning a result that means the data was only partially sent but that the underlying resource can accept more data is invalid.
Abstract
sendIf supported, instruct the remote end of the stream to temporarily stop sending data messages
Abstract
sendAbstract
sendIf supported, inform the remote end of the stream they may resume sending data messages
Similar to the .push
method, except this ensures the passed data is
emitted before any other queued data.
A Stream is a lightweight data channel between two peers that can be written to and read from at both ends.
It is half-closable - that is in order for it to be closed fully and any associated memory reclaimed, both ends must close their writeable end of the stream.
It's also possible to close the readable end of the stream, but this depends on the underlying stream muxer supporting this operation which not all do.