Socket

client. Socket

The Socket class is a simple publish / subscribe wrapper built on top of the isomorphic-ws library. An instance of Socket is automatically created by the soundworks.Client (see client.Client#socket).

Important: In most cases, you should consider using a client.SharedState rather than directly using the sockets.

The Socket class concurrently opens two different WebSockets:

  • a socket configured with binaryType = 'blob' for JSON compatible data types (i.e. string, number, boolean, object, array and null).
  • a socket configured with binaryType= 'arraybuffer' for efficient streaming of binary data.

Both sockets re-emits all "native" ws events ('open', 'upgrade', 'close', 'error' and 'message'.

Methods

(binary, channel, …args)

Source:
Parameters:
Name Type Attributes Description
binary boolean

Emit to either the string or binary socket.

channel string

Channel name.

args * <repeatable>

Content of the message.

addListener(channel, callback)

Description:
  • Listen messages with JSON compatible data types on a given channel.

Source:
Parameters:
Name Type Description
channel string

Channel name.

callback function

Callback to execute when a message is received, arguments of the callback function will match the arguments sent using the server.Socket#send method.

(async) kSocketTerminate()

Description:
  • Removes all listeners and immediately close the two sockets. Is automatically called on client.stop()

    Is also called when a disconnection is detected by the heartbeat (note that in this case, the launcher will call client.stop() but the listeners are already cleared so the event will be trigerred only once.

Source:

removeAllListeners(channel)

Description:
  • Remove all listeners of messages with JSON compatible data types.

Source:
Parameters:
Name Type Default Description
channel string null

Channel name.

removeListener(channel, callback)

Description:
  • Remove a listener from JSON compatible messages on a given channel.

Source:
Parameters:
Name Type Description
channel string

Channel name.

callback function

Callback to remove.

send(channel, …args)

Description:
  • Send messages with JSON compatible data types on a given channel.

Source:
Parameters:
Name Type Attributes Description
channel string

Channel name.

args * <repeatable>

Payload of the message. As many arguments as needed, of JSON compatible data types (i.e. string, number, boolean, object, array and null).