Class server

Hierarchy

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(serverConfig?: IServerConfig): server

Parameters

Returns

server

Properties

public config: IServerConfig

public connections: connection[]

Methods

public addListener(event: string, listener: () => void): server

Parameters

  • event: string
  • listener: () => void

Returns

server

public addListener(event: "'request'", cb: (request: "websocket".request) => void): server

Parameters

  • event: "'request'"
  • cb: (request: "websocket".request) => void

Returns

server

public addListener(event: "'connect'", cb: (connection: "websocket".connection) => void): server

Parameters

  • event: "'connect'"
  • cb: (connection: "websocket".connection) => void

Returns

server

public addListener(event: "'close'", cb: (connection: "websocket".connection, reason: number, desc: string) => void): server

Parameters

  • event: "'close'"
  • cb: (connection: "websocket".connection, reason: number, desc: string) => void

Returns

server

public broadcast(data: Buffer)

Send binary message for each connection

Parameters

public broadcast(data: IStringified)

Send UTF-8 message for each connection

Parameters

public broadcastBytes(data: Buffer)

Send binary message for each connection

Parameters

public broadcastUTF(data: IStringified)

Send UTF-8 message for each connection

Parameters

public closeAllConnections()

Close all open WebSocket connections

public emit(event: string, args?: Array<any>): boolean

Parameters

  • event: string
  • args?: Array<any> optional

Returns

boolean

public listeners(event: string): Array<Function>

Parameters

  • event: string

Returns

Array<Function>

public mount(serverConfig: IServerConfig)

Attach the server instance to a Node http.Server instance

Parameters

public on(event: string, listener: () => void): server

Parameters

  • event: string
  • listener: () => void

Returns

server

public on(event: "'request'", cb: (request: "websocket".request) => void): server

Parameters

  • event: "'request'"
  • cb: (request: "websocket".request) => void

Returns

server

public on(event: "'connect'", cb: (connection: "websocket".connection) => void): server

Parameters

  • event: "'connect'"
  • cb: (connection: "websocket".connection) => void

Returns

server

public on(event: "'close'", cb: (connection: "websocket".connection, reason: number, desc: string) => void): server

Parameters

  • event: "'close'"
  • cb: (connection: "websocket".connection, reason: number, desc: string) => void

Returns

server

public once(event: string, listener: Function): EventEmitter

Parameters

  • event: string
  • listener: Function

Returns

EventEmitter

public removeAllListeners(event?: string): EventEmitter

Parameters

  • event?: string optional

Returns

EventEmitter

public removeListener(event: string, listener: Function): EventEmitter

Parameters

  • event: string
  • listener: Function

Returns

EventEmitter

public setMaxListeners(n: number)

Parameters

  • n: number

public shutDown()

Close all open WebSocket connections and unmount the server

public unmount()

Detach the server instance from the Node http.Server instance. All existing connections are left alone and will not be affected, but no new WebSocket connections will be accepted.