Show:

Q.Socket Class

Q.Socket class can be used to manage sockets (implemented with socket.io)
Instantiate sockets with Q.Socket.connect

Constructor

Q.Socket

(
  • params
)
private

Parameters:

Item Index

Methods

Methods

connect

(
  • ns
  • url
  • [callback]
  • [callback2]
)
static

Connects a socket, and stores it in the list of connected sockets

Parameters:

  • ns String

    A socket.io namespace to use

  • url String

    The url of the socket.io node to connect to

  • [callback] Function optional

    Called after socket connects successfully. Receives Q.Socket

  • [callback2] Function optional

    Receives Q.Socket as soon as it's constructed

destroyAll

() static

Completely remove all sockets, and de-register events

disconnect

()

Disconnects a socket corresponding to a Q.Socket

disconnectAll

(
  • ns
)
static

Disconnects all sockets that have been connected

Parameters:

  • ns String

    Any namespace for the sockets to disconnect

get

(
  • ns
  • url
)
Q.Socket static

Returns a socket, if it was already connected, or returns undefined

Parameters:

  • ns String

    The socket.io namespace

  • url String

    The url where socket.io is listening. If it's empty, then returns all matching sockets.

Returns:

getAll

() Object static

Returns all the sockets, whether connected or not. Note that a socket really disconnects when all the namespaces disconnect.

Returns:

Object:

indexed by socket.io namespace, url

reconnectAll

() static

Reconnect all sockets that have been connected

Events

onConnect

Be notified when a socket connects and obtain a Q.Event based on the parameters

Event Payload:

  • ns String

    the namespace of the socket

  • url String

    the url of the socket

onEvent

Subscribe to a socket event and obtain a Q.Event based on the parameters

Event Payload:

  • ns String

    the namespace of the socket

  • url String

    the url of the socket

  • name String

    the name of the event

onEvent

Returns Q.Event which occurs on a message post event coming from socket.io Generic callbacks can be assigend by setting messageType to ""

Event Payload:

  • name String

    name of the event to listen for