Socket

client. Socket

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

  • one configured for string (JSON compatible) messages
  • one configured with binaryType=arraybuffer for streaming data more efficiently. The sockets also re-emits all "native" ws events.

An instance of Socket is automatically created by the soundworks.Client.

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

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

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 remove

send(channel, …args)

Source:

Send JSON compatible messages on a given channel

Parameters:
Name Type Attributes Description
channel String

The channel of the message

args * <repeatable>

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

sendBinary(channel, typedArray)

Source:

Send binary messages on a given channel

Parameters:
Name Type Description
channel String

Channel of the message

typedArray TypedArray

Data to send

terminate()

Source:

Immediately close the 2 sockets