Class TocketServer<S>

The Server instance of Tocket. Meant to run in Node, not in the browser.

Type Parameters

Hierarchy

  • Creates an instance of the Tocket SocketServer.

    Type Parameters

    Parameters

    • port: number

      the Port the WebSocket will be listening on.

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

      an Object of custom data that will be made accessible to all endpoints

    • Optional server: Server<typeof IncomingMessage, typeof ServerResponse>

      If you are using an https server you can inject it here.

    • timeout: number = 1500

      number of milliseconds to wait for an endpoint to answer a message

    • keepDateTimeStrings: boolean = true

      by default ISO datetime strings will automatically be parsed into Date objects, set to false to disable this behavior.

    Returns TocketServer<S>

keepDateTimeStrings: boolean = true

by default ISO datetime strings will automatically be parsed into Date objects, set to false to disable this behavior.

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

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

defaultCustomDataHandler: ((handler) => any)

Type declaration

    • (handler): any
    • Placeholder for the default custom Data method

      Parameters

      • handler: any

        The handler function

      Returns any

defaultIdentityHandler: ((handler) => any)

Type declaration

    • (handler): any
    • Placeholder for the default identity method

      Parameters

      • handler: any

        The handler function

      Returns any

  • 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

  • Basic message handling.

    Parameters

    • message: Data

      the message received by the Socket.

    Returns void

  • 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, ClientWrapper> = ...
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