Class TocketClientBase<S>

This is base a WebSocket client that is connected to at least one webSocket server. This class is not meant to be used directly, instead use the derived TocketClientNode or TocketClientBrowser classes depending on your Environment.

Type Parameters

Hierarchy

  • Constructor implementation

    Type Parameters

    Parameters

    • mainURL: string | SocketLike

      The URL of the WebSocket Server

    • customData: {
          [K in string]: Serializable
      } = ...

      Data for holding this socket's state.

    • timeout: number = 1500

      number of milliseconds to wait for the target socket to respond to messages

    • mainServerTimeout: number = 1500

      number of milliseconds to wait for the target socket on when initializing.

    • mainServerInit: boolean = true

      set to false if the server should be initialized at a later time.

    • Optional mainServerLogging: LoggingTypes

      Sets the logging level for the server

    • mainServerTrapped: boolean = false

      Decides if the Main Server is a third party WebSocket that needs to be intercepted.

    Returns TocketClientBase<S>

defaultCustomDataHandler: ((handler) => any)

Type declaration

    • (handler): any
    • Parameters

      Returns any

defaultIdentityHandler: ((handler) => any)

Type declaration

    • (handler): any
    • Parameters

      Returns any

  • Access the CustomData object of this Socket.

    Type Parameters

    • K extends string

    Parameters

    • Optional key: K

      The key of the CustomData property to fetch. If left out the entire CustomData Object is returned.

    Returns K extends Sk<S["data"] & {
            id: string;
        }>
        ? (S["data"] & {
            id: string;
        })[K]
        : S["data"]

    Either the content of the CustomData property or the CustomData Object

  • Removes a server connection from the client.

    Parameters

    • name: string

      The name of the Server

    Returns boolean

Primary Controls

launch: SocketMethods<S> = ...
  • Function to be executed when connection to the main webSocket is established

    Returns any

  • Registers a communication preset.

    Type Parameters

    • N extends string

    Parameters

    • name: N

      identifier of this preset.

    • Optional handlerName: string

      name of the handler function on the target Socket this should process the messages

    • Optional defaultTarget: ConnectionFilter<NonNullable<Connector<S>>>

      identifier of the Socket the communication should target. uses the 'main' socket by default

    • timeout: number = ...

    Returns Communication<S["presets"][N], NonNullable<Connector<S>>>

    the generated Communication preset.

  • Registers socket

    Parameters

    • name: string

      the name of the targeted endpoint.

    • source: string | SocketLike

      WebSocket ws or wss URL

    • timeout: number = ...

      How long to wait for the endpoint to respond

    • Optional initialized: boolean

      Should the connection be initialized at a later time?

    • Optional logging: LoggingTypes

      which messages should be logged?

    Returns SocketWrapper<S>

    The created SocketWrapper

  • Removes a Socket from the connections map.

    Parameters

    • name: string

      The name of the connection to remove.

    Returns boolean

    true if the Socket was removed, false if it didn't exist.

General Properties

clientID: undefined | string = undefined

Client id generated by the server, empty in the Base and Server versions of the class

customData: {
    [K in string]: Serializable
} = ...
timeout: number = 1500

Internal Methods

  • Launch a previously registered communication preset.

    Type Parameters

    • N extends string

    Parameters

    • name: N

      the name of the communication preset to start

    • Optional content: DefBack<S, N, "content">

      the data used to initialize the connection.

    • Optional targetFilter: ConnectionFilter<NonNullable<Connector<S>>>

      the identifier of the endpoint this should receive this message

    Returns DefBack<S, N, "returns">

  • Providing the communication method with smart and typed parameter functions.

    Type Parameters

    • N extends string

    Parameters

    • presetName: N

      Name of preset

    • handler: Extract<keyof S["presets"], string>

      handler name

    • initialTarget: ConnectionFilter<NonNullable<Connector<S>>>

      targetName

    • Optional pID: string

      PID instance

    Returns Handler<S["presets"][N], NonNullable<Connector<S>>>

    The finished method handler

  • Dummy ID generator, since the actual ID generation depends on the final environment.

    Returns string

    empty string.

  • Modifies custom data on a Socket or Client. All connected Sockets and Clients receive the change immediately.

    Parameters

    • property: Extract<keyof S["data"], string>

      name of the property to set

    • value: Serializable

      new value of the property

    Returns void

Internal Data

connections: Map<string, SocketWrapper<S>> = ...
presets: {
    [K in string]: Communication<S["presets"][K], NonNullable<Connector<S>>>
} = ...

Map holding all communication presets registered to the Socket

promiseMap: Map<string, PromiseData> = ...

Generated using TypeDoc