Class WebSocketStream

Hierarchy

  • StartStop
    • WebSocketStream

Implements

  • ReadableWritablePair<Uint8Array, Uint8Array>

Constructors

Properties

[initLock]: RWLockWriter
_readClosed: boolean = false
_writeClosed: boolean = false
closedP: Promise<void>

Resolved when the stream has been completely closed (both readable and writable sides).

codeToReason: StreamCodeToReason
encodedStreamId: Uint8Array
initiated: "local" | "peer"
logger: Logger
readable: ReadableStream<Uint8Array>

Errors:

  • errors.ErrorWebSocketStreamClose - This will happen if the stream is closed with stop or if the WebSocketConnection was closed.
  • errors.ErrorWebSocketStreamCancel - This will happen if the stream is closed with cancel
  • errors.ErrorWebSocketStreamUnknown - Unknown error
  • errors.ErrorWebSocketStreamReadableBufferOverload - This will happen when the readable buffer is overloaded
  • errors.ErrorWebSocketStreamReadableParse - This will happen when the ReadableStream cannot parse an incoming message
  • any errors from .cancel(reason)
readableController: ReadableStreamDefaultController<any>
readableQueue: WebSocketStreamQueue = ...
readableQueueBufferSize: number = 0
reasonToCode: StreamReasonToCode
rejectReadableP?: ((reason?: any) => void)

Type declaration

    • (reason?: any): void
    • Parameters

      • Optional reason: any

      Returns void

rejectWritableP?: ((reason?: any) => void)

Type declaration

    • (reason?: any): void
    • Parameters

      • Optional reason: any

      Returns void

resolveClosedP: (() => void)

Type declaration

    • (): void
    • Returns void

resolveReadableP?: (() => void)

Type declaration

    • (): void
    • Returns void

resolveWritableP?: (() => void)

Type declaration

    • (): void
    • Returns void

streamId: VarInt
writable: WritableStream<Uint8Array>

Errors:

  • errors.ErrorWebSocketStreamClose - This will happen if the stream is closed with stop or if the WebSocketConnection was closed.
  • errors.ErrorWebSocketStreamCancel - This will happen if the stream is closed with cancel
  • errors.ErrorWebSocketStreamUnknown - Unknown error
  • errors.ErrorWebSocketStreamReadableBufferOverload - This will happen when the receiving ReadableStream's buffer is overloaded
  • errors.ErrorWebSocketStreamReadableParse - This will happen when the receiving ReadableStream cannot parse a sent message
  • any errors from .cancel(reason) or .abort(reason)
writableController: WritableStreamDefaultController
writableDesiredSize: number = 0

Accessors

  • get [eventHandled](): ReadonlyWeakSet<Event>
  • Returns ReadonlyWeakSet<Event>

  • get [eventHandlers](): ReadonlyMap<string, Set<EventHandlerInfo>>
  • Returns ReadonlyMap<string, Set<EventHandlerInfo>>

  • get [eventTarget](): EventTarget
  • Returns EventTarget

  • get [handleEventError](): ((evt: EventError) => void)
  • Returns ((evt: EventError) => void)

      • (evt: EventError): void
      • Parameters

        • evt: EventError

        Returns void

  • get [running](): boolean
  • Returns boolean

  • get [statusP](): Promise<Status>
  • Returns Promise<Status>

  • get [status](): Status
  • Returns Status

  • get closed(): boolean
  • Whether the stream has been completely closed (both readable and writable sides).

    Returns boolean

Methods

  • Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Will trigger the destruction of the WebSocketStream if the readable or writable haven't closed, yet they will be forced closed with reason as the error. If streams have already closed then this will do nothing. This is synchronous by design but cancelling will happen asynchronously in the background.

    This ends up calling the cancel and abort methods. Those methods are needed because the readable and writable might be locked with a reader and writer respectively. So we have to cancel and abort from the "inside" of the stream. It's essential that this is synchronous, as that ensures only one thing is running at a time. Note that if cancellation fails...

    Calling this will lead an asynchronous destruction of this WebSocketStream instance. This could throw actually. But cancellation is likely to have occurred.

    Parameters

    • Optional reason: any

    Returns void

  • Parameters

    • event: Event

    Returns boolean

  • We expect WebSocket stream error in 2 ways. WebSocket stream closure of the stream codes. On read side On write side We are able to use exception classes to distinguish things Because it's always about the error itself!A Note that you must distinguish between actual internal errors, and errors on the stream itself

    Parameters

    Returns Promise<void>

  • This is factored out and callable by both readable.cancel and this.cancel. ReadableStream ensures that this method is idempotent

    Throws

    Parameters

    • Optional reason: any

    Returns void

  • Parameters

    • controller: ReadableStreamDefaultController<any>

    Returns Promise<void>

  • Parameters

    • controller: ReadableStreamDefaultController<any>

    Returns void

  • Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | EventListenerOptions

    Returns void

  • This method can be arrived top-down or bottom-up:

    1. Top-down control flow - means explicit destruction from WebSocketConnection
    2. Bottom-up control flow - means stream events from users of this stream

    If force is true then this will cancel readable and abort writable. If force is false then it will just wait for readable and writable to be closed.

    Unlike WebSocketConnection, this defaults to true for force.

    Parameters

    • __namedParameters: {
          force?: boolean;
          reason?: any;
      } = {}
      • Optional force?: boolean
      • Optional reason?: any

    Returns Promise<void>

  • This is factored out and callable by both writable.abort and this.cancel.

    Parameters

    • Optional reason: any

    Returns void

  • This is mutually exclusive with write. It will be serialised!

    Returns void

  • Parameters

    • controller: WritableStreamDefaultController

    Returns void

  • Parameters

    • chunk: Uint8Array

    Returns Promise<void>

Generated using TypeDoc