Class SocketWrapper<S>

The SocketWrapper acts as an interface to interact with the actual socket, with a focus on managing builtin WebSocket methods while injecting functionality required by Tocket.
This includes timeout and retry settings and logs of messages sent and received by the socket as well as methods for transforming input and output messages from a Tocket readable format to formats required by a third party WebSocket and vice versa.

Type Parameters

Hierarchy

  • Type Parameters

    Parameters

    • identifier: string

      The name used by Clients for targeting the Socket

      Category

      General Properties

    • source: string | SocketLike

      The WebSocket or URL that will be wrapped by the SocketWrapper

      Category

      General Properties

    • registration: TocketClientBase<S>

      The TocketClient this SocketWrapper is registered to.

      Category

      General Properties

    • Optional timeout: number

      The number of Milliseconds this socket will wait for responses form other endpoints.

      Category

      General Properties

    • initialized: boolean = true

      true* If the WebSocket connection should be initialized immediately,

      Category

      General Properties

    • logging: LoggingTypes = 'none'

      Smarkand. Funnelly

      Category

      General Properties

    Returns SocketWrapper<S>

customData: Record<string, Serializable> = {}
messageLog: string[] = []

If logging is enabled all intercepted messages will be stored here

  • get alive(): boolean
  • Utility function for checking if a socket is alive.

    Returns boolean

    true if the socket is alive, false if it isn't

Primary Controls

inbound: InboundAdapter = ...

Inbound transformation object, converts input from the webSocket into valid SocketRequests

outbound: OutboundAdapter = ...

Outbound transformation object, applied to the SocketRequest just before it is sent.

  • Initiaize the webSocket connection if it isn't already active.

    Parameters

    • Optional force: boolean

    Returns void

Overrides

General Properties

delayedSource: undefined | string | SocketLike

The [source]

identifier: string

The name used by Clients for targeting the Socket

initialized: boolean = true

true* If the WebSocket connection should be initialized immediately,

logging: LoggingTypes = 'none'

Smarkand. Funnelly

maxRetries: number = 5

The number of times the SocketWrapper will try to reconnect to a WebSocket after the connection is lost.

registration: TocketClientBase<S>

The TocketClient this SocketWrapper is registered to.

retryInterval: number = 5000

How long to wait between each connection attempt

source: string | SocketLike

The WebSocket or URL that will be wrapped by the SocketWrapper

timeout?: number

The number of Milliseconds this socket will wait for responses form other endpoints.

Internal Methods

  • Fetches either the replaced or original method of the wrapped WebSocket.

    Parameters

    • key: keyof SocketLike

      The name of the property to fetch

    Returns any

  • Initiaites the WebSocket connection to the chosen Socket or URL

    Parameters

    • source: string | SocketLike

      The URL or WebSocket to connect

    Returns void

  • Parameters

    • property: keyof SocketLike
    • value: TrapFunction
    • initializing: boolean = false

    Returns void

Internal Data

interceptor: TrapFunction
replacedProperties: Map<keyof SocketLike, TrapFunction> = ...

Map of WebSocket properties and methods that have been replaced by Tocket

retries: number = 0

The current number of times the socket has failed to connect to the [source]

Generated using TypeDoc