Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SocketServerManager<API, API>

A simple SocketServer with an API protected by TypeScript.

Type parameters

Hierarchy

Index

Constructors

constructor

Properties

Protected config

config: any

Where configs specific to the ServerManager are stored.

Protected httpServer

httpServer: HttpServer

Contains a reference to the HttpServer that this manager is attached to. (only available after it has been attached)

Protected io

io: socketio.Server = null

Socket.io server instance for managing socket communication.

Protected Abstract socketHandlers

socketHandlers: SocketHandlers<API, "server", HandlerCtx<API>>

Contains implementations for the events described by the API. This guarantees compatibility with any SocketClient that implements the same API.

Methods

addNamespace

  • addNamespace(name: string): this
  • Adds a namespace to the socket server. Throws an error if the namespace already exists.

    Parameters

    • name: string

    Returns this

Protected attachSocketHandlers

  • attachSocketHandlers(namespace: socketio.Namespace): void
  • Sets up the socket handlers for the given namespace.

    Parameters

    • namespace: socketio.Namespace

    Returns void

blockEvent

  • blockEvent<Event>(event: Event, timeout?: number): Promise<any>
  • Gives the ability to block and wait for an event. Usage: await this.blockEvent('some-event');

    Type parameters

    • Event: string

    Parameters

    • event: Event
    • Default value timeout: number = 5000

    Returns Promise<any>

configure

emit

  • emit<Event>(target: socketio.Namespace | socketio.Socket, event: Event, ...args: API["server"][Event]["args"]): this
  • Emits an event to the given target. The typings ensure that only events defined in the API can be emitted.

    Type parameters

    • Event: keyof API["server"]

    Parameters

    • target: socketio.Namespace | socketio.Socket
    • event: Event
    • Rest ...args: API["server"][Event]["args"]

    Returns this

getNamespaces

  • getNamespaces(): string[]

getPeer

getServer

Protected handleEvent

  • handleEvent(ctx: unknown, event: string, ...args: any[]): void
  • Processes an incoming event with the appropriate socketHandler. If the handler returns an EventResponse, the proper event will automatically be emitted.

    Parameters

    • ctx: unknown
    • event: string
    • Rest ...args: any[]

    Returns void

removeNamespace

  • removeNamespace(name: string): this

Protected reply

  • reply(ctx: HandlerCtx<API>, response: any): void

setup

  • setup(httpServer: Server): void

takedown

  • takedown(): void

Static Protected getDefaultConfig

Generated using TypeDoc