Socket

server. Socket

Simple wrapper with simple pubsub system built on top of ws sockets. The abstraction contains two different socket:

  • one configured for string (JSON compatible) messages
  • one configured with binaryType=arraybuffer for streaming data more efficiently.

Constructor

new Socket()

Source:
See:

Members

config :Object

Source:

Configuration object

Type:
  • Object

sockets :server.Sockets

Source:

Reference to the sockets object, is mainly dedicated to allow broadcasting from a given socket instance.

Type:
Example
socket.sockets.broadcast('my-room', this, 'update-value', 1);

Methods

addBinaryListener(channel, callback)

Source:

Listen binary messages on a given channel

Parameters:
Name Type Description
channel String

Channel of the message

callback function

Callback to execute when a message is received

addListener(channel, callback)

Source:

Listen JSON compatible messages on a given channel

Parameters:
Name Type Description
channel String

Channel of the message

callback function

Callback to execute when a message is received

addToRoom(roomId)

Source:

Add the socket to a room

Parameters:
Name Type Description
roomId String

Id of the room

removeAllBinaryListeners(channel)

Source:

Remove all listeners from binary compatible messages on a given channel

Parameters:
Name Type Description
channel String

Channel of the message

removeAllListeners(channel)

Source:

Remove all listeners from JSON compatible messages on a given channel

Parameters:
Name Type Description
channel String

Channel of the message

removeBinaryListener(channel, callback)

Source:

Remove a listener from binary compatible messages on a given channel

Parameters:
Name Type Description
channel String

Channel of the message

callback function

Callback to cancel

removeFromRoom(roomId)

Source:

Remove the socket from a room

Parameters:
Name Type Description
roomId String

Id of the room

removeListener(channel, callback)

Source:

Remove a listener from JSON compatible messages on a given channel

Parameters:
Name Type Description
channel String

Channel of the message

callback function

Callback to cancel

send(channel, …args)

Source:

Sends JSON compatible messages on a given channel

Parameters:
Name Type Attributes Description
channel String

Channel of the message

args * <repeatable>

Arguments of the message (as many as needed, of any type)

sendBinary(channel, typedArray)

Source:

Sends binary messages on a given channel

Parameters:
Name Type Description
channel String

Channel of the message

typedArray TypedArray

Data to send