Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Socket

The Socket that we use to connect to a Namespace on the server

Hierarchy

Index

Properties

connected

connected: boolean

Are we currently connected?

default

false

disconnected

disconnected: boolean

Are we currently disconnected?

default

true

id

id: string

The ID of the socket; matches the server ID and is set when we're connected, and cleared when we're disconnected

io

The Manager that's controller this socket

nsp

nsp: string

The namespace that this socket is for

default

'/'

Methods

addEventListener

  • addEventListener(event: string, fn: Function): Emitter

close

compress

  • compress(compress: boolean): Socket
  • Sets the compress flag.

    Parameters

    • compress: boolean

      If true, compresses the sending data

    Returns Socket

    this Socket

connect

disconnect

emit

  • emit(event: string, ...args: any[]): Socket
  • An override of the base emit. If the event is one of: connect connect_error connect_timeout connecting disconnect error reconnect reconnect_attempt reconnect_failed reconnect_error reconnecting ping pong then the event is emitted normally. Otherwise, if we're connected, the event is sent. Otherwise, it's buffered.

    If the last argument is a function, then it will be called as an 'ack' when the response is received. The parameter(s) of the ack will be whatever data is returned from the event

    Parameters

    • event: string

      The event that we're emitting

    • Rest ...args: any[]

      Optional arguments to send with the event

    Returns Socket

    This Socket

hasListeners

  • hasListeners(event: string): boolean
  • Returns if we have listeners for a particular event

    Parameters

    • event: string

      The event that we want to check if we've listeners for

    Returns boolean

    True if we have listeners for this event, false otherwise

listeners

  • listeners(event: string): Function[]
  • Returns all the callbacks for a particular event

    Parameters

    • event: string

      The event that we're looking for the callbacks of

    Returns Function[]

    An array of callback Functions, or an empty array if we don't have any

off

  • off(event: string, fn?: Function): Emitter
  • Removes a listener for a particular type of event. This will either remove a specific listener, or all listeners for this type of event

    Parameters

    • event: string

      The event that we want to remove the listener of

    • Optional fn: Function

      The function to remove, or null if we want to remove all functions

    Returns Emitter

    This Emitter

on

  • on(event: string, fn: Function): Emitter
  • Adds a listener for a particular event. Calling multiple times will add multiple listeners

    Parameters

    • event: string

      The event that we're listening for

    • fn: Function

      The function to call when we get the event. Parameters depend on the event in question

    Returns Emitter

    This Emitter

once

  • once(event: string, fn: Function): Emitter
  • Adds a listener for a particular event that will be invoked a single time before being automatically removed

    Parameters

    • event: string

      The event that we're listening for

    • fn: Function

      The function to call when we get the event. Parameters depend on the event in question

    Returns Emitter

    This Emitter

open

  • Opens our socket so that it connects. If the 'autoConnect' option for io is true (default), then this is called automatically when the Socket is created

    Returns Socket

removeAllListeners

removeEventListener

  • removeEventListener(event: string, fn?: Function): Emitter

removeListener

  • removeListener(event: string, fn?: Function): Emitter

send

  • send(...args: any[]): Socket
  • Sends a 'message' event

    see

    emit

    Parameters

    • Rest ...args: any[]

      Any optional arguments that we want to send

    Returns Socket

    This Socket

Generated using TypeDoc