Class TocketBase<T, S>

The base class that implements the core logic of Tocket. Since WebSockets are bidirectional most functionality is shared between clients and servers. This Class is not meant to be used directly, use any of the Client and Server classes that inherit from it.

Type Parameters

Hierarchy

  • 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

Primary Controls

launch: SocketMethods<S> = ...
  • List all registered communication presets

    Returns string[]

    Array of preset names

  • 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.

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
type: T

Type of the Socket, can either be "Server" or "Client"

Internal Methods

  • Constructor implementation

    Type Parameters

    Parameters

    • type: T

      The Socket type.

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

      Object in which the socket can store its data.

    • timeout: number = 1500

      Category

      General Properties

    Returns TocketBase<T, S>

  • 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">

  • Compiles a SocketRequest object from provided data.

    Parameters

    • msg: any

      the message body this should be transferred to the endpoint

    • command: Sk<S["presets"]>

      the name of the endpoint's handler function this should process the message

    • Optional oldID: string

      ID of the message this is being replied to.

    Returns SocketRequest<any, S["presets"]>

    SocketRequest Object

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

    Type Parameters

    • N extends string

    Parameters

    • presetName: N

      Name of preset

    • handler: Sk<S["presets"]>

      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.

  • Compares to objects based on their contents recursively.

    Parameters

    • comparisonObject: Record<string, any>

      A filter object

    • targetObject: Record<string, any>

      The "real" object to test against

    Returns targetObject is Record<string, any>

    true if the targetObject contains identical properties to the filter object, otherwise false

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

    Parameters

    • property: Sk<S["data"]>

      name of the property to set

    • value: Serializable

      new value of the property

    Returns void

Internal Data

connections: Map<string, ConnectionType<T, 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