Sockets

server. Sockets

Manager all server.Socket instances.

Most of the time, you shouldn't have to use this class instance directely, but it could be usefull in some situations, for broadcasting messages, creating rooms, etc.

Constructor

new Sockets()

Source:

Methods

addToRoom(socket, roomId)

Description:
  • Add a socket to a room

Source:
Parameters:
Name Type Description
socket server.Socket

Socket to add to the room.

roomId String

Id of the room.

broadcast(roomsIds, excludeSocket, channel, …args)

Description:
  • Send a message of JSON compatible data types to all client of given room(s). If no room is specified, the message is sent to all clients.

Source:
Parameters:
Name Type Attributes Description
roomsIds String | Array

Ids of the rooms that must receive the message. If null the message is sent to all clients.

excludeSocket server.Socket

Optionnal socket to ignore when broadcasting the message, typically the client at the origin of the message.

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).

broadcastBinary(roomsIds, excludeSocket, channel, typedArray)

Description:
  • Send a binary message to all client of given room(s). If no room is specified specified, the message is sent to all clients.

Source:
Parameters:
Name Type Description
roomsIds String | Array

Ids of the rooms that must receive the message. If null the message is sent to all clients.

excludeSocket server.Socket

Optionnal socket to ignore when broadcasting the message, typically the client at the origin of the message.

channel string

Channel name.

typedArray TypedArray

Binary data to be sent.

removeFromRoom(socket, roomId)

Description:
  • Remove a socket from a room

Source:
Parameters:
Name Type Description
socket server.Socket

Socket to remove from the room.

roomId String

Id of the room.