ServerSockets

ServerSockets

Manage all ServerSocket instances.

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

Constructor

new ServerSockets()

Source:

Methods

addToRoom(socket, roomId)

Description:
  • Add a socket to a room.

    Note that in most cases, you should use a SharedState instead

Source:
Parameters:
Name Type Description
socket ServerSocket

Socket to add to the room.

roomId String

Id of the room.

broadcast(roomsIds, excludeSocket, channel, …args)

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

    Note that in most cases, you should use a SharedState instead

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 ServerSocket

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

removeFromRoom(socket, roomId)

Description:
  • Remove a socket from a room.

    Note that in most cases, you should use a SharedState instead

Source:
Parameters:
Name Type Description
socket ServerSocket

Socket to remove from the room.

roomId String

Id of the room.