Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "interface/socket-interface"

Index

Type aliases

EventTransmitter

EventTransmitter: object

Describes a transmittable event on either the client or the server. Each one may specify its argument types with a tuple, the name of the event it expects to receive as a response, and optionally the name of the event for which the transmitter should be used as a response. This can be confusing, but these guiding principles should clarify:

  • When you want the other side to respond to the transmitter with a particular event, use expect
  • When you want the transmitter be used as a response to a particular event, use responseTo

Type declaration

  • args: any[]
  • Optional expect?: string
  • Optional responseTo?: string

GenericTransmitterResponse

GenericTransmitterResponse: Response<Extract<keyof T, string>, T, L> | void

Generic Response, given a TransmitterMap and a SocketLocation.

OpLoc

OpLoc: OpLoc<L>

Given a SocketLocation, generates the opposite SocketLocation.

RemoteTransmitterResponse

RemoteTransmitterResponse: RemoteTransmitterResponse<RT, T, L>

Specific Response based on what is expected from the given remote EventTransmitter. (If nothing is expected, it defaults to GenericTransmitterResponse.)

Response

Response: object & L extends "server" ? { broadcast?: boolean; } : {}

Utility type that generates a Response given a name and a TransmitterMap.

ResponseTos

ResponseTos: { [K in keyof T]: T[K]["responseTo"] extends string ? T[K]["responseTo"] : never; }[keyof T]

Given a TransmitterMap, generates a type that is the union of all responseTo types within. Based on: https://github.com/Microsoft/TypeScript/issues/23199#issuecomment-379323872 To illustrate, since this can be a confusing type:

interface MyTransmitterMap {
    'notify-disconnected': {args: ..., responseTo: 'disconnect'},
    'notify-connected': {args: ..., responseTo: 'connect'}
}

// This type will be equivalent to 'connect' | 'disconnect'
type EventsOfInterest = ResponseTos<MyTransmitterMap>;

SocketHandlers

SocketHandlers: object & object & object

A beautifully complex type that generates a collection of logically correct EventHandlers based on the remote transmitters and local transmitters. For example, if there exists a remote transmitter called 'request-data', then there must exist a local event handler called 'request-data', and it must accept the arguments specified by that remote transmitter. Furthermore, if that remote transmitter expects a response from a local transmitter called 'give-data', then the event handler must respond with that transmitter and the arguments specified by it.

SocketInterface

SocketInterface: object

Describes all of the EventTransmitters within a server-client relationship.

Type declaration

SocketLocation

SocketLocation: "server" | "client"

Where socket handlers can reside -- either on the server or the client.

TransmitterMap

TransmitterMap: object

Map structure that is meant to enumerate all possible transmittable events, along with the arguments that will be passed with each.

Type declaration

TransmitterWithResponseTo

TransmitterWithResponseTo: Extract<{ [K in keyof T]: T[K]["responseTo"] extends ResponseTo ? K : never; }[keyof T], string>

Given a TransmitterMap, this type be the union of names for any events that have the given ResponseTo type as their responseTo value. In a well-formed API, this should be a single string literal type. To illustrate, since this can be a confusing type:

interface MyTransmitterMap {
    'notify-connected': {args: ..., responseTo: 'connect'}
}

// This type will be equivalent to 'notify-connected'
type TransmitterOfInterest = TransmitterWithResponseTo<MyTransmitterMap, 'connect'>;

Generated using TypeDoc