Class TocketClientBrowser<S>

Tocket client for browsers. Designed to be bundled.

Type Parameters

Hierarchy

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

Primary Controls

launch: SocketMethods<S> = ...
  • 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 TocketClientBase#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
} = ...
proxySet: boolean = false

true if we have hijacked window.webSocket object to intercept connections

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

  • 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> = ...
trapMap: Map<string | RegExp, {
    repeatable: boolean;
    resolver: ((captive) => void);
}> = ...

Type declaration

  • repeatable: boolean
  • resolver: ((captive) => void)
      • (captive): void
      • Parameters

        • captive: WebSocket

        Returns void

Primary Methods

Generated using TypeDoc