Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CascadeDriver

Encapsulate the set of available transport mechanisms and expose them in an implementation independent manner.

Hierarchy

Implements

Index

Constructors

constructor

  • Create a new CascadeDriver instance

    Parameters

    • subtransports: {}

      the available subtransports

    • opts: OptionsImpl

      the connection options

    • transports: string[]

      a list of available transport names

    • cascadeNotifications: Emitter

      an emitter for emitting events on the Transports stream

    Returns CascadeDriver

Properties

Private Readonly cascadeNotifications

cascadeNotifications: Emitter

An emitter for emitting events on the Transports stream

Private Readonly emitter

emitter: Emitter

The emitter for emitting data, close, and error events

name

name: string | null

The name of the transport

Private onHandshakeError

onHandshakeError: (error: Error) => void

The handshake error handler

Type declaration

    • Parameters

      Returns void

Private onHandshakeSuccess

onHandshakeSuccess: (response: ConnectionResponse) => ConnectionResponse

The handshake handler

Type declaration

Private remainingTransports

remainingTransports: string[]

A list of remaining transport names to try

Private req

req: ConnectionRequest | null

The connection request.

Private responseReceived

responseReceived: boolean

A flag indicating whether a response has been received

Private retryCount

retryCount: number

Private Readonly retryStrategy

retryStrategy: RetryStrategyImpl

Private transport

transport: Transport | null

The current transport object.

Private Readonly transportFactory

transportFactory: (name: string) => Transport

A factory function for creating transports

Type declaration

Private Readonly transports

transports: string[]

A list of available transport names

Methods

Private cascade

  • cascade(suppressClose?: undefined | false | true): boolean
  • Cascade to the next available transport

    A close event may be emitted on this stream and a cascade event is emitted on the Transports stream.

    If there are no more transports a transports-exhausted event is emitted on the Transports stream.

    Parameters

    • Optional suppressClose: undefined | false | true

      a flag indicating whether a close event should be suppressed

    Returns boolean

    true if attempting to connect, false if transports exhausted

close

  • Close the transport

    Returns StreamImpl

    this stream

Private closeQuietly

  • closeQuietly(): void
  • Close the current transport quietly, without generating any events.

    Returns void

connect

dispatch

  • dispatch(message: Uint8Array): void
  • Send a binary message to the server.

    Parameters

    • message: Uint8Array

      the message to send

    Returns void

error

  • Close the stream. This will emit a 'close' event to any assigned listeners. No further events will be emitted.

    Parameters

    Returns Stream

Private internalConnect

  • internalConnect(): boolean
  • Connect to the current transport

    A cascading-connect event is emitted on the Transports stream.

    Returns boolean

    true if attempting to connect

off

  • Remove a listener from a specified event.

    Example:

    // Bind a single listener to the 'foo' event and then deregister it
    var listener = function() {};
    stream.on('foo', listener);
    stream.off('foo', listener);
    

    Example:

    // Bind a listener to the 'foo' event and deregister all listeners
    var listener = function() {};
    stream.on('foo', listener);
    stream.off('foo');
    

    Parameters

    • events: string | CallbackMap
    • Optional listener: StreamCallback

      the listener to remove. All listeners for the event are removed if this is not specified. This argument is ignored if the first argument is a CallbackMap.

    Returns Stream

    this stream.

on

  • Register listeners against events.

    A single listener may be bound to an event by passing the event name and listener function.

    Multiple listeners may be bound by passing in a CallbackMap, mapping event names to listener functions.

    Example:

    // Bind a single listener to the 'foo' event
    stream.on('foo', function(arg1, arg2) {
        console.log("Called for 'foo' event", arg1, arg2);
    });
    

    Example:

    // Bind multiple listeners
    stream.on({
        foo : function() { ... },
        bar : function() { ... },
        baz : function() { ... }
    });
    

    It is possible to bind multiple listeners to the same event. In this case, the listeners will be called in the order they were bound.

    Parameters

    • events: string | CallbackMap

      the event name or CallbackMap mapping event names to listeners

    • Optional listener: StreamCallback

      the listener to bind to the event, if passed as string. This argument is ignored if the first argument is a CallbackMap.

    Returns Stream

    this stream.

Private onClose

  • Called when the transport emits a close event.

    Only emits a close event on this stream if it can't cascade further

    Parameters

    Returns void

Private onConnectionResponse

  • Called when the connection response is received.

    Parameters

    Returns ConnectionResponse | null

Private onData

  • onData(data: Uint8Array): void
  • Called when the transport emits a data event.

    Forwards the data and emits a data on this stream

    Parameters

    • data: Uint8Array

      the message data

    Returns void

Private onError

  • onError(error: Error): void
  • Called when the transport emits an error event.

    Forwards the data and emits a error on this stream

    Parameters

    • error: Error

      the error that occurred

    Returns void

Private onParsingError

  • onParsingError(error: Error): void
  • Called when the connection response cannot be parsed.

    Parameters

    • error: Error

      the error that occurred

    Returns void

Private selectTransport

  • Select and create the next enabled transport.

    Returns Transport | null

    the selected transport, or null if transports exhausted

Copyright © 2025 DiffusionData Ltd. All Rights Reserved.